Mocking the Controller Context using Rhino Mock

When using ASP.NET MVC 5, its easy to write unit tests around the framework due to the various abstractions provided.

Stephen Walther provides a good overview of the different objects. Whenever you need to interact with the request, response, session or browser, the following objects can be mocked using your mocking framework of choice:

  • HttpRequestBase
  • HttpResponseBase
  • HttpSessionBase
  • HttpBrowserCapabilitiesBase

Here of some examples using of mocking the various classes using Rhino Mock:

Mocking the Controller Context (MVC)


Mocking the Controller Context (Web API)

Mocking the Identity and Principal


Mocking the Session State

Popular posts from this blog

A Simple 3 Layer Architecture