public void Assert <T>(T expectedObject, T realObject, params Expression <Func <T, object> >[] propertiesNotToCompareExpressions) { PropertyInfo[] properties = realObject.GetType().GetProperties(); List <string> propertiesNotToCompare = GetMemberNames(propertiesNotToCompareExpressions); foreach (PropertyInfo currentRealProperty in properties) { if (!propertiesNotToCompare.Contains(currentRealProperty.Name)) { PropertyInfo currentExpectedProperty = expectedObject.GetType().GetProperty(currentRealProperty.Name); string exceptionMessage = string.Format("The property {0} of class {1} was not as expected.", currentRealProperty.Name, currentRealProperty.DeclaringType.Name); if (currentRealProperty.PropertyType != typeof(DateTime) && currentRealProperty.PropertyType != typeof(DateTime?)) { MSU.Assert.AreEqual(currentExpectedProperty.GetValue(expectedObject, null), currentRealProperty.GetValue(realObject, null), exceptionMessage); } else { DateTimeAssert.AreEqual( currentExpectedProperty.GetValue(expectedObject, null) as DateTime?, currentRealProperty.GetValue(realObject, null) as DateTime?, DateTimeDeltaType.Minutes, 5); } } } }
public void Assert(T expectedObject, T realObject, params string[] propertiesNotToCompare) { var properties = realObject.GetType().GetProperties(); foreach (var currentRealProperty in properties) { if (!propertiesNotToCompare.Contains(currentRealProperty.Name)) { var currentExpectedProperty = expectedObject.GetType().GetProperty(currentRealProperty.Name); var exceptionMessage = string.Format("The property {0} of class {1} was not as expected.", currentRealProperty.Name, currentRealProperty.DeclaringType.Name); if (currentRealProperty.PropertyType != typeof(DateTime) && currentRealProperty.PropertyType != typeof(DateTime?)) { MSU.Assert.AreEqual(currentExpectedProperty.GetValue(expectedObject, null), currentRealProperty.GetValue(realObject, null), exceptionMessage); } else { DateTimeAssert.AreEqual( currentExpectedProperty.GetValue(expectedObject, null) as DateTime?, currentRealProperty.GetValue(realObject, null) as DateTime?, DateTimeDeltaType.Minutes, 5); } } } }