Пример #1
0
        public void Should_return_ancestors_calling_GetAncestors()
        {
            // arrange
            var testTarget = new TestTarget
            {
                Id = 345,
                Data = new TestTargetData { TestString = "Its a target!" }
            };
            var node = new HierarchyNode
            {
                Id = 34,
                LeftId = 2,
                RightId = 3,
                TargetId = testTarget.Id
            };
            var ancestor1 = new HierarchyNode
            {
                Id = 22,
                LeftId = 1,
                RightId = 6,
                TargetId = testTarget.Id
            };
            var ancestor2 = new HierarchyNode
            {
                Id = 11,
                LeftId = 1,
                RightId = 13,
                TargetId = testTarget.Id
            };

            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.GetAncestors(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>(), true, true))
                .Returns(new List<HierarchyNode> { ancestor2, ancestor1, node });
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var resultNode = service.GetAncestors(hierarchyEntry, node, true, true);

            // assert
            Assert.That(resultNode, Is.Not.Null);
            Assert.That(resultNode.Count, Is.EqualTo(3));
            Assert.That(resultNode[0].Id, Is.EqualTo(ancestor2.Id));
            Assert.That(resultNode[0].LeftId, Is.EqualTo(ancestor2.LeftId));
            Assert.That(resultNode[0].RightId, Is.EqualTo(ancestor2.RightId));
            Assert.That(resultNode[0].TargetId, Is.EqualTo(ancestor2.TargetId));
            Assert.That(resultNode[1].Id, Is.EqualTo(ancestor1.Id));
            Assert.That(resultNode[1].LeftId, Is.EqualTo(ancestor1.LeftId));
            Assert.That(resultNode[1].RightId, Is.EqualTo(ancestor1.RightId));
            Assert.That(resultNode[1].TargetId, Is.EqualTo(ancestor1.TargetId));
            Assert.That(resultNode[2].Id, Is.EqualTo(node.Id));
            Assert.That(resultNode[2].LeftId, Is.EqualTo(node.LeftId));
            Assert.That(resultNode[2].RightId, Is.EqualTo(node.RightId));
            Assert.That(resultNode[2].TargetId, Is.EqualTo(node.TargetId));

            mockHierarchyDataProvider.Verify(p => p.GetAncestors(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>(), true, true));
        }
Пример #2
0
        public static void Initialize()
        {
            // verify tables
            var dataProvider = new MssqlDataProvider();
            var hierarchyDataProvider = new MssqlHierarchyDataProvider(dataProvider);

            var hierarchyEntryRepository = new HierarchyEntryRepository(dataProvider);
            var targetEntryRepository = new TargetEntryRepository(dataProvider);
            var targetRepository = new TargetRepository(dataProvider);

            var assembly = Assembly.GetCallingAssembly();
            var targetTypes = assembly.GetTypesOfType<ITarget>();

            var hierarchyService = new HierarchyService(hierarchyDataProvider, hierarchyEntryRepository, targetEntryRepository, targetRepository, targetTypes);

            // build missing tables

            // register structureMap
        }
