I’m writing unit tests and I want to simulate the scenario where a DB2Exception gets thrown.
The problem is that it has no public constructors, so I can’t create it, and most unit-testing frameworks (I use Rhino Mocks with nunit) also can’t create stubs for them.
Am I stuck with not being able to test this interaction?
(Details: this is the DB2Exception defined in IBM.Data.DB2.dll – version 8.1.2.1)
I was hoping
DB2Exceptionhad some derived classes, but alas – no, it’s sealed. Here’s the class description.Since DB2Exceptions are obviously thrown by someone, there’s probably an
internalconstructor. You’ll have to resort to reflection to use it. There was once a .NET Reflector that analyzed MSIL and produced C# code, but now it costs money. You can find some alternatives here.