-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix null pointer exception in pick project dialog. (#962)
* Fix the null pointer exception.
- Loading branch information
Jim Przybylinski
authored
May 17, 2018
1 parent
453a41b
commit bdb6b47
Showing
9 changed files
with
164 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
GoogleCloudExtension/GoogleCloudExtension/PickProjectDialog/IPickProjectIdViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using Google.Apis.CloudResourceManager.v1.Data; | ||
using GoogleCloudExtension.Utils; | ||
using GoogleCloudExtension.Utils.Async; | ||
using System.Collections.Generic; | ||
|
||
namespace GoogleCloudExtension.PickProjectDialog | ||
{ | ||
/// <summary> | ||
/// Interface of the view model used by the <see cref="PickProjectIdWindowContent"/> | ||
/// </summary> | ||
public interface IPickProjectIdViewModel : IViewModelBase | ||
{ | ||
/// <summary> | ||
/// Result of the view model after the dialog window is closed. Remains | ||
/// null until an action buttion is clicked. | ||
/// </summary> | ||
Project Result { get; } | ||
|
||
/// <summary> | ||
/// Command to open the manage users dialog. | ||
/// </summary> | ||
ProtectedCommand ChangeUserCommand { get; } | ||
|
||
/// <summary> | ||
/// Command to confirm the selection of a project id. | ||
/// </summary> | ||
ProtectedCommand OkCommand { get; } | ||
|
||
/// <summary> | ||
/// Command to execute when refreshing the list of projects. | ||
/// </summary> | ||
ProtectedCommand RefreshCommand { get; } | ||
|
||
/// <summary> | ||
/// The list of projects available to the current user. | ||
/// </summary> | ||
IEnumerable<Project> Projects { get; } | ||
|
||
/// <summary> | ||
/// The project selected from the list of current projects. | ||
/// </summary> | ||
Project SelectedProject { get; set; } | ||
|
||
/// <summary> | ||
/// The property that surfaces task completion information for the Load Projects task. | ||
/// </summary> | ||
AsyncProperty LoadTask { get; set; } | ||
|
||
bool HasAccount { get; } | ||
string Filter { get; set; } | ||
bool AllowAccountChange { get; } | ||
string HelpText { get; } | ||
|
||
bool FilterItem(object item); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...ension/GoogleCloudExtensionUnitTests/PickProjectDialog/PickProjectIdWindowContentTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
using Google.Apis.CloudResourceManager.v1.Data; | ||
using GoogleCloudExtension.PickProjectDialog; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Moq; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Windows.Data; | ||
using System.Windows.Threading; | ||
|
||
namespace GoogleCloudExtensionUnitTests.PickProjectDialog | ||
{ | ||
[TestClass] | ||
public class PickProjectIdWindowContentTests : ExtensionTestBase | ||
{ | ||
private PickProjectIdWindowContent _objectUnderTest; | ||
private Mock<IPickProjectIdViewModel> _viewModelMock; | ||
|
||
protected override void BeforeEach() | ||
{ | ||
_viewModelMock = new Mock<IPickProjectIdViewModel>(); | ||
_objectUnderTest = new PickProjectIdWindowContent(_viewModelMock.Object); | ||
// Initalize data bindings. See https://stackoverflow.com/questions/5396805/force-binding-in-wpf | ||
_objectUnderTest.Dispatcher.Invoke(() => { }, DispatcherPriority.SystemIdle); | ||
} | ||
|
||
[TestMethod] | ||
public void TestInitalConditions() | ||
{ | ||
Assert.AreEqual(_objectUnderTest.DataContext, _viewModelMock.Object); | ||
Assert.IsTrue(_objectUnderTest._filter.IsFocused); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFilterUpdated() | ||
{ | ||
var visibleProject = new Project { Name = "Visible", ProjectId = "2" }; | ||
_viewModelMock.Setup(vm => vm.FilterItem(It.IsAny<Project>())).Returns(false); | ||
_viewModelMock.Setup(vm => vm.FilterItem(visibleProject)).Returns(true); | ||
|
||
_viewModelMock.SetupGet(vm => vm.Projects).Returns( | ||
new[] | ||
{ | ||
new Project {Name = "Filtered Out", ProjectId = "1"}, | ||
visibleProject | ||
}); | ||
_viewModelMock.Raise( | ||
vm => vm.PropertyChanged += null, | ||
new PropertyChangedEventArgs(nameof(IPickProjectIdViewModel.Projects))); | ||
|
||
var cvs = (CollectionViewSource)_objectUnderTest.Resources[PickProjectIdWindowContent.CvsKey]; | ||
CollectionAssert.AreEqual(new[] { visibleProject }, cvs.View.Cast<Project>().ToList()); | ||
} | ||
|
||
[TestMethod] | ||
public void TestFilterUpdateWithNullViewDoesNotThrow() | ||
{ | ||
_viewModelMock.SetupGet(vm => vm.Projects).Returns(() => null); | ||
_viewModelMock.Raise( | ||
vm => vm.PropertyChanged += null, | ||
new PropertyChangedEventArgs(nameof(IPickProjectIdViewModel.Projects))); | ||
|
||
_viewModelMock.SetupGet(vm => vm.Filter).Returns("Visible"); | ||
_viewModelMock.Raise( | ||
vm => vm.PropertyChanged += null, | ||
new PropertyChangedEventArgs(nameof(IPickProjectIdViewModel.Filter))); | ||
} | ||
} | ||
} |