public void DeepCopy_Should_Create_Exact_And_Independent_Copy_Of_An_Object() { var instance = new CustomSerializableType { DateTimeValueType = DateTime.Now.AddDays(1).AddMilliseconds(123).AddTicks(123), NumericValueType = 777, StringValueType = Guid.NewGuid().ToString(), ReferenceType = new CustomSerializableType { DateTimeValueType = DateTime.Now, StringValueType = Guid.NewGuid().ToString() } }; var deepCopy = instance.DeepCopy(true); Assert.NotNull(deepCopy); Assert.False(ReferenceEquals(instance, deepCopy)); Assert.True(instance.NumericValueType == deepCopy.NumericValueType); Assert.True(instance.DateTimeValueType == deepCopy.DateTimeValueType); Assert.True(instance.StringValueType == deepCopy.StringValueType); Assert.NotNull(deepCopy.ReferenceType); Assert.False(ReferenceEquals(instance.ReferenceType, deepCopy.ReferenceType)); Assert.True(instance.ReferenceType.DateTimeValueType == deepCopy.ReferenceType.DateTimeValueType); Assert.True(instance.ReferenceType.StringValueType == deepCopy.ReferenceType.StringValueType); }
public void DeepCopyShouldCreateExactAndIndependentCopyOfAnObject() { var instance = new CustomSerializableType { DateTimeValueType = DateTime.Now.AddDays(1).AddMilliseconds(123).AddTicks(123), NumericValueType = 777, StringValueType = Guid.NewGuid().ToString(), ReferenceType = new CustomSerializableType { DateTimeValueType = DateTime.Now, StringValueType = Guid.NewGuid().ToString() } }; var deepCopy = instance.DeepCopy(true); Assert.IsNotNull(deepCopy); Assert.IsFalse(ReferenceEquals(instance, deepCopy)); Assert.That(instance.NumericValueType == deepCopy.NumericValueType); Assert.That(instance.DateTimeValueType == deepCopy.DateTimeValueType); Assert.That(instance.StringValueType == deepCopy.StringValueType); Assert.IsNotNull(deepCopy.ReferenceType); Assert.IsFalse(ReferenceEquals(instance.ReferenceType, deepCopy.ReferenceType)); Assert.That(instance.ReferenceType.DateTimeValueType == deepCopy.ReferenceType.DateTimeValueType); Assert.That(instance.ReferenceType.StringValueType == deepCopy.ReferenceType.StringValueType); }
public void MemberWiseDeepClone_Test() { //Arrange CustomSerializableType customSerializable = new CustomSerializableType { DateTimeValueType = DateTime.Now.AddDays(1).AddMilliseconds(123).AddTicks(123), NumericValueType = 777, StringValueType = Guid.NewGuid().ToString(), ReferenceType = new CustomSerializableType { DateTimeValueType = DateTime.Now, StringValueType = Guid.NewGuid().ToString() } }; //Act CustomSerializableType clonedCustomSerializable = customSerializable.MemberWiseDeepClone(); //Assert Assert.IsNotNull(clonedCustomSerializable); Assert.IsFalse(ReferenceEquals(customSerializable, clonedCustomSerializable)); Assert.That(customSerializable.NumericValueType == clonedCustomSerializable.NumericValueType); Assert.That(customSerializable.DateTimeValueType == clonedCustomSerializable.DateTimeValueType); Assert.That(customSerializable.StringValueType == clonedCustomSerializable.StringValueType); Assert.IsNotNull(customSerializable.ReferenceType); Assert.IsFalse(ReferenceEquals(customSerializable.ReferenceType, clonedCustomSerializable.ReferenceType)); Assert.That(customSerializable.ReferenceType.DateTimeValueType == clonedCustomSerializable.ReferenceType.DateTimeValueType); Assert.That(customSerializable.ReferenceType.StringValueType == clonedCustomSerializable.ReferenceType.StringValueType); }
public void TestWriteObjectWithCustomSerializable() { var config = new SerializationConfig(); var sc = new SerializerConfig() .SetImplementation(new CustomSerializer()) .SetTypeClass(typeof (CustomSerializableType)); config.AddSerializerConfig(sc); var serializationService = new SerializationServiceBuilder().SetPortableVersion(1) .AddPortableFactory(TestSerializationConstants.PORTABLE_FACTORY_ID, new TestPortableFactory()) .SetConfig(config).Build(); var foo = new CustomSerializableType {Value = "foo"}; var objectCarryingPortable1 = new ObjectCarryingPortable(foo); var data = serializationService.ToData(objectCarryingPortable1); var objectCarryingPortable2 = serializationService.ToObject<ObjectCarryingPortable>(data); Assert.AreEqual(objectCarryingPortable1, objectCarryingPortable2); }