MVC3 Moq 帐户控制器 c# nUnit
我正在尝试学习最小起订量,但事实证明这有点困难。
如果我想在新的 MVC3 项目中使用 nUnit 和 Moq 为帐户控制器实现一些基本测试,我该怎么做?
我习惯了实体框架。但没有为其构建接口。
编辑: 我理解这一切的理论以及这样做的必要性,但是实现它让我感到困惑我
一直在使用实体代码生成器(dbContext)来生成可用于接口的代码
I am trying to learn Moq but it is proving somewhat difficult.
If I want to implement some basic tests using nUnit and Moq for the account controller in a new MVC3 project, how would I go about it?
Im used to the entity framework. but not building interfaces for it.
edit:
I understand the theory of it all and the need to do it, but implementing it is confusing me
I have been using Entity Code generator (dbContext) to generate code I can use for interfaces
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,这是一个很好的测试:当您注册新用户时,您希望确保他会自动登录网站,这样他就不需要再次输入用户名和密码。
测试将是这样的:
这里的关键是Verify 方法。它的工作原理就像断言一样。在本例中,您要验证方法 SignIn 是否仅被调用一次。这是如何使用模拟来检查帐户控制器是否按预期工作的示例。
Ok, here is a good test: When you register a new user, you want to make sure that he will be automatically signed in the site, so he doest not need to type his username and password again.
The test would be something like this:
The key here is the Verify method. It works just like an Assert. In this case you are verifing that the method SignIn was called exactly once. This is an example of how to use mocks to check if the Account Controller is working as expected.