我對控制器發佈了操作。代碼如下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))」。
我不知道爲什麼..
請幫助...
感謝