public void Can_Get_Correct_ReferenceType_Property_Value() { var referenceTypeProperty = typeof(MyTestClass).GetProperty("ReferenceTypeProperty", BindingFlags.Public | BindingFlags.Instance); Assert.NotNull(referenceTypeProperty); var referenceTypePropertyValueGetter = referenceTypeProperty.GetValueGetter(); Assert.NotNull(referenceTypePropertyValueGetter); var testClass = new MyTestClass(); var nullValue = referenceTypePropertyValueGetter(testClass); Assert.Null(nullValue); testClass.ReferenceTypeProperty = "418"; var fourOneEightValue = referenceTypePropertyValueGetter(testClass); Assert.IsType <string>(fourOneEightValue); Assert.Equal("418", fourOneEightValue); }
public void Can_Get_Correct_NullableType_PropertyValue() { var nullableTypeProperty = typeof(MyTestClass).GetProperty("NullableTypeProperty", BindingFlags.Public | BindingFlags.Instance); Assert.NotNull(nullableTypeProperty); var nullableTypePropertyValueGetter = nullableTypeProperty.GetValueGetter(); Assert.NotNull(nullableTypePropertyValueGetter); var testClass = new MyTestClass(); var nullValue = nullableTypePropertyValueGetter(testClass); Assert.Null(nullValue); testClass.NullableTypeProperty = 418; var fourOneEightValue = nullableTypePropertyValueGetter(testClass); Assert.Equal(typeof(int), fourOneEightValue.GetType()); Assert.Equal(418, fourOneEightValue); }
public void Can_Get_Correct_ValueType_Property_Value() { var valueTypeProperty = typeof(MyTestClass).GetProperty("ValueTypeProperty", BindingFlags.Public | BindingFlags.Instance); Assert.NotNull(valueTypeProperty); var valueTypePropertyValueGetter = valueTypeProperty.GetValueGetter(); Assert.NotNull(valueTypePropertyValueGetter); var testClass = new MyTestClass(); var zeroValue = valueTypePropertyValueGetter(testClass); Assert.IsType <int>(zeroValue); Assert.Equal(0, zeroValue); testClass.ValueTypeProperty = 418; var fourOneEightValue = valueTypePropertyValueGetter(testClass); Assert.IsType <int>(fourOneEightValue); Assert.Equal(418, fourOneEightValue); }