.net - How can I test for null arguments in the constructor of abstract class using rhino mocks? -
i have class so:
public abstract class classa<t> { protected classa(iinterface interface) { if (interface== null) { throw new argumentnullexception ("interface"); } } }
i want write test verifies if pass null in exception thrown:
[test] [expectedexception (typeof (argumentnullexception))] public testmethod() { classa classa = mockrepository.generatemock<classa<string>> (null); }
but test keeps failing exception rather exception being expected. tried wrapping call in try catch block, same issue. tried generatestub , partialmock.
what missing?
i've run issue myself, unfortunately haven't been able find way tell rhino not wrap exception itself. far, best i've been able come follows:
[test] [expectedexception(typeof(argumentnullexception))] public void testmethod() { try { classa classa = _mocks.createmock<classa>(null); } catch (exception e) { if (e.innerexception != null) { throw e.innerexception; } } { _mocks.replayall(); } }
Comments
Post a Comment