public void DeepClone_DictionaryOfClassRef_AsReference(TypeModel model) { var itemClass = new ItemClass() { Message = "hello"}; var dictionary = new DictionaryOfClass() { Collection = new Dictionary<int, ItemClass> { { 1, itemClass }, { 2, itemClass } } }; var clone = (DictionaryOfClass)model.DeepClone(dictionary); Assert.AreEqual(dictionary.Collection.Count, clone.Collection.Count); foreach (var key in dictionary.Collection.Keys) { Assert.AreEqual(dictionary.Collection[key].Message, clone.Collection[key].Message); } Assert.IsTrue(object.ReferenceEquals(dictionary.Collection[1], dictionary.Collection[2]), "Original reference failed"); Assert.IsTrue(object.ReferenceEquals(clone.Collection[1], clone.Collection[2]), "Clone reference not maintained"); }
public void DeepClone_DictionaryOfClass_AsReference(TypeModel model) { var dictionary = new DictionaryOfClass() { Collection = new Dictionary<int, ItemClass> { { 1, new ItemClass() { Message = "hello"} }, { 2, new ItemClass() { Message = "world"} } } }; var clone = (DictionaryOfClass)model.DeepClone(dictionary); Assert.AreEqual(dictionary.Collection.Count, clone.Collection.Count); foreach (var key in dictionary.Collection.Keys) { Assert.AreEqual(dictionary.Collection[key].Message, clone.Collection[key].Message); } }
public void DeepClone_DictionaryWithNullItem_AsReference(TypeModel model) { var dictionary = new DictionaryOfClass() { Collection = new Dictionary<int, ItemClass>() { { 1 , new ItemClass() { Message = "Hi there"} }, { 2 , null }, { 3, new ItemClass() { Message = "How are you ?" } } } }; var clone = (DictionaryOfClass)model.DeepClone(dictionary); Assert.AreEqual(dictionary.Collection.Count, clone.Collection.Count); Assert.AreEqual(dictionary.Collection[1].Message, clone.Collection[1].Message); Assert.IsNull(clone.Collection[2]); Assert.AreEqual(dictionary.Collection[3].Message, clone.Collection[3].Message); }
public void DeepClone_DictionaryEmpty_NotAsReference(TypeModel model) { var manualModel = TypeModel.Create(); manualModel.Add(typeof (DictionaryOfClass), true).AddField(1, "Collection"); manualModel.Add(typeof (ItemClass), true); var dictionary = new DictionaryOfClass() { Collection = new Dictionary<int, ItemClass>() }; var clone = (DictionaryOfClass)manualModel.DeepClone(dictionary); Assert.IsNotNull(clone.Collection); Assert.AreEqual(clone.Collection.Count, 0); }
public void DeepClone_DictionaryEmpty_AsReference(TypeModel model) { var dictionary = new DictionaryOfClass() { Collection = new Dictionary<int, ItemClass>() }; var clone = (DictionaryOfClass)model.DeepClone(dictionary); Assert.IsNotNull(clone.Collection); Assert.AreEqual(clone.Collection.Count, 0); }