I'm trying to Mock the IUnityContainer using Moq 3.0
I'm getting a BadImageFormatException, but not when debugging. From the looks of it I'm not the only one that's ran into this problem.
here
And its a registered issue for Moq
here
I'm just curious if anyone has found a solution... closest I've found is a nice solution that uses RhinoMock by Roy Osherove
here
but I really like Moq! So I don't really want to have to switch to Rhino Mock but I will if I must
Thanks in advance!
You don't.
The only reason to mock the container is if you're passing it around. That's an anti-pattern.
Instead you want to compose the entire object graph at the application's entry point, or Composition Root.
If you need to create instances on the fly, use Automatic Factories.
For your tests, you can either construct the object under test and pass mock objects to the constructor or create a new container in the test and register mock objects with it.
Do you need a full-blown mock object? Could you get by with simply implementing a Fake? I.e., implementing a test instantiation of the IUnityContainer interface and overriding the method that you need to interact with?
I've fallen into the trap more than once in thinking that since I have a mock object library, I should use it for isolating every dependency in my system. More often than not, doing something simpler gets me the results I want with much lower frustration levels.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With