Here is part of the controller action:
[HttpPost] public ActionResult NewComplaint(Complaint complaint) { if(!ModelState.IsValid) {
When the application starts, the model is automatically checked before the if statement is even called. However, when you try to run a unit test, this code does not automatically check.
If I used FormCollection and instead called TryUpdateModel, the check would be done, but I don't want to use it.
I found that calling TryValidateModel (model) before the if statement worked well around the problem; only one extra line of code is required. I would rather get rid of it.
Any ideas why automatic verification does not occur during unit testing, but arises when the application is running?
EDIT: Remember, I am using ASP.NET MVC3 RC1, and I am mocking the controller HTTPContext object, if that matters
source share