public void I_root_returns_grandchild_on_DescendantOrDefault()
        {
            // ARRANGE

            MockableNodeType grandChildNode = new Mock <MockableNodeType>().Object;

            var childNode = new Mock <MockableNodeType>();

            childNode
            .Setup(n => n.TryGetChildNode(2))
            .Returns((true, grandChildNode));

            var childNodeObject = childNode.Object;

            this.startNode
            .Setup(n => n.TryGetChildNode(1))
            .Returns((true, childNodeObject));

            // ACT

            MockableNodeType result1 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create(1, 2));

            HierarchyPath <int> foundNodePath;
            MockableNodeType    result2 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create(1, 2), out foundNodePath);

            // ASSERT

            Assert.NotNull(grandChildNode);
            Assert.Same(grandChildNode, result1);
            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Exactly(2));
            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Exactly(2));
        }
        public void IHasParentNode_inner_node_returns_parent_on_Parent()
        {
            // ARRANGE

            var rootNode = new Mock <MockableNodeType>();

            rootNode // has no parent
            .Setup(r => r.HasParentNode).Returns(false);

            var parentOfStartNode = new Mock <MockableNodeType>();

            parentOfStartNode // has root node as parent
            .Setup(p => p.HasParentNode).Returns(true);
            parentOfStartNode
            .Setup(p => p.ParentNode).Returns(rootNode.Object);

            this.startNode // has a parant
            .Setup(m => m.HasParentNode).Returns(true);
            this.startNode // returns parent node
            .Setup(m => m.ParentNode).Returns(parentOfStartNode.Object);

            // ACT

            MockableNodeType result = this.startNode.Object.Parent();

            // ASSERT

            startNode.Verify(m => m.HasParentNode, Times.Once());
            startNode.Verify(m => m.ParentNode, Times.Once());

            Assert.Same(parentOfStartNode.Object, result);
        }
        public void I_root_returns_substitute_on_invalid_childId_on_DescendantOrDefault()
        {
            // ARRANGE

            MockableNodeType childNode = new Mock <MockableNodeType>().Object;

            this.startNode
            .Setup(n => n.TryGetChildNode(1))
            .Returns((false, childNode));

            MockableNodeType substitute = new Mock <MockableNodeType>().Object;

            // ACT

            MockableNodeType result1 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create(1), createDefault: () => substitute);

            HierarchyPath <int> foundNodePath;
            MockableNodeType    result2 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create(1), out foundNodePath, createDefault: () => substitute);

            // ASSERT

            Assert.Same(substitute, result1);
            Assert.Same(substitute, result2);
            Assert.Equal(HierarchyPath.Create <int>(), foundNodePath);
            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Exactly(2));
        }
Пример #4
0
        public void I_root_returns_grandchild_on_DescendentAt()
        {
            // ARRANGE

            var subChildNode = new Mock <MockableNodeType>().Object;

            var childNodeMock = new Mock <MockableNodeType>();

            childNodeMock
            .Setup(n => n.TryGetChildNode(2))
            .Returns((true, subChildNode));

            var childNode = childNodeMock.Object;

            this.startNode
            .Setup(n => n.TryGetChildNode(1))
            .Returns((true, childNode));

            // ACT

            MockableNodeType result = this.startNode.Object.DescendantAt(HierarchyPath.Create(1, 2));

            // ASSERT

            Assert.Same(subChildNode, result);
            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Once());
            childNodeMock.Verify(n => n.TryGetChildNode(2), Times.Once());
        }
Пример #5
0
        public void I_root_returns_itself_on_DescendantAt()
        {
            // ACT

            MockableNodeType result = this.startNode.Object.DescendantAt(HierarchyPath.Create <int>());

            // ASSERT

            Assert.Same(startNode.Object, result);
        }
        public void I_root_returns_itself_on_DescendantAtOrDefault()
        {
            // ACT

            MockableNodeType result1 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create <int>());

            HierarchyPath <int> foundNodePath;
            MockableNodeType    result2 = this.startNode.Object.DescendantAtOrDefault(HierarchyPath.Create <int>(), out foundNodePath);

            // ASSERT

            Assert.Same(startNode.Object, result1);
            Assert.Same(startNode.Object, result2);
            Assert.Equal(HierarchyPath.Create <int>(), foundNodePath);


            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Never());
        }
Пример #7
0
        public void I_root_returns_child_on_DescendantAt()
        {
            // ARRANGE

            MockableNodeType childNode = new Mock <MockableNodeType>().Object;

            this.startNode
            .Setup(n => n.TryGetChildNode(1))
            .Returns((true, childNode));

            // ACT

            MockableNodeType result = this.startNode.Object.DescendantAt(HierarchyPath.Create(1));

            // ASSERT

            Assert.NotNull(childNode);
            Assert.Same(childNode, result);
            this.startNode.Verify(n => n.TryGetChildNode(1), Times.Once());
        }