Mocking DependencyResolver

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: https://gist.github.com/williamhallatt/751e26ee1ed64b51ea1648eff776c56a Mocking (in this case) the ISomeOtherService is obviously a trivial matter … Continue reading Mocking DependencyResolver

Mocking multipart/form-data HttpRequestMessage for testing ASP.NET ApiController

I recently had a problem where I needed to unit test an ApiController action that read data off of the controller’s request object, in other words, something that looks like this: https://gist.github.com/williamhallatt/c66ace1c849d9b52696b5f121481f1ad The real-world action receives a multipart/form-data request (a form), which contains an uploaded file as one of its fields. Reading the form fields and … Continue reading Mocking multipart/form-data HttpRequestMessage for testing ASP.NET ApiController