Posted by Sébastien Lachance with Comments (0)
I just got a hard time figuring how I could be mocking the HttpContext so that I would be able to mock HttpRequest. But once you understand the principle, it is fairly easy.
First thing we need to know is that the HttpContext is held inside a ControllerContext object. Once we have instantiated one, we can then put it inside our controller.
controller.ControllerContext = new ControllerContext(mockedhttpContext, new RouteData(), controller);
Related posts