Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        private static void AppendNode(IList <MockTreeItem> items, int nodeCountPerDeep, string parentId, int deep)
        {
            if (deep == 0)
            {
                return;
            }

            var isTop = string.IsNullOrWhiteSpace(parentId);

            for (int i = 0; i < nodeCountPerDeep; i++)
            {
                var item = new MockTreeItem();
                item.Id       = isTop ? string.Format("{0}.", i + 1) : string.Format("{0}{1}.", parentId, i + 1);
                item.Name     = "标题" + item.Id;
                item.ParentId = parentId;
                items.Add(item);

                AppendNode(items, nodeCountPerDeep, item.Id, deep - 1);
            }
        }
Ejemplo n.º 5
0
        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);
                }
            }
        }