How do I mock the HttpContext in ASP.NET MVC using Moq?

HttpContext is read-only, but it is actually derived from the ControllerContext, which you can set.

 controller.ControllerContext = new ControllerContext( context.Object, new RouteData(), controller );

Leave a Comment