public void TestInstanceProperty() { var reflector = new Reflector(typeof(PropertyTestTarget)); var obj = new PropertyTestTarget(3333); Assert.AreEqual(3333, reflector.GetProperty(obj, "Num")); reflector.SetProperty(obj, "Num", -1); Assert.AreEqual(-1, reflector.GetProperty(obj, "Num")); }
public void FindStaticPropertyIfInstanceIsNull() { var reflector = new Reflector(typeof(PropertyTestTarget)); PropertyTestTarget.SetStaticText("hoge"); Assert.AreEqual("hoge", reflector.GetProperty(null, "Text")); reflector.SetProperty(null, "Text", "あああ"); Assert.AreEqual("あああ", reflector.GetStaticProperty("Text")); }
public void TestStaticProperty() { var reflector = new Reflector(typeof(PropertyTestTarget)); PropertyTestTarget.SetStaticText("hoge"); Assert.AreEqual("hoge", reflector.GetStaticProperty("Text")); reflector.SetStaticProperty("Text", "あああ"); Assert.AreEqual("あああ", reflector.GetStaticProperty("Text")); }
public void ThrowIfPropertyTypeUnmatch() { var reflector = new Reflector(typeof(PropertyTestTarget)); var obj = new PropertyTestTarget(123); try { reflector.SetProperty(obj, "Num", "aaaaa"); Assert.Fail(); } catch (ArgumentException) { } }
public void TestIfPropertyNotFound() { var reflector = new Reflector(typeof(PropertyTestTarget)); var obj = new PropertyTestTarget(123); try { reflector.SetProperty(obj, "none", null); Assert.Fail(); } catch (MemberAccessException) { } try { var val = reflector.GetProperty(obj, "none"); Assert.Fail(); } catch (MemberAccessException) { } }
public void TearDown() { FieldTestTarget.SetStaticText(null); PropertyTestTarget.SetStaticText(null); }