//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)); }
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 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)); }
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)); }
//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)); Assert.Throws<FieldAccessException>(() => fi.SetValue(myInstance, newvalue)); }