0
我有一個簡單的動作:ASP.NET MVC 4測試控制器
[HttpPost]
public virtual ActionResult AddVote(string id, sbyte value)
{
//...
if (somethingIsWrong)
ModelState.AddModelError("", "SomethingIsWrong");
//...
}
現在我想測試的ModelState是否有效/無效:
[Fact]
public void AddVotePostTest()
{
var controller = new VoteController();
controller.AddVote("someId", 1);
Assert.True(controller.ModelState.IsValid); //AccessViolationException here
}
但我點在哪裏得到AccessViolationException我打電話給controller.ModelState.IsValid。
這可能有所幫助:http://stackoverflow.com/questions/286124/how-can-i-test-modelstate – Faust
選中此項:[Test Driven Development with ASP.NET MVC](http://www.singingeels.com/Articles/Test_Driven_Development_with_ASPNET_MVC.aspx) – Yasser