public void ShouldReturnNullWhenGetPropertyValueByRecursionFoundNoProperty() { var dummyObject = new EmptyDummy(); var propertyReflection = new PropertyReflection(); var result = propertyReflection.GetPropertyValue(dummyObject, "Doughnut", true); Assert.IsNull(result); }
public void ShouldGetPropertyValueSuccessfullyByRecursionOnParentObject() { var dummyObject = new DummyObject { Id = 5 }; var propertyReflection = new PropertyReflection(); var result = propertyReflection.GetPropertyValue(dummyObject, "Id", true); Assert.IsNotNull(result); Assert.AreEqual(5, Convert.ToInt32(result)); }
public void ShouldGetPropertyValueSuccessfullyByRecursion() { var dummyObject = new DummyObjectComplex { Dummy = new DummyObject { Name = "Stars" } }; var propertyReflection = new PropertyReflection(); var result = propertyReflection.GetPropertyValue(dummyObject, "Name", true); Assert.IsNotNull(result); Assert.AreEqual("Stars", result.ToString()); }
public void ShouldGetPropertyValueSuccessfully() { var dummyObject = new DummyObject { Name = "Stars" }; var propertyReflection = new PropertyReflection(); var result = propertyReflection.GetPropertyValue(dummyObject, "Name"); Assert.IsNotNull(result); Assert.AreEqual(result, "Stars"); }
public void GetPropertyValue() { //Arrange var person = CreatSut(); //Act var result = PropertyReflection.GetPropertyValue <Person>(person, x => x.Address.Country.CountryName); //Assert Assert.Equal("USA", result); }
public void ShouldThrowExceptionWhenPropertyNotExistingOnGettingValue() { var dummyObject = new DummyObject(); var propertyReflection = new PropertyReflection(); var result = Assert.Throws<Exception>(() => propertyReflection.GetPropertyValue(dummyObject, "Doughnut")); Assert.IsNotNull(result); Assert.IsInstanceOf(typeof(Exception), result); Assert.AreEqual("Property Doughnut does not exist on DummyObject object", result.Message); }
private DataTable ConvertToDataTable <T>(IEnumerable <T> data, params Expression <Func <T, object> >[] columnsFunc) { DataTable table = new DataTable(); foreach (var column in columnsFunc) { string columnName = PropertyReflection.GetPropertyDisplayName <T>(column); table.Columns.Add(columnName); } foreach (T obj in data) { DataRow row = table.NewRow(); for (int i = 0; i < table.Columns.Count; i++) { row[table.Columns[i].ColumnName] = PropertyReflection.GetPropertyValue <T>(obj, columnsFunc[i]); } table.Rows.Add(row); } return(table); }