如何使用 MvcContrib.TestHelper 测试 asp.net mvc post 操作
我正在尝试使用优秀的 MvcContrib.TestHelper 来测试我的路由配置,但我遇到了问题。
请假设我的路由配置已正确设置并在 TestFixture 中初始化。
我有一个名为 Create 的控制器(TransactionsController)操作,它采用 TransactionRecord 类型的输入参数:
[Trace, AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(TransactionRecord tx)
{
...
}
目前我的测试如下:
[Test]
public void TestRoute_POST_Transactions_Create()
{
"~/Transactions/".WithMethod(HttpVerbs.Post).ShouldMapTo<Web.Controllers.TransactionsController>(x => x.Create());
}
我的问题是 Create() 方法采用 TransactionRecord 类型的参数,我不知道如何合并它进入我的测试。
我还没有找到任何这种性质的例子。
I am trying to test my routing configuration using the excellent MvcContrib.TestHelper and I've run into a problem.
Please assume that my Routing Configuration is set up correctly and initialised in the TestFixture.
I have a controller (TransactionsController) action called Create that takes an input parameter of type TransactionRecord:
[Trace, AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(TransactionRecord tx)
{
...
}
Currently my test is as follows:
[Test]
public void TestRoute_POST_Transactions_Create()
{
"~/Transactions/".WithMethod(HttpVerbs.Post).ShouldMapTo<Web.Controllers.TransactionsController>(x => x.Create());
}
My problem is that the Create() method takes a parameter of type TransactionRecord, I do not know how to incorporate this into my test.
I've not been able to find any examples of this nature.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 TransactionRecord 是根据发布数据创建的,只需将 null 传递给您的测试:
由 mvccontrib 讨论组提供的回答:
http://groups.google.com/group/mvccontrib-discuss/ browser_thread/thread/2839edd5ad3c5258
As the TransactionRecord is created from post data, just pass null to your test:
Answer courtesy of mvccontrib discussion group:
http://groups.google.com/group/mvccontrib-discuss/browse_thread/thread/2839edd5ad3c5258