public void GetterWithException() { TestingClass tc = new TestingClass(); MemberInfo propMember = typeof(TestingClass).GetProperty("Problem"); Assert.That(() => TypeUtils.GetMemberValue(tc, propMember), Throws.TypeOf <InvalidStateException>()); }
public void GetMemberValue() { TestingClass tc = new TestingClass(); tc.bSimpleStr = "BaseValue"; tc.simpleStr = "aValue"; MemberInfo fieldMember = typeof(TestingClass).GetField("simpleStr"); MemberInfo propMember = typeof(TestingClass).GetProperty("IntProp"); MemberInfo baseFieldMember = typeof(BaseTestingClass).GetField("bSimpleStr"); MemberInfo basePropMember = typeof(BaseTestingClass).GetProperty("BaseIntProp"); Assert.AreEqual("aValue", TypeUtils.GetMemberValue(tc, fieldMember)); Assert.AreEqual(31, TypeUtils.GetMemberValue(tc, propMember)); Assert.AreEqual("BaseValue", TypeUtils.GetMemberValue(tc, baseFieldMember)); Assert.AreEqual(37, TypeUtils.GetMemberValue(tc, basePropMember)); // the null value is used in ChildValidation // we don't take care if, for some reason, we are looking for a value of something else than a field or property MemberInfo methodMember = typeof(TestingClass).GetMethod("ToString"); Assert.IsNull(TypeUtils.GetMemberValue(tc, methodMember)); }
public void GetterWithException() { TestingClass tc = new TestingClass(); MemberInfo propMember = typeof(TestingClass).GetProperty("Problem"); TypeUtils.GetMemberValue(tc, propMember); }