예제 #1
0
        public void LoadPageThrowsIfPageNumberIsLessThanOne()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            ExceptionAssert.ThrowsArgOutOfRange(() => node.LoadPage(0), "pageNumber", 1, null, true);
        }
예제 #2
0
        public void ExtensionsPropertyIsNotNull()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.NotNull(node.Extensions);
        }
예제 #3
0
        public void IsSearchResultsNodeIsFalse()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.False(node.IsSearchResultsNode);
        }
예제 #4
0
        public void TotalPagesPropertyIsCorrect()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.AreEqual(1, node.TotalPages);
        }
예제 #5
0
        public void ToStringMethodReturnsName()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.Equal("Mock Tree Node", node.ToString());
        }
예제 #6
0
        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));
        }
예제 #7
0
        public void IsSelectedIsFalseByDefault()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.False(node.IsSelected);
        }
예제 #8
0
        public void CurrentPagesPropertyIsCorrect()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.Equal(1, node.CurrentPage);
        }
예제 #9
0
        public void NodesPropertyIsNotNullAndEmpty()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.NotNull(node.Nodes);
            Assert.Equal(0, node.Nodes.Count);
        }
예제 #10
0
        public void ParentPropertyIsCorrect()
        {
            // Arrange
            IVsExtensionsTreeNode parentTreeNode = new Mock <IVsExtensionsTreeNode>().Object;
            PackagesTreeNodeBase  node           = CreatePackagesTreeNodeBase(parentTreeNode);

            // Act & Assert
            Assert.Same(parentTreeNode, node.Parent);
        }
예제 #11
0
        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();
            }
        }
예제 #12
0
        public void SortSelectionChangedReturnsFalseIfCurrentSortDescriptorIsNull()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase(numberOfPackages: 10);

            // Act
            bool result = node.SortSelectionChanged(null);

            // Assert
            Assert.False(result);
        }
예제 #13
0
        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);
        }
예제 #14
0
        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();
            }
        }
예제 #15
0
        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);
        }
예제 #16
0
        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);
        }
예제 #17
0
        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);
            });
        }