Forcing MVC Model State to invalid for Unit Tests

added by Robert Greyling
1/8/2015 8:20:06 PM

1 Kicks, 328 Views

Unit testing ASP.Net MVC applications is easier than every today. But how do you force ModelState.IsValid to be false in a unit tests? The simple thought would be to simply create an invalid object and pass that into your action method, but this will not work. Why? Because the validation is down by the MVC pipeline prior to reaching your actual method and you do not have direct access to this.


0 comments