Expected Exception in Unit test
//Exception in calling target (test itself)
[TestMethod, Isolated]
[ExpectedException(typeof(EmailNotSentException))]
public void ProcessWhenGenericExceptionIsThrownConvertItToEmailNotSentException()
{
Isolate.WhenCalled(() => SPUtility.SendEmail(null, true, false, address, subject, body)).WillThrow(new Exception());
target.Process(data); //here is expected exception
}
//If we have try catch block with throw in code, we need to have try catch in unit test to catch it.
//If we expect exception without throw, we just use .WillThrow(new SPException()) in fake method.