4 ms·
Similar to Moq?
by hoofhearted 5y ago
Similar to Moq?
- gwbas1c 5y agoIn order to use Moq (or NMock, or similar,) you need to use techniques like dependency injection. With Moq, you just can't call "new Foo()" in your code, because that's not mockable. You need to pass in a delegate that returns an IFoo. Or, you can't use statics, because those aren't mockable. What I'm trying to do is take the compiled IL, automatically convert Foo to an interface, and replace "new Foo()" with calls to a delegate. Then in your test, you set the delegate and provide an IFoo. You could use Moq to make your IFoo. Likewise, with Moq, if you're writing code against a 3rd party API based around static methods, you need to wrap them in an interface, make a shim object, write your code to the shim object... I'm trying to take IL that's directly calling static methods, and redirect them to an alternate class. The point is that you don't need to write interfaces for every type you want to mock, nor do you need to use dependency injection in every class you want to unit test. All that is done automatically, after compilation.