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); }
public Child Add(Grandchild grandchild) { ChildrenList.Add(grandchild); return this; }
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); }
public Child Add(Grandchild grandchild) { ChildrenList.Add(grandchild); return(this); }