Example #1
0
        public void BuildHierarchy_SimpleList_ReturnsCorrectHierarchy()
        {
            //Arrange
            var parent = new FolderItem()
            {
                Id = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247482")
            };

            var child = new RouteItem()
            {
                Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247481"),
                ParentId = parent.Id
            };

            List <Node> listHierarchy = new List <Node> {
                parent, child
            };

            //Act
            var result = NodeManager.BuildHierarchy(listHierarchy);

            //Assert
            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].Children.Count == 1);
        }
Example #2
0
        public void BuildHierarchy_ComplexList_ReturnsCorrectHierarchy()
        {
            //Arrange
            var root = new FolderItem()
            {
                Id = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247481")
            };

            var children = new List <Node>()
            {
                new RouteItem
                {
                    Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247482"),
                    ParentId = root.Id
                },
                new RouteItem
                {
                    Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247483"),
                    ParentId = root.Id
                },
                new RouteItem
                {
                    Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247484"),
                    ParentId = root.Id
                }
            };

            var secondLevelParent = new FolderItem
            {
                Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247485"),
                ParentId = root.Id
            };

            var secondLevelParentChild = new RouteItem
            {
                Id       = Guid.Parse("9245fe4a-d402-451c-b9ed-9c1a04247486"),
                ParentId = secondLevelParent.Id
            };

            List <Node> listHierarchy = new List <Node> {
                root, secondLevelParent, secondLevelParentChild
            };

            listHierarchy.AddRange(children);

            //Act
            var result = NodeManager.BuildHierarchy(listHierarchy);

            //Assert
            //Root has 1 parent with 4 children
            //1st children of root is a folder with 1 child
            Assert.IsTrue(result.Count == 1);
            Assert.IsTrue(result[0].Children.Count == 4);
            int firstChildChildrenCount = result[0].Children[0].Children.Count;

            Assert.IsTrue(firstChildChildrenCount == 1);
        }