示例#1
0
文件: Test.cs 项目: chakarov/Clonus
 public void Clone_WithArray_WithNestedCircularReference_ShouldWork()
 {
     var original = new TestObject_ParentCircularReference[] {
         new TestObject_ParentCircularReference { Id = 1, Name = "Test1" },
         new TestObject_ParentCircularReference { Id = 2, Name = "Test2" }
     };
     original[0].Child = new TestObject_ChildCircularReference { Name = "Child", Parent = original[0] };
     original[1].Child = new TestObject_ChildCircularReference { Name = "Child", Parent = original[1] };
     var clone = Cloner.Clone(original, CloneMethod.Deep);
     for (var i = 0; i < original.Length; i++)
     {
         Assert.AreEqual(original[i].Child.Name, clone[i].Child.Name);
         Assert.AreEqual(original[i].Child.Parent.Name, clone[i].Child.Parent.Name);
         Assert.IsTrue(ReferenceEquals(clone[i], clone[i].Child.Parent), "When cloning circular references, referential integrity should be preserved");
     }
 }
示例#2
0
文件: Test.cs 项目: chakarov/Clonus
 public void Clone_WithNestedCircularReference_ShouldWork()
 {
     var original = new TestObject_ParentCircularReference { Id = 1, Name = "Parent" };
     original.Child = new TestObject_ChildCircularReference { Id = 2, Name = "Child" };
     original.Child.Parent = original;
     var clone = Cloner.Clone(original, CloneMethod.Deep);
     Assert.AreEqual(original.Name, clone.Name);
     Assert.AreEqual(original.Child.Name, clone.Child.Name);
     Assert.AreEqual(original.Child.Parent.Name, clone.Child.Parent.Name);
     Assert.IsTrue(ReferenceEquals(clone, clone.Child.Parent), "When cloning circular references, referential integrity should be preserved");
     Assert.IsTrue(ReferenceEquals(clone.Child, clone.Child.Parent.Child), "When cloning circular references, referential integrity should be preserved");
 }