Пример #1
0
        public void ToRelations_0_TopCode_Should_OK()
        {
            var treeItemHolder = new TreeItemHolder <MockTreeItem>();

            treeItemHolder.Value = new MockTreeItem()
            {
                Name = "A"
            };
            for (int i = 1; i <= 3; i++)
            {
                var child = new TreeItemHolder <MockTreeItem>();
                child.Value = new MockTreeItem()
                {
                    Name = "A." + i
                };
                treeItemHolder.Children.Add(child);
                for (int j = 1; j <= 3; j++)
                {
                    var cc = new TreeItemHolder <MockTreeItem>();
                    cc.Value = new MockTreeItem()
                    {
                        Name = child.Value.Name + j
                    };
                    child.Children.Add(cc);
                }
            }
            var mockTreeItems = treeItemHolder.ToRelations(0);

            //mockTreeItems.LogProperties();
            foreach (var mockTreeItem in mockTreeItems)
            {
                mockTreeItem.RelationCode.StartsWith("0").ShouldTrue();
            }
        }
Пример #2
0
        public void ToRelations_NullTree_Should_ThrowEx()
        {
            var treeItemHolder = new TreeItemHolder <MockTreeItem>();

            treeItemHolder.Value = null;
            treeItemHolder.ToRelations();
        }
Пример #3
0
        /// <summary>
        /// 树转换成列表,并计算好Position
        /// </summary>
        /// <param name="treeItemHolder"></param>
        /// <param name="relationCode"></param>
        /// <returns></returns>
        private static IList <T> SetRelations(TreeItemHolder <T> treeItemHolder, string relationCode)
        {
            var relations = new List <T>();

            if (relations.Count == 0)
            {
                //root
                if (treeItemHolder.Value == null)
                {
                    throw new InvalidOperationException("必须对Value进行赋值,然后使用");
                }
                treeItemHolder.Value.RelationCode = relationCode;
                relations.Add(treeItemHolder.Value);
            }

            if (treeItemHolder.Children != null && treeItemHolder.Children.Count > 0)
            {
                for (int i = 1; i <= treeItemHolder.Children.Count; i++)
                {
                    var    item = treeItemHolder.Children[i - 1];
                    string currentTreePosition = relationCode + "." + i;
                    var    childrenList        = SetRelations(item, currentTreePosition);
                    relations.AddRange(childrenList);
                }
            }

            return(relations);
        }
Пример #4
0
        public static IList <MockTreeItem> CreateMocksWithRelations()
        {
            var treeItemHolder = new TreeItemHolder <MockTreeItem>();

            treeItemHolder.Value = new MockTreeItem()
            {
                Name = "A"
            };
            for (int i = 1; i <= 3; i++)
            {
                var child = new TreeItemHolder <MockTreeItem>();
                child.Value = new MockTreeItem()
                {
                    Name = "A." + i
                };
                treeItemHolder.Children.Add(child);
                for (int j = 1; j <= 3; j++)
                {
                    var cc = new TreeItemHolder <MockTreeItem>();
                    cc.Value = new MockTreeItem()
                    {
                        Name = child.Value.Name + j
                    };
                    child.Children.Add(cc);
                }
            }
            return(treeItemHolder.ToRelations(1));
        }
Пример #5
0
        public void ToRelations_EmptyTree_Should_OK()
        {
            var treeItemHolder = new TreeItemHolder <MockTreeItem>();

            treeItemHolder.Value = new MockTreeItem()
            {
                Name = "A"
            };
            var mockTreeItems = treeItemHolder.ToRelations();

            //mockTreeItems.LogProperties();
            mockTreeItems.Count.ShouldEqual(1);
            mockTreeItems[0].RelationCode.ShouldEqual("1");
        }
Пример #6
0
        public static IList <MockTreeItem> CreateRelationsUnordered()
        {
            var treeItemHolder = new TreeItemHolder <MockTreeItem>();

            treeItemHolder.Value = new MockTreeItem()
            {
                Name = "A"
            };
            for (int i = 1; i <= 3; i++)
            {
                var child = new TreeItemHolder <MockTreeItem>();
                child.Value = new MockTreeItem()
                {
                    Name = "A." + i
                };
                treeItemHolder.Children.Add(child);
                for (int j = 1; j <= 3; j++)
                {
                    var cc = new TreeItemHolder <MockTreeItem>();
                    cc.Value = new MockTreeItem()
                    {
                        Name = child.Value.Name + j
                    };
                    child.Children.Add(cc);
                }
            }
            var mockTreeItems = treeItemHolder.ToRelations(1);

            //Name=A.14, RelationCode=1.1.4
            //Name=A.24, RelationCode=1.2.4
            mockTreeItems.Add(new MockTreeItem()
            {
                Name = "A.14", RelationCode = "1.1.4"
            });
            mockTreeItems.Add(new MockTreeItem()
            {
                Name = "A.24", RelationCode = "1.2.4"
            });
            return(mockTreeItems);
        }