public void DeepClone_StackBaseCollectionRefDefinedBefore_AsReference(TypeModel model) { var inner = new StackBaseCollection<IItemClass>(); var itemClass = new ItemClass() { Message = "Hi" }; inner.Push(itemClass); inner.Push(itemClass); var obj = new StackBaseCollectionWrapper<IItemClass>() { AItem = itemClass, Collection = inner }; var clone = (StackBaseCollectionWrapper<IItemClass>)model.DeepClone(obj); Assert.AreEqual(obj.AItem.Message, clone.AItem.Message); Assert.AreEqual(obj.Collection.Count, clone.Collection.Count); var firstObj = obj.Collection.Pop(); var firstCloneObj = clone.Collection.Pop(); Assert.AreEqual(firstObj.Message, firstCloneObj.Message); var secondObj = obj.Collection.Pop(); var secondCloneObj = clone.Collection.Pop(); Assert.AreEqual(secondObj.Message, secondCloneObj.Message); Assert.IsTrue(object.ReferenceEquals(obj.AItem, firstObj), "Original reference Item-Collection failed"); Assert.IsTrue(object.ReferenceEquals(firstObj, secondObj), "Original reference Collection-Collection failed"); Assert.IsTrue(object.ReferenceEquals(clone.AItem, firstCloneObj), "Clone reference Item-Collection not maintained"); Assert.IsTrue(object.ReferenceEquals(firstCloneObj, secondCloneObj), "Clone reference Collection-Collection not maintained"); }
public void DeepClone_StackBaseCollection_AsReference(TypeModel model) { var inner = new StackBaseCollection<IItemClass>(); inner.Push( new ItemClass() { Message = "Hi" }); inner.Push( new ItemClass() { Message = "There bro" }); var obj = new StackBaseCollectionWrapper<IItemClass>() { Collection = inner }; var clone = (StackBaseCollectionWrapper<IItemClass>)model.DeepClone(obj); Assert.AreEqual(obj.Collection.Count, clone.Collection.Count); Assert.AreEqual(obj.Collection.Pop().Message, clone.Collection.Pop().Message); Assert.AreEqual(obj.Collection.Pop().Message, clone.Collection.Pop().Message); }