Пример #3
0
        public void Should_return_children_calling_GetChildren()
        {
            // arrange
            var testTarget = new TestTarget
            {
                Id = 345,
                Data = new TestTargetData { TestString = "Its a target!" }
            };
            var parentNode = new HierarchyNode
            {
                Id = 23,
                LeftId = 1,
                RightId = 6,
                TargetId = testTarget.Id
            };
            var child1 = new HierarchyNode
            {
                Id = 45,
                LeftId = 2,
                RightId = 3,
                TargetId = testTarget.Id
            };
            var child2 = new HierarchyNode
            {
                Id = 46,
                LeftId = 4,
                RightId = 5,
                TargetId = testTarget.Id
            };

            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.GetChildren(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()))
                .Returns(new List<HierarchyNode> { child1, child2 });
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var resultNode = service.GetChildren(hierarchyEntry, parentNode);

            // assert
            Assert.That(resultNode, Is.Not.Null);
            Assert.That(resultNode.Count, Is.EqualTo(2));
            Assert.That(resultNode[0].Id, Is.EqualTo(child1.Id));
            Assert.That(resultNode[0].LeftId, Is.EqualTo(child1.LeftId));
            Assert.That(resultNode[0].RightId, Is.EqualTo(child1.RightId));
            Assert.That(resultNode[0].TargetId, Is.EqualTo(child1.TargetId));

            mockHierarchyDataProvider.Verify(p => p.GetChildren(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
        }
Пример #4
0
        public void Should_verify_calling_DeleteNode()
        {
            // arrange
            var deleteNode = new HierarchyNode
            {
                Id = 1,
                LeftId = 2,
                RightId = 3
            };
            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.Delete(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            service.DeleteNode(hierarchyEntry, deleteNode);

            // assert
            mockHierarchyDataProvider.Verify(p => p.Delete(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
        }
Пример #5
0
        public void Should_return_valid_Root_Node_calling_Initializehierarchy()
        {
            // arrange
            var rootNodeTarget = new TestTarget
            {
                Id = 0,
                Data = new TestTargetData
                {
                    TestString = "Profile Root"
                }
            };
            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.Add(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();

            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var rootHierarchyNode = service.InitializeHierarchy(hierarchyEntry, rootNodeTarget);

            // assert
            Assert.That(rootHierarchyNode, Is.Not.Null);
            Assert.That(rootHierarchyNode.LeftId, Is.EqualTo(1));
            Assert.That(rootHierarchyNode.RightId, Is.EqualTo(2));
            Assert.That(rootHierarchyNode.Id, Is.EqualTo(0));

            mockHierarchyDataProvider
                .Verify(p => p.Add(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
        }
Пример #6
0
        public void Should_return_valid_node_calling_PrepareForInsertNode()
        {
            // arrange
            var parentNode = new HierarchyNode
            {
                Id = 0,
                LeftId = 1,
                RightId = 2
            };
            var childNode = new HierarchyNode
            {
                Id = 0,
                LeftId = 0,
                RightId = 0,
                TargetId = 345
            };

            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.PrepareForInsertNode(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var newHierarchyNode = service.PrepareForInsertNode(hierarchyEntry, parentNode, childNode);

            // assert
            Assert.That(newHierarchyNode, Is.Not.Null);
            Assert.That(newHierarchyNode.LeftId, Is.EqualTo(parentNode.RightId));
            Assert.That(newHierarchyNode.RightId, Is.EqualTo(parentNode.RightId + 1));
            Assert.That(newHierarchyNode.Id, Is.EqualTo(0));

            mockHierarchyDataProvider.Verify(p => p.PrepareForInsertNode(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
        }
Пример #7
0
        public void Should_return_valid_node_calling_GetRootNode()
        {
            // arrange
            var rootNodeTarget = new HierarchyNode
            {
                Id = 0,
                LeftId = 1,
                RightId = 2
            };
            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider
                .Setup(p => p.GetRootNode(It.IsAny<HierarchyEntry>()))
                .Returns(rootNodeTarget);
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var rootHierarchyNode = service.GetRootNode(hierarchyEntry);

            // assert
            Assert.That(rootHierarchyNode, Is.Not.Null);
            Assert.That(rootHierarchyNode.LeftId, Is.EqualTo(1));
            Assert.That(rootHierarchyNode.RightId, Is.EqualTo(2));
            Assert.That(rootHierarchyNode.Id, Is.EqualTo(0));

            mockHierarchyDataProvider.Verify(p => p.GetRootNode(It.IsAny<HierarchyEntry>()));
        }
Пример #8
0
        public void Should_return_parent_calling_GetParent()
        {
            // arrange
            var testTarget = new TestTarget
            {
                Id = 345,
                Data = new TestTargetData { TestString = "Its a target!" }
            };
            var childNode = new HierarchyNode
            {
                Id = 34,
                LeftId = 2,
                RightId = 3,
                TargetId = testTarget.Id
            };
            var parentNode = new HierarchyNode
            {
                Id = 22,
                LeftId = 1,
                RightId = 6,
                TargetId = testTarget.Id
            };

            var mockHierarchyDataProvider = new Mock<IHierarchyDataProvider>();
            mockHierarchyDataProvider.Setup(p => p.GetParent(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()))
                .Returns(parentNode);
            var mockHierarchyEntryRepository = new Mock<IHierarchyEntryRepository>();
            var mockTargetEntryRepository = new Mock<ITargetEntryRepository>();
            var mockTargetRepository = new Mock<ITargetRepository>();
            var mockTargetTypes = new List<Type>();
            var service = new HierarchyService(mockHierarchyDataProvider.Object, mockHierarchyEntryRepository.Object, mockTargetEntryRepository.Object, mockTargetRepository.Object, mockTargetTypes);

            // act
            var resultNode = service.GetParent(hierarchyEntry, childNode);

            // assert
            Assert.That(resultNode, Is.Not.Null);
            Assert.That(resultNode.Id, Is.EqualTo(parentNode.Id));
            Assert.That(resultNode.LeftId, Is.EqualTo(parentNode.LeftId));
            Assert.That(resultNode.RightId, Is.EqualTo(parentNode.RightId));
            Assert.That(resultNode.TargetId, Is.EqualTo(parentNode.TargetId));

            mockHierarchyDataProvider.Verify(p => p.GetParent(It.IsAny<HierarchyEntry>(), It.IsAny<HierarchyNode>()));
        }