コード例 #1
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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]);
        }
コード例 #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"));
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #5
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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));
        }
コード例 #6
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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));
        }
コード例 #7
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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);
        }
コード例 #8
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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);
        }
コード例 #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);
        }
コード例 #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
        }
コード例 #11
0
ファイル: EmitterTest.cs プロジェクト: jgonte/Utilities
        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);
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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);
        }
コード例 #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
        }