public void EmitterEmitObjectComparerTest() { AccessedStruct obj1 = new AccessedStruct { IntegerData = 10, TextData = "Text1" }; AccessedStruct obj2 = new AccessedStruct { IntegerData = 20, TextData = "Text2" }; Type type = typeof(AccessedStruct); Func <object, object, List <string> > comparer = Emitter.EmitObjectComparer(type); List <string> diffProperties = comparer(obj1, obj2); Assert.AreEqual(2, diffProperties.Count); Assert.AreEqual("TextData", diffProperties[0]); Assert.AreEqual("IntegerData", diffProperties[1]); }
public void TypeAccessorStructGetValueTest() { AccessedStruct obj = new AccessedStruct(); TypeAccessor accessor = obj.GetTypeAccessor(); obj.TextData = "Some text"; obj.IntegerData = 427; Assert.AreEqual("Some text", accessor.GetValue(obj, "TextData")); Assert.AreEqual(427, accessor.GetValue(obj, "IntegerData")); }
public void TypeAccessorStructSetValueUsingInterfaceTest() { IAccessed obj = new AccessedStruct(); TypeAccessor accessor = obj.GetTypeAccessor(); accessor.SetValue(obj, "TextData", "Some text"); accessor.SetValue(obj, "IntegerData", 427); Assert.AreEqual("Some text", obj.TextData); Assert.AreEqual(427, obj.IntegerData); }
public void TypeAccessorStructSetValueTest() { AccessedStruct obj = new AccessedStruct(); TypeAccessor accessor = obj.GetTypeAccessor(); accessor.SetValue(obj, "TextData", "Some text"); accessor.SetValue(obj, "IntegerData", 427); Assert.IsNull(obj.TextData); Assert.AreEqual(0, obj.IntegerData); }
public void EmitterEmitPropertyGetterIntegerStructTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("IntegerData"); Func <object, object> getter = Emitter.EmitPropertyGetter(propertyInfo); int value = 427; AccessedStruct obj = new AccessedStruct(); obj.IntegerData = value; Assert.AreEqual(value, getter(obj)); }
public void EmitterEmitPropertyGetterStringStructTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("TextData"); Func <object, object> getter = Emitter.EmitPropertyGetter(propertyInfo); string value = "Some text"; AccessedStruct obj = new AccessedStruct(); obj.TextData = value; Assert.AreEqual(value, getter(obj)); }
public void EmitterEmitPropertySetterIntegerStructTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("IntegerData"); Action <object, object> setter = Emitter.EmitPropertySetter(propertyInfo); int value = 427; IAccessed obj = new AccessedStruct(); setter(obj, value); Assert.AreEqual(value, obj.IntegerData); }
public void EmitterEmitPropertySetterStringStructTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("TextData"); Action <object, object> setter = Emitter.EmitPropertySetter(propertyInfo); string value = "Some text"; IAccessed obj = new AccessedStruct(); setter(obj, value); Assert.AreEqual(value, obj.TextData); }
public void PropertyAccessorStructSetValueIntUsingInterfaceTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("IntegerData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); int value = 427; IAccessed obj = new AccessedStruct(); accessor.SetValue(obj, value); Assert.AreEqual(value, obj.IntegerData); }
public void PropertyAccessorStructSetValueIntTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("IntegerData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); int value = 427; AccessedStruct obj = new AccessedStruct(); accessor.SetValue(obj, value); Assert.AreEqual(0, obj.IntegerData); // It does not set the value }
public void EmitterEmitObjectClonerStructTest() { AccessedStruct objToClone = new AccessedStruct { IntegerData = 10, TextData = "Text1" }; Type type = typeof(AccessedStruct); Func <object, object> cloner = Emitter.EmitObjectCloner(type); AccessedStruct clone = (AccessedStruct)cloner(objToClone); Assert.AreEqual(clone.IntegerData, objToClone.IntegerData); Assert.AreEqual(clone.TextData, objToClone.TextData); }
public void PropertyAccessorStructGetValueIntTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("IntegerData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); int value = 427; AccessedStruct obj = new AccessedStruct(); obj.IntegerData = value; Assert.AreEqual(value, accessor.GetValue(obj)); }
public void PropertyAccessorStructGetValueStringTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("TextData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); string value = "Some text"; AccessedStruct obj = new AccessedStruct(); obj.TextData = value; Assert.AreEqual(value, accessor.GetValue(obj)); }
public void PropertyAccessorStructSetValueStringUsingInterfaceTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("TextData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); string value = "Some text"; IAccessed obj = new AccessedStruct(); Assert.IsNull(obj.TextData); accessor.SetValue(obj, value); Assert.AreEqual(value, obj.TextData); }
public void PropertyAccessorStructSetValueStringTest() { Type type = typeof(AccessedStruct); PropertyInfo propertyInfo = type.GetProperty("TextData"); PropertyAccessor accessor = new PropertyAccessor(propertyInfo); Assert.IsTrue(accessor.CanGet); Assert.IsTrue(accessor.CanSet); Assert.AreEqual(propertyInfo.PropertyType, accessor.PropertyType); string value = "Some text"; AccessedStruct obj = new AccessedStruct(); Assert.IsNull(obj.TextData); accessor.SetValue(obj, value); Assert.IsNull(obj.TextData); // It does not set the value }