Esempio n. 1
0
        //Helper method to Verify constant Field can not be set using Reflection
        public void TestSetValue_constantField(string field, object newvalue)
        {
            FieldInfo fi = GetField(field);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.True(fi.Name.Equals(field));
            Assert.Throws <FieldAccessException>(() => fi.SetValue(myInstance, newvalue));
        }
Esempio n. 2
0
        public void SetValue_ConstantField_Fails(string fieldName, object newValue)
        {
            FieldInfo fi = GetField(fieldName);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.Equal(fieldName, fi.Name);
            Assert.Throws<FieldAccessException>(() => fi.SetValue(myInstance, newValue));
        }
Esempio n. 3
0
        public void SetValue_ConstantField_Fails(string fieldName, object newValue)
        {
            FieldInfo fi = GetField(fieldName);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.Equal(fieldName, fi.Name);
            Assert.Throws <FieldAccessException>(() => fi.SetValue(myInstance, newValue));
        }
        public void TestSetValue_roIntField()
        {
            FieldInfo fi = typeof(FieldInfoConstantTests).GetTypeInfo().GetDeclaredField("rointField");
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.NotNull(myInstance);

            object current = fi.GetValue(myInstance);
            Assert.Equal(1, current);

            fi.SetValue(myInstance, Int32.MinValue);

            Assert.Equal(Int32.MinValue, fi.GetValue(myInstance));
        }
Esempio n. 5
0
        public void SetValue_ReadOnlyIntField_Succeeds()
        {
            FieldInfo fi = typeof(FieldInfoConstantTests).GetTypeInfo().GetDeclaredField("readOnlyIntField");
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.NotNull(myInstance);

            object current = fi.GetValue(myInstance);
            Assert.Equal(1, current);

            fi.SetValue(myInstance, int.MinValue);

            Assert.Equal(int.MinValue, fi.GetValue(myInstance));
        }
Esempio n. 6
0
        //Helper method to Verify constant Field can not be set using Reflection
        public void TestSetValue_constantField(string field, object newvalue)
        {
            FieldInfo fi = GetField(field);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.True(fi.Name.Equals(field));

            try
            {
                fi.SetValue(myInstance, newvalue);
                Assert.False(true, "Exception expected.");
            }
            catch (Exception) { }
        }
        //Helper method to Verify constant Field can not be set using Reflection
        public void TestSetValue_constantField(string field, object newvalue)
        {
            FieldInfo fi = GetField(field);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.True(fi.Name.Equals(field));

            try
            {
                fi.SetValue(myInstance, newvalue);
                Assert.False(true, "Exception expected.");
            }
            catch (Exception) { }
        }
Esempio n. 8
0
        public void TestSetValue_roIntField()
        {
            FieldInfo fi = typeof(FieldInfoConstantTests).GetTypeInfo().GetDeclaredField("rointField");
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.NotNull(myInstance);

            object current = fi.GetValue(myInstance);

            Assert.Equal(1, current);

            fi.SetValue(myInstance, Int32.MinValue);

            Assert.Equal(Int32.MinValue, fi.GetValue(myInstance));
        }
Esempio n. 9
0
        public void SetValue_ReadOnlyIntField_Succeeds()
        {
            FieldInfo fi = typeof(FieldInfoConstantTests).GetTypeInfo().GetDeclaredField("readOnlyIntField");
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.NotNull(myInstance);

            object current = fi.GetValue(myInstance);

            Assert.Equal(1, current);

            fi.SetValue(myInstance, int.MinValue);

            Assert.Equal(int.MinValue, fi.GetValue(myInstance));
        }
Esempio n. 10
0
        //Helper method to Verify constant Field can not be set using Reflection
        public void TestSetValue_constantField(string field, object newvalue)
        {
            FieldInfo fi = GetField(field);
            FieldInfoConstantTests myInstance = new FieldInfoConstantTests();

            Assert.NotNull(fi);
            Assert.True(fi.Name.Equals(field));
            Assert.Throws<FieldAccessException>(() => fi.SetValue(myInstance, newvalue));
        }