NCrunch seems to behave differently to the Resharper and MSTest runners when it encounters test methods annotated with ExpectedException annotations.
When the normal ExpectedException annotation is encountered, NCrunch works fine. When an annotation derived from ExpectedExceptionBaseAttribute is encountered however, NCrunch ignores the exception expectation whereas the Resharper and MSTest runners work fine.
A minimal reproduction is shown below.
Code:
[TestClass]
public sealed class ExpectedExceptionTests
{
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void ExpectedExceptionAttributeTest()
{
throw new InvalidOperationException("This is fine");
}
[TestMethod]
[DerivedExpectedExceptionAttribute(typeof(InvalidOperationException))]
public void ExpectedExceptionDerivedAttributeTest()
{
throw new InvalidOperationException("This is fine in Resharper and MSTest, but fails in NCrunch because the derived expected exception annotation is ignored");
}
private sealed class DerivedExpectedExceptionAttribute : ExpectedExceptionBaseAttribute
{
private readonly Type _expectedExceptionType;
public DerivedExpectedExceptionAttribute(Type expectedExceptionType)
{
_expectedExceptionType = expectedExceptionType;
}
protected override void Verify(Exception exception)
{
Assert.IsInstanceOfType(exception, _expectedExceptionType);
}
}
}
Could NCrunch be updated to support annotations that derive from ExpectedExceptionBaseAnnotation the way the other runners do?