I have a class like so:
public abstract class ClassA<T>
{
protected ClassA(IInterface interface)
{
if (interface== null)
{
throw new ArgumentNullException ("interface");
}
}
}
I want to write a test which verifies that if I pass null in the exception is thrown:
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public TestMethod()
{
ClassA classa = MockRepository.GenerateMock<ClassA<String>> (null);
}
but the test keeps failing with an exception rather than the exception being expected. I also tried wrapping the call in a try catch block, but same issue. I tried GenerateStub and PartialMock.
What am I missing?
I’ve recently run into this issue myself, unfortunately I haven’t been able to find any way to tell Rhino not to wrap the exception itself. Thus far, the best I’ve been able to come up with would be as follows: