title: How do I mock the HttpContext in ASP.NET MVC using Moq?
body: <pre><code>[TestMethod]
  public void Home_Message_Display_Unknown_User_when_coockie_does_not_exist()
  {
      var context = new Mock&lt;HttpContextBase&gt;();
      var request = new Mock&lt;HttpRequestBase&gt;();
      context
          .Setup(c =&gt; c.Request)
          .Returns(request.Object);
      HomeController controller = new HomeController();
  
      controller.HttpContext = context; //Here I am getting an error (read only).
      ...
   }
  </code></pre>
  
  <p>my base controller has an overrride of the Initialize that get's this requestContext.  I am trying to pass this along but I am not doing something right. </p>
  
  <pre><code>protected override void Initialize(System.Web.Routing.RequestContext requestContext)
  {
      base.Initialize(requestContext);
  }
  </code></pre>
  
  <p>Where can I get more information on mocking my RequestContext and HttpContext using Moq?  I am trying to mock cookies and the general context.</p>