public void ReflectionUtility_GetPropertyValue_3()
        {
            CanaryClass canary = new CanaryClass();
            int         actual = (int)ReflectionUtility.GetPropertyValue(canary, "NoSetterProperty");

            Assert.AreEqual(canary.NoSetterProperty, actual);
        }
        public void ReflectionUtility_SetPropertyValue_4()
        {
            int         expected = 12345;
            CanaryClass canary   = new CanaryClass();

            ReflectionUtility.SetPropertyValue(canary, "NoSuchProperty", expected);
        }
Esempio n. 3
0
        public void PropertyOrField_Get_Set_2()
        {
            CanaryClass canary = new CanaryClass
            {
                BooleanField = true
            };
            Type      type = canary.GetType();
            FieldInfo info = type.GetField("BooleanField");

            Assert.IsNotNull(info);
            PropertyOrField field = new PropertyOrField(info);

            Assert.AreSame(info, field.FieldInfo);
            Assert.IsNull(field.PropertyInfo);
            Assert.AreEqual("BooleanField", field.Name);
            Assert.IsTrue(field.MemberType == typeof(bool));
            Assert.IsFalse(field.IsProperty);
            Assert.IsFalse(field.IsIndexed);
            Assert.IsFalse(field.ReadOnly);

            Assert.AreEqual(true, field.GetValue(canary));

            field.SetValue(canary, false);
            Assert.AreEqual(false, canary.BooleanField);

            Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false));

            Assert.AreEqual("BooleanField", field.ToString());
        }
Esempio n. 4
0
        public void PropertyOrField_Get_Set_1()
        {
            CanaryClass canary = new CanaryClass
            {
                Int32Field = 123
            };
            Type      type = canary.GetType();
            FieldInfo info = type.GetField("Int32Field");

            Assert.IsNotNull(info);
            PropertyOrField field = new PropertyOrField(info);

            Assert.AreSame(info, field.FieldInfo);
            Assert.IsNull(field.PropertyInfo);
            Assert.AreEqual("Int32Field", field.Name);
            Assert.IsTrue(field.MemberType == typeof(int));
            Assert.IsFalse(field.IsProperty);
            Assert.IsFalse(field.IsIndexed);
            Assert.IsFalse(field.ReadOnly);

            Assert.AreEqual(123, field.GetValue(canary));

            field.SetValue(canary, 321);
            Assert.AreEqual(321, canary.Int32Field);

            Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false));

            Assert.AreEqual("Int32Field", field.ToString());
        }
Esempio n. 5
0
        public void PropertyOrField_Get_Set_4()
        {
            CanaryClass canary = new CanaryClass
            {
                Int32Property = 123
            };
            Type         type = canary.GetType();
            PropertyInfo info = type.GetProperty("Int32Property");

            Assert.IsNotNull(info);
            PropertyOrField property = new PropertyOrField(info);

            Assert.AreSame(info, property.PropertyInfo);
            Assert.IsNull(property.FieldInfo);
            Assert.AreEqual("Int32Property", property.Name);
            Assert.IsTrue(property.MemberType == typeof(int));
            Assert.IsTrue(property.IsProperty);
            Assert.IsFalse(property.IsIndexed);
            Assert.IsFalse(property.ReadOnly);

            Assert.AreEqual(123, property.GetValue(canary));

            property.SetValue(canary, 321);
            Assert.AreEqual(321, canary.Int32Property);

            Assert.IsTrue(property.HaveAttribute <DisplayNameAttribute>(false));
            DisplayNameAttribute attribute = property.GetCustomAttribute <DisplayNameAttribute>(false);

            Assert.IsNotNull(attribute);
            Assert.AreEqual("CanaryProperty", attribute.DisplayName);

            Assert.AreEqual("Int32Property", property.ToString());
        }
Esempio n. 6
0
        public void PropertyOrField_Get_Set_3()
        {
            CanaryClass canary = new CanaryClass
            {
                StringField = "Text"
            };
            Type      type = canary.GetType();
            FieldInfo info = type.GetField("StringField");

            Assert.IsNotNull(info);
            PropertyOrField field = new PropertyOrField(info);

            Assert.AreSame(info, field.FieldInfo);
            Assert.IsNull(field.PropertyInfo);
            Assert.AreEqual("StringField", field.Name);
            Assert.IsTrue(field.MemberType == typeof(string));
            Assert.IsFalse(field.IsProperty);
            Assert.IsFalse(field.IsIndexed);
            Assert.IsFalse(field.ReadOnly);

            Assert.AreEqual("Text", field.GetValue(canary));

            field.SetValue(canary, "Text2");
            Assert.AreEqual("Text2", canary.StringField);

            Assert.IsFalse(field.HaveAttribute <DisplayNameAttribute>(false));

            Assert.AreEqual("StringField", field.ToString());
        }
        public void ReflectionUtility_SetPropertyValue_2()
        {
            int         expected = 12345;
            CanaryClass canary   = new CanaryClass();

            ReflectionUtility.SetPropertyValue(canary, "Int32Property", expected);
            Assert.AreEqual(expected, canary.Int32Property);
        }
        public void ReflectionUtility_SetPropertyValue_1()
        {
            string      expected = "Text";
            CanaryClass canary   = new CanaryClass();

            ReflectionUtility.SetPropertyValue(canary, "StringProperty", expected);
            Assert.AreEqual(expected, canary.StringProperty);
        }
        public void ReflectionUtility_GetPropertyValue_2()
        {
            CanaryClass canary = new CanaryClass
            {
                BooleanProperty = true
            };
            bool actual = (bool)ReflectionUtility.GetPropertyValue(canary, "BooleanProperty");

            Assert.AreEqual(canary.BooleanProperty, actual);
        }
        public void ReflectionUtility_GetPropertyValue_1()
        {
            CanaryClass canary = new CanaryClass
            {
                StringProperty = "Text"
            };
            string actual = (string)ReflectionUtility.GetPropertyValue(canary, "StringProperty");

            Assert.AreEqual(canary.StringProperty, actual);
        }
        public void ReflectionUtility_GetFieldValue_1()
        {
            CanaryClass canary = new CanaryClass
            {
                StringField = "Text"
            };
            string actual = (string)ReflectionUtility.GetFieldValue(canary, "StringField");

            Assert.AreEqual(canary.StringField, actual);
        }
        public void ReflectionUtility_GetFieldValue_2()
        {
            CanaryClass canary = new CanaryClass();

            ReflectionUtility.GetFieldValue(canary, "NoSuchField");
        }
        public void ReflectionUtility_GetPropertyValue_4()
        {
            CanaryClass canary = new CanaryClass();

            ReflectionUtility.GetPropertyValue(canary, "NoSuchProperty");
        }