如何使用System.Web.Security.Membership里面的单元测试方法?

Joh*_*ell 9 c# moq mocking

我想测试一个方法来检查它是否正确保存了一个事务.在其内部调用Membership.GetUser()来验证每次导致测试失败的用户.有没有办法模拟这个,以便Membership.GetUser()总是返回一个有效的名称?

我正在使用Moq,C#和ASP.Net 4.5 MVC

Ser*_*sev 5

总之,你不能.这就是为什么每次调用这种"服务"都应该隐藏在抽象背后.

您可以在默认MVC模板中看到该示例.

  • 发现这看起来很有希望:http://blog.spontaneouspublicity.com/unit-testing-the-mvc4-account-controller.那是你在谈论的那种抽象吗? (2认同)