基本上我想设置20个左右的Request.Form值,发送POST到我的控制器,然后检查结果。编写将Request.Form数据发送到我的控制器的单元测试最简单的方法是什么?
我发现了几篇文章,如this one,它们描述了如何使用NUnit,MVCContrib和Rhino Mocks的组合来完成此操作。但我不知道这是否真的有必要。
似乎Visual Studio 2010和ASP.NET MVC 2应该能够在本地执行此操作,并在“测试结果”窗口中显示结果。事实上,当我创建的向导创建新的单元测试,谈到了这个...
[TestMethod()]
[HostType("ASP.NET")]
[AspNetDevelopmentServerHost("G:\\Webs\\MyWebsite.com\\MyWebsite", "/")]
[UrlToTest("http://localhost:43383/")]
public void PaypalIPNTest()
{
BuyController target = new BuyController(); // TODO: Initialize to an appropriate value
ActionResult expected = new EmptyResult(); // TODO: Initialize to an appropriate value
ActionResult actual;
actual = target.PaypalIPN();
Assert.AreEqual(expected, actual);
Assert.Inconclusive("Verify the correctness of this test method.");
}
是否有可能根据上面的代码养活target.PaypalIPN()
我的Request.Form变量?还是我需要依靠第三方库来完成这个任务?
谢谢你。我忘了模型可以被MVC引擎自动解释为表单集合。这样做肯定会清理PaypalIPN功能。 –