title: MVC3 unit testing response code
body: <p>I have a controller within MVC3 which needs to return a response code 500 if something goes wrong. I am doing this by returning a view object and setting http response code to equal 500 (I have checked this in firebug and all is working great). </p>
  
  <pre><code>public ActionResult http500()
  {
      ControllerContext.HttpContext.Response.StatusCode = 500;
      ControllerContext.HttpContext.Response.StatusDescription = "An error occurred whilst processing your request.";
  
      return View();
  }
  </code></pre>
  
  <p>The problem I have now is I need to be able to write a unit test which checks the response code. I have tried accessing the response code in several different ways both through the ViewResult object and the Controller context.</p>
  
  <p>Neither way gives me the response code I have set in the controller.</p>
  
  <pre><code>[TestMethod()]
  public void http500Test()
  {
     var controller = new ErrorController();
     controller.ControllerContext = new ControllerContext(FakeHttpObject(), new RouteData(), controller);
  
  
     ViewResult actual = controller.http500() as ViewResult;
     Assert.AreEqual(controller.ControllerContext.HttpContext.Response.StatusCode, 500);
  
  }
  </code></pre>
  
  <p>How would I go about getting the response code 500 from the controller or is this more of an integration testing thing.</p>