public void CopyTo() { const int obj1Int = 45245; const string obj1String = "string1"; double? obj1NullableDouble = 45245.356356; const string obj1NotChange = "NotChange1"; const string obj1Field = "Field1"; const long obj2Long = 9898; DateTime obj2Date = DateTime.Now; float? obj2NullableFloat = 45245.356356F; const string obj2NotChange = "NotChange2"; const string obj2Field = "Field2"; var firstRefValue = new object(); var secondRefValue = new List<string>(); var obj1 = new FakeClass1 { Field = obj1Field, NumberProperty = obj1Int, NullableNumberProperty = obj1NullableDouble, OwnProperty1 = obj1NotChange, Date = obj1String, ReferenceProperty = firstRefValue }; var obj2 = new FakeClass2 { Field = obj2Field, NumberProperty = obj2Long, NullableNumberProperty = obj2NullableFloat, OwnProperty2 = obj2NotChange, Date = obj2Date, ReferenceProperty = secondRefValue }; Assert.IsFalse(obj2.CopyTo(obj1, CultureInfo.InvariantCulture)); Assert.AreEqual(obj2Field,obj2.Field); Assert.AreEqual(obj2Long, obj2.NumberProperty); Assert.AreEqual(obj2NullableFloat, obj2.NullableNumberProperty); Assert.AreEqual(obj2NotChange, obj2.OwnProperty2); Assert.AreEqual(obj2Date, obj2.Date); Assert.AreEqual(secondRefValue, obj2.ReferenceProperty); Assert.AreEqual(obj1Field, obj1.Field); Assert.AreEqual(Convert.ToInt32(obj2Long), obj1.NumberProperty); Assert.AreEqual(Convert.ToDouble(obj2NullableFloat.Value), obj1.NullableNumberProperty.Value); Assert.AreEqual(Convert.ToDouble(obj2NullableFloat.Value), obj1.NullableNumberProperty.Value); Assert.AreEqual(obj1NotChange, obj1.OwnProperty1); var dateDelta = obj2Date - DateTime.Parse(obj1.Date, CultureInfo.InvariantCulture); Assert.IsTrue(dateDelta.TotalSeconds < 1.0); Assert.IsTrue(Object.ReferenceEquals(firstRefValue, obj1.ReferenceProperty)); }
public void Set() { const int obj1Int = 45245; const string obj1String = "string1"; double? obj1NullableDouble = 45245.356356; const string obj1Field = "Field1"; const long obj2Long = 9898; float? obj2NullableFloat = 45245.356356F; var refValue = new object(); var obj1 = new FakeClass1 { Field = obj1Field, NumberProperty = obj1Int, NullableNumberProperty = obj1NullableDouble, Date = obj1String, ReferenceProperty = refValue }; Assert.IsFalse(obj1.Set("Field", "testValue")); Assert.AreEqual(obj1Field, obj1.Field); Assert.IsTrue(obj1.Set("NumberProperty", obj2Long)); Assert.AreEqual(Convert.ToInt32(obj2Long), obj1.NumberProperty); Assert.IsTrue(obj1.Set("NullableNumberProperty", obj2NullableFloat)); Assert.AreEqual(Convert.ToDouble(obj2NullableFloat.Value), obj1.NullableNumberProperty.Value); Assert.IsTrue(obj1.Set("NumberProperty", null)); Assert.AreEqual(0, obj1.NumberProperty); }