Reputation: 25292
I have a simple action:
[HttpPost]
public virtual ActionResult AddVote(string id, sbyte value)
{
//...
if (somethingIsWrong)
ModelState.AddModelError("", "SomethingIsWrong");
//...
}
Now I want to test whether ModelState is valid/invalid:
[Fact]
public void AddVotePostTest()
{
var controller = new VoteController();
controller.AddVote("someId", 1);
Assert.True(controller.ModelState.IsValid); //AccessViolationException here
}
But I get AccessViolationException at the point where I call controller.ModelState.IsValid.
Upvotes: 0
Views: 174
Reputation: 25292
The error was caused by the fact System.Web.Mvc 3 was referenced in my test project. I have referenced System.Web.Mvc 4 and the problem gone
Upvotes: 1