public void GetFullPropertyPathName_FromInstanceNestedProperty_ReturnsFullPath() { Expression<Func<TestModel, object>> exp = x => x.Nested.Deep; var obj = new TestModel { Id = 1, MyString = null, CreatedAt = DateTime.MaxValue, Nested = new NestedModel { Deep = "Going Deep" } }; var result = Reflect.OnProperties.GetFullPropertyPathName<TestModel, object>(exp); Assert.Equal("Nested.Deep", result); }
public void GetValue_FromInstance_ReturnsValue() { Expression<Func<TestModel, object>> exp = x => x.MyString; var obj = new TestModel { Id = 1, MyString = "The Value" }; var result = Reflect.OnProperties.GetValue<TestModel, object>(obj, exp); Assert.Equal("The Value", result); }
public void SetProperty_PublicProperty_SetsProperty() { var model = new TestModel(); Reflect.OnProperties.SetProperty<TestModel>(model, x => x.Id, 5); Reflect.OnProperties.SetProperty<TestModel>(model, x => x.MyString, "Bob"); Assert.Equal(5, model.Id); Assert.Equal("Bob", model.MyString); }
public void TypeSafeSetProperty_PublicTypeSafeProperty_SetsProperty() { var model = new TestModel(); Reflect.OnProperties.TypeSafeSetProperty<TestModel, int>(model, x => x.Id, 5); Reflect.OnProperties.TypeSafeSetProperty<TestModel, string>(model, x => x.MyString, "Bob"); Assert.Equal(5, model.Id); Assert.Equal("Bob", model.MyString); }
public void SetProperty_ProtectedProperty_SetsProperty() { var model = new TestModel(); Reflect.OnProperties.SetProperty<TestModel>(model, x => x.President, "Clinton"); Assert.Equal("Clinton", model.President); }
public void SetProperty_PrivateProperty_SetsProperty() { var model = new TestModel(); Reflect.OnProperties.SetProperty<TestModel>(model, x => x.Spy, "Bond"); Assert.Equal("Bond", model.Spy); }
public void NullSafeGetValue_FromInstanceWithNull_ReturnsSetDefaultValue() { //Expression<Func<TestModel, object>> exp = x => x.MyString; var obj = new TestModel { Id = 1, MyString = null }; var result = Reflect.OnProperties.NullSafeGetValue<TestModel, object>(obj, x => x.MyString, "Default"); Assert.Equal("Default", result); }
public void NullSafeGetValue_FromInstanceNestedProperty_ReturnsValue() { Expression<Func<TestModel, object>> exp = x => x.Nested.Deep; var obj = new TestModel { Id = 1, MyString = null, CreatedAt = DateTime.MaxValue, Nested = new NestedModel { Deep = "Going Deep" } }; var result = Reflect.OnProperties.NullSafeGetValue<TestModel, object>(obj, exp, string.Empty); Assert.Equal("Going Deep", result); }
public void NullSafeGetValue_FromInstanceBaseDate_ReturnsDate() { Expression<Func<TestModel, object>> exp = x => x.CreatedAt; var obj = new TestModel { Id = 1, MyString = null, CreatedAt = DateTime.MaxValue }; var date = Reflect.OnProperties.NullSafeGetValue<TestModel, object>(obj, exp, DateTime.MinValue); Assert.Equal(DateTime.MaxValue, date); }