Ejemplo n.º 1
0
        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]);
        }
Ejemplo n.º 2
0
        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"));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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));
        }
Ejemplo n.º 13
0
        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));
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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
        }