How do I use Assert.Throws to assert the type of the exception and the actual message wording?
Something like this:
Assert.Throws
I recently ran into the same thing, and suggest this function for MSTest:
public bool AssertThrows(Action action) where T : Exception
{
try {action();
}
catch(Exception exception)
{
if (exception.GetType() == typeof(T))
return true;
}
return false;
}
Usage:
Assert.IsTrue(AssertThrows(delegate{ newMyMethod(MyParameter); }));
There is more in Assert that a particular exception has occured (Assert.Throws in MSTest).