是否可以在 ASP.NET MVC 中对某些 AddModelError 结果进行单元测试?
我有一个控制器方法,它返回一个 RedirectToActionResult
(成功!)或一个 ViewResult
(失败并显示错误消息)。
如果业务逻辑失败,我会将错误消息添加到AddModelError
属性中。
有什么方法可以在我的 MS 单元测试中对此进行测试吗? 我还有起订量,如果这也有帮助的话。 (不过,我不认为这种情况需要起订量)..我没有使用 Request
对象中的任何内容。
I've got a controller method which returns a RedirectToActionResult
(success!) or a ViewResult
(failed with error messages).
If the business logic fails, i add the error messages to the AddModelError
property.
Is there any way i can test this in my MS Unit tests? I also have Moq, if that helps too. (i don't believe Moq is required for this scenario though) .. I'm not using anything from the Request
object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,想通了。
Yep, figured it out.
您还可以直接测试控制器(无需测试视图),如下所示:
You can (also) test the Controller directly (without testing the View) as follows: