【发布时间】:2011-06-15 14:52:13
【问题描述】:
我在控制器中有后期操作。代码如下所示
[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));
}
当我调试这个单个测试用例时,测试用例通过了,因为条件 if (TryUpdateModel(data)) 返回 true 并进入 if 条件。 但是当我从整个解决方案中调试测试用例时,这个测试用例失败了,因为它进入了“if (TryUpdateModel(data))”的其他条件。
我不知道为什么..
请帮忙...
谢谢
【问题讨论】:
标签: asp.net-mvc-3 unit-testing