I have some tests where i am checking for parameter name in exception. How do i write this in MS TEST?
ArgumentNullExc
public static class ExceptionAssert
{
public static T Throws(Action action) where T : Exception
{
try
{
action();
}
catch (T ex)
{
return ex;
}
Assert.Fail("Expected exception of type {0}.", typeof(T));
return null;
}
}
You can use the extension method above as a test helper. Here is an example of how to use it:
// test method
var exception = ExceptionAssert.Throws(
() => organizations.GetOrganization());
Assert.AreEqual("lawbaseFixedContactRepository", exception.ParamName);