示例#1
0
        public void TestDeepGraph()
        {
            Parent parent = Parent.Create().SetId(1).SetName("parent");
            Child  child  = new Child()
            {
                Id = 2, Name = "child", Parent = parent
            };

            parent.ChildList.Add(child);
            Grandchild grandchild = new Grandchild()
            {
                Id = 3, Name = "granchild", Parent = child
            };

            child.Add(grandchild);

            Parent parentCopy =
                parent
                .Graph()
                .Add(p => p.ChildList, new Graph <Child>()
                     .Add(c => c.Children, new Graph <Grandchild>()
                          .Add(g => g.Parent)))
                .Copy();

            Assert.AreNotEqual(parent, parentCopy);
            Child childCopy = parentCopy.ChildList[0];

            Assert.AreNotEqual(child, childCopy);
            Assert.AreEqual(2, childCopy.Id);
            Child grandchildParent = childCopy.Children.First().Parent;

            Assert.AreNotEqual(child, grandchildParent);
            Assert.AreNotEqual(childCopy, grandchildParent);
            Assert.AreEqual(2, grandchildParent.Id);
        }
示例#2
0
 public Child Add(Grandchild grandchild)
 {
     ChildrenList.Add(grandchild); return this;
 }
示例#3
0
        public void TestDeepGraph()
        {
            Parent parent = Parent.Create().SetId(1).SetName("parent");
            Child child = new Child() { Id=2, Name="child", Parent=parent };
            parent.ChildList.Add(child);
            Grandchild grandchild = new Grandchild() { Id=3, Name="granchild", Parent=child };
            child.Add(grandchild);

            Parent parentCopy =
                parent
                    .Graph()
                    .Add(p => p.ChildList, new Graph<Child>()
                        .Add(c => c.Children, new Graph<Grandchild>()
                            .Add(g => g.Parent)))
                    .Copy();

            Assert.AreNotEqual(parent, parentCopy);
            Child childCopy = parentCopy.ChildList[0];
            Assert.AreNotEqual(child, childCopy);
            Assert.AreEqual(2, childCopy.Id);
            Child grandchildParent = childCopy.Children.First().Parent;
            Assert.AreNotEqual(child, grandchildParent);
            Assert.AreNotEqual(childCopy, grandchildParent);
            Assert.AreEqual(2, grandchildParent.Id);
        }
示例#4
0
 public Child Add(Grandchild grandchild)
 {
     ChildrenList.Add(grandchild); return(this);
 }