I would like to provide some custom Assert methods in my MSTest Unit Testing framework. I have my own static class "CustomAssert", and methods like the one below:
public static void DatesAreEqualToDay(DateTime expectedValue, DateTime actualValue)
{
if (!(
expectedValue.Year == actualValue.Year &&
expectedValue.Month == actualValue.Month &&
expectedValue.Day == actualValue.Day))
{
Assert.Fail(string.Format("Expected: <{0:yyyy-MM-dd}> - Actual <{1:yyyy-MM-dd}>", expectedValue, actualValue));
}
}
The test fails when the the dates are not the same. But instead the custom error message, I am just getting the message that the test threw an AssertFailedException. How do you get the custom assertions to be handled like MSTest's Assert methods, and show the intelligent error message?