This may be known to some of you, but I’d never had to do this before, so I thought I’d share.
I had some MVC 4 code that explicitly calls the System DependencyResolver (the application uses Unity for dependency injection) to retrieve a service:
Mocking (in this case) the ISomeOtherService is obviously a trivial matter and, fortunately, it turns out it is quite easy get the DependencyResolver to return the mock as well. Using NUnit and NSubstitute, it can achieved with the minimum hassle as below
Feel free to ask if anything is unclear.