I have the following controller:
public sealed class SomeController : Controller
{
public ActionResult PageNotFound()
{
Response.StatusCode = 404;
return View("404");
}
}
I created the MSpec specification:
[Subject(typeof (SomeController))]
public class when_invalid_page_is_requested : SomeControllerSpec
{
Because of = () => result = Controller.PageNotFound();
It should_set_status_code_to_404 =
() => Controller.Response.StatusCode.ShouldEqual(404);
}
public abstract class SomeControllerSpec
{
protected static HomeController Controller;
Establish context = () => { Controller = new SomeController(); };
}
But due to the way I create the controller instance, the HttpContext is null. What would be the best way to check the status code set by the action PageNotFound?
EDIT: answer below
source
share