我对控制器发布了操作。代码如下TryUpdateModel从单元测试用例中导致错误(Asp.net mvc)
[HttpPost]
public ActionResult Create(Int64 id, FormCollection collection)
{
var data = Helper.CreateEmptyApplicationsModel();
if (TryUpdateModel(data))
{
// TODO: Save data
return RedirectToAction("Edit", "Applications", new { area = "Applications", id = id });
}
else
{
// TODO: update of the model has failed, look at the error and pass back to the view
if (!ModelState.IsValid)
{
if (id != 0) Helper.ShowLeftColumn(data, id);
return View("Create", data);
}
}
return RedirectToAction("Details", "Info", new { area = "Deals", InfoId= id });
}
我写测试用例这个如下
[TestMethod]
public void CreateTest_for_post_data()
{
var collection = GetApplicantDataOnly();
_controller.ValueProvider = collection.ToValueProvider();
var actual = _controller.Create(0, collection);
Assert.IsInstanceOfType(actual, typeof(RedirectToRouteResult));
}
给我调试这个单一测试用例,测试情况下通过,因为条件 如果(TryUpdateModel(数据))返回true,如果条件成立,则返回true。 但是,当我从整个解决方案调试测试用例时,此测试用例失败,因为它遇到“if(TryUpdateModel(data))”。
我不知道为什么..
请帮助...
感谢