public void ConvertToHolders_top_level_should_ok()
        {
            var perCount        = 2;
            var maxDeep         = 3;
            var mockTreeItems   = MockTreeItem.Create(perCount, maxDeep);
            var treeItemHolders = TreeItemHolder <MockTreeItem> .ConvertToHolders(mockTreeItems, item => item.Id, item => item.ParentId, null);

            ShowTreeHolders(treeItemHolders);

            treeItemHolders.Count.ShouldEqual(2);
        }
        public void MaxDeep_should_ok()
        {
            var perCount        = 1;
            var maxDeep         = 4;
            var mockTreeItems   = MockTreeItem.Create(perCount, maxDeep);
            var treeItemHolders = TreeItemHolder <MockTreeItem> .ConvertToHolders(mockTreeItems, item => item.Id, item => item.ParentId, null);

            ShowTreeHolders(treeItemHolders);

            var treeItemHolder = treeItemHolders[0];

            treeItemHolder.MaxDeep().ShouldEqual(maxDeep);
        }
        public void Search_should_ok()
        {
            var perCount        = 2;
            var maxDeep         = 3;
            var mockTreeItems   = MockTreeItem.Create(perCount, maxDeep);
            var treeItemHolders = TreeItemHolder <MockTreeItem> .ConvertToHolders(mockTreeItems, item => item.Id, item => item.ParentId, null);

            ShowTreeHolders(treeItemHolders);
            var treeItemHolder = treeItemHolders[0];

            treeItemHolder.Search(item => item.Id, "NotExistId").ShouldNull("NotExistId");
            treeItemHolder.Search(item => item.Id, "1.").ShouldNotNull();
            treeItemHolder.Search(item => item.Id, "1.1.").ShouldNotNull();
            treeItemHolder.Search(item => item.Id, "1.1.1.").ShouldNotNull();
        }
Exemple #4
0
        public static IList <MockTreeItemTree> ConvertTrees(IList <MockTreeItem> items)
        {
            var trees = new List <MockTreeItemTree>();

            if (items.IsNullOrEmpty())
            {
                return(trees);
            }

            var holders = TreeItemHolder <MockTreeItem> .ConvertToHolders(items, item => item.Id, item => item.ParentId, null);

            foreach (var holder in holders)
            {
                var itemTree = holder.ConvertToTree(item => item.ToMapped <MockTreeItemTree>(), tree => tree.Children);
                trees.Add(itemTree);
            }
            return(trees);
        }
        public void ConvertToTree_should_ok()
        {
            var perCount        = 2;
            var maxDeep         = 3;
            var mockTreeItems   = MockTreeItem.Create(perCount, maxDeep);
            var treeItemHolders = TreeItemHolder <MockTreeItem> .ConvertToHolders(mockTreeItems, item => item.Id, item => item.ParentId, null);

            ShowTreeHolders(treeItemHolders);
            var treeItemHolder = treeItemHolders[0];

            var mockTreeItemTree = treeItemHolder.ConvertToTree(
                item => item.ToMapped <MockTreeItemTree>(),
                tree => tree.Children);

            AssertChildren(mockTreeItemTree, 1, perCount);
            foreach (var childTree in mockTreeItemTree.Children)
            {
                AssertChildren(childTree, 2, perCount);
                foreach (var childChildTree in childTree.Children)
                {
                    AssertChildren(childChildTree, 3, 0);
                }
            }
        }