I am writing some integration tests for an MVC web application, which involves firing http post and get requests at an instance of the application that I spin up with IIS Express.
The problem is that I want to assert that validation has passed (for example on account creation), and obviously this is impossible to interpret from just validation messages mixed in with markup that is returned (well not impossible, but out of the question).
What I am currently doing is checking the ModelState in my controller base class in the OnActionExecuted event and setting the status code to a 202 (Accepted but still requires processing):
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
if (!ModelState.IsValid)
{
Response.StatusCode = 202;
}
base.OnActionExecuted(filterContext);
}
I know 202 doesn't really reflect what has happened, but there isn't a status code that fits the situation, and it won't cause an error on the browser when the application is in normal use.
What are peoples opinions of this design? And will it have any adverse affects?