public void Deep_Clones_Each_Item_Once() { var list = new DeepCloneableList <TestClone>(ListCloneBehavior.CloneOnce) { new TestClone(), new TestClone(), new TestClone() }; var cloned = list.DeepClone() as DeepCloneableList <TestClone>; // Test that each item in the sequence is equal - based on the equality comparer of TestClone (i.e. it's ID) Assert.IsTrue(list.SequenceEqual(cloned)); // Test that each instance in the list is not the same one foreach (TestClone item in list) { TestClone clone = cloned.Single(x => x.Id == item.Id); Assert.AreNotSame(item, clone); } // Clone again from the clone - since it's clone once the items should be the same var cloned2 = cloned.DeepClone() as DeepCloneableList <TestClone>; // Test that each item in the sequence is equal - based on the equality comparer of TestClone (i.e. it's ID) Assert.IsTrue(cloned.SequenceEqual(cloned2)); // Test that each instance in the list is the same one foreach (TestClone item in cloned) { TestClone clone = cloned2.Single(x => x.Id == item.Id); Assert.AreSame(item, clone); } }
public void Cloned_Sequence_Equals() { var list = new DeepCloneableList <TestClone>(ListCloneBehavior.Always) { new TestClone(), new TestClone(), new TestClone() }; var cloned = (DeepCloneableList <TestClone>)list.DeepClone(); // Test that each item in the sequence is equal - based on the equality comparer of TestClone (i.e. it's ID) Assert.IsTrue(list.SequenceEqual(cloned)); // Test that each instance in the list is not the same one foreach (TestClone item in list) { TestClone clone = cloned.Single(x => x.Id == item.Id); Assert.AreNotSame(item, clone); } }