public void LoadPageThrowsIfPageNumberIsLessThanOne() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert ExceptionAssert.ThrowsArgOutOfRange(() => node.LoadPage(0), "pageNumber", 1, null, true); }
public void ExtensionsPropertyIsNotNull() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.NotNull(node.Extensions); }
public void IsSearchResultsNodeIsFalse() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.False(node.IsSearchResultsNode); }
public void TotalPagesPropertyIsCorrect() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.AreEqual(1, node.TotalPages); }
public void ToStringMethodReturnsName() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.Equal("Mock Tree Node", node.ToString()); }
private static PackagesSearchNode CreatePackagesSearchNode(string searchTerm, int numberOfPackages = 1, bool collapseVersions = true, PackagesTreeNodeBase baseNode = null) { PackagesProviderBase provider = new MockPackagesProvider(); IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object; PackagesTreeNodeBase baseTreeNode = baseNode ?? new MockTreeNode(parentTreeNode, provider, numberOfPackages, collapseVersions); return(new PackagesSearchNode(provider, parentTreeNode, baseTreeNode, searchTerm)); }
public void IsSelectedIsFalseByDefault() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.False(node.IsSelected); }
public void CurrentPagesPropertyIsCorrect() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.Equal(1, node.CurrentPage); }
public void NodesPropertyIsNotNullAndEmpty() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); // Act & Assert Assert.NotNull(node.Nodes); Assert.Equal(0, node.Nodes.Count); }
public void ParentPropertyIsCorrect() { // Arrange IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object; PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(parentTreeNode); // Act & Assert Assert.Same(parentTreeNode, node.Parent); }
private void OnCategorySelectionChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { PackagesTreeNodeBase selectedNode = explorer.SelectedExtensionTreeNode as PackagesTreeNodeBase; if (selectedNode != null) { // notify the selected node that it is opened. selectedNode.OnOpened(); } }
public void SortSelectionChangedReturnsFalseIfCurrentSortDescriptorIsNull() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(numberOfPackages: 10); // Act bool result = node.SortSelectionChanged(null); // Assert Assert.False(result); }
private static void TreeNodeActionTest(Action <PackagesTreeNodeBase> treeNodeAction, Action <PackagesTreeNodeBase> callback, int?pageSize = null, int?numberOfPackages = null) { const int defaultNumberOfPackages = 10; PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(numberOfPackages: numberOfPackages ?? defaultNumberOfPackages); node.IsSelected = true; TreeNodeActionTest(node, treeNodeAction, callback, pageSize); }
private void OnCategorySelectionChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { PackagesTreeNodeBase oldNode = e.OldValue as PackagesTreeNodeBase; if (oldNode != null) { // notify the previously selected node that it was closed. oldNode.OnClosed(); } PackagesTreeNodeBase newNode = e.NewValue as PackagesTreeNodeBase; if (newNode != null) { // notify the selected node that it is opened. newNode.OnOpened(); } }
private static void TreeNodeActionTest(PackagesTreeNodeBase node, Action <PackagesTreeNodeBase> treeNodeAction, Action <PackagesTreeNodeBase> callback, int?pageSize = null) { // Arrange ManualResetEventSlim resetEvent = new ManualResetEventSlim(initialState: false); node.PageSize = pageSize ?? node.PageSize; Exception exception = null; node.PackageLoadCompleted += delegate { try { // Callback for assertion callback(node); } catch (Exception e) { // There was an exception when running the callback async, so record the exception exception = e; } finally { // If there is an exception we don't want to freeze the unit test forever resetEvent.Set(); } }; // Act treeNodeAction(node); // Wait for the event to get signaled resetEvent.Wait(); // Make sure there was no exception Assert.Null(exception); }
public void IsExpandedPropertyWhenChangedRaiseEvent() { // Arrange PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(); node.IsExpanded = false; bool propertyRaised = false; node.PropertyChanged += (o, e) => { if (e.PropertyName == "IsExpanded") { propertyRaised = true; } }; // Act node.IsExpanded = true; // Assert Assert.IsTrue(propertyRaised); }
public void LoadPageFollowedBySortClearsCacheAndUsesNewSortOrder() { // Arrange var idSortDescriptor = new PackageSortDescriptor("Id", "Id", ListSortDirection.Ascending); PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(numberOfPackages: 5); node.IsSelected = true; // Act TreeNodeActionTest(node, n => n.LoadPage(1), n => { // Assert Assert.Equal(1, n.TotalPages); Assert.Equal(1, n.CurrentPage); Assert.Equal(5, n.Extensions.Count); Assert.Equal("A4", n.Extensions[0].Name); Assert.Equal("A3", n.Extensions[1].Name); Assert.Equal("A2", n.Extensions[2].Name); Assert.Equal("A1", n.Extensions[3].Name); Assert.Equal("A0", n.Extensions[4].Name); }); TreeNodeActionTest(node, n => n.SortSelectionChanged(idSortDescriptor), n => { // Assert Assert.Equal(1, n.TotalPages); Assert.Equal(1, n.CurrentPage); Assert.Equal(5, n.Extensions.Count); Assert.Equal("A0", n.Extensions[0].Name); Assert.Equal("A1", n.Extensions[1].Name); Assert.Equal("A2", n.Extensions[2].Name); Assert.Equal("A3", n.Extensions[3].Name); Assert.Equal("A4", n.Extensions[4].Name); }); }