public void TestForRestrictiveGetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); //this should be ok, because both get and set of the "Third" property are public third.SetValue(something, 456); Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty first = Create(typeof(Something).GetProperty("First")); first.SetValue(something, 123); //this should cause MethodAccessException, because get is private Assert.Throws<MethodAccessException>(() => first.GetValue(something)); }
public void TestForRestrictiveGetterWithSafeWrapper() { Something something = new Something(); //new SafeProperty() IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); //this should be ok, because both get and set of the "Third" property are public third.SetValue(something, 456); Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty first = Create(typeof(Something).GetProperty("First")); first.SetValue(something, 123); //this should not cause MethodAccessException, "first" is createtd using "CreateSafe" Assert.AreEqual(123, first.GetValue(something)); }
public void TestForRestrictiveSetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); third.SetValue(something, 456); //this should be ok, because both get and set of the "Third" property are public Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty second = Create(typeof(Something).GetProperty("Second")); Assert.AreEqual(2, second.GetValue(something)); //this should cause MethodAccessException, because set is private in "Second" property second.SetValue(something, 123); //this should never execute Assert.Throws<MethodAccessException>(() => second.GetValue(something)); }
public void TestForRestrictiveSetterWithSafeWrapper() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); third.SetValue(something, 456); //this should be ok, because both get and set of the "Third" property are public Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty second = Create(typeof(Something).GetProperty("Second")); Assert.AreEqual(2, second.GetValue(something)); //this should not cause MethodAccessException because "second" is created using "CreateSafe" second.SetValue(something, 123); Assert.AreEqual(123, second.GetValue(something)); }
public void TestForRestrictiveSetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); third.SetValue(something, 456); //this should be ok, because both get and set of the "Third" property are public Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty second = Create(typeof(Something).GetProperty("Second")); Assert.AreEqual(2, second.GetValue(something)); //this should cause MethodAccessException, because set is private in "Second" property second.SetValue(something, 123); //this should never execute Assert.AreEqual(123, second.GetValue(something)); }
public void TestForRestrictiveGetter() { Something something = new Something(); IDynamicProperty third = Create(typeof(Something).GetProperty("Third")); //this should be ok, because both get and set of the "Third" property are public third.SetValue(something, 456); Assert.AreEqual(456, third.GetValue(something)); IDynamicProperty first = Create(typeof(Something).GetProperty("First")); first.SetValue(something, 123); //this should cause MethodAccessException, because get is private Assert.AreEqual(123, first.GetValue(something)); }