Skip to content

Instantly share code, notes, and snippets.

@diegocaxito
Created July 5, 2012 18:55
Show Gist options
  • Save diegocaxito/3055695 to your computer and use it in GitHub Desktop.
Save diegocaxito/3055695 to your computer and use it in GitHub Desktop.
DTO Assert
[TestClass]
public class Test{
public void TestAssert(){
//....
AssertUtil.AssertProperties(myExpectedResult, myActualResult);
}
}
public static class AssertUtil
{
public static void AssertProperties<T>(T expected, T actual)
{
foreach (var property in typeof(T).GetProperties())
Assert.AreEqual(property.GetValue(expected, null).FromNullToString(), property.GetValue(actual, null).FromNullToString(), property.Name);
}
}
internal static class ConvertNull
{
public static string FromNullToString(this object value)
{
return value != null ? value.ToString() : string.Empty;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment