Exemplo n.º 1
0
        public void LoadPageThrowsIfPageNumberIsLessThanOne()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

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

            // Act & Assert
            Assert.NotNull(node.Extensions);
        }
Exemplo n.º 3
0
        public void IsSearchResultsNodeIsFalse()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

            // Act & Assert
            Assert.False(node.IsSearchResultsNode);
        }
Exemplo n.º 4
0
        public void TotalPagesPropertyIsCorrect()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

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

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

            // Act & Assert
            Assert.False(node.IsSelected);
        }
Exemplo n.º 8
0
        public void CurrentPagesPropertyIsCorrect()
        {
            // Arrange
            PackagesTreeNodeBase node = CreatePackagesTreeNodeBase();

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

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

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

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

            // Assert
            Assert.False(result);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            });
        }