加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 模拟FormsAuthentication.Authenticate()方法

发布时间:2020-12-16 07:30:42 所属栏目:asp.Net 来源:网络整理
导读:有什么方法可以用测试凭证模拟FormsAuthentication.Authenticate(“用户名”,“密码”)方法吗?我的测试目标是确保如果身份验证失败,它会重定向到正确的位置.我正在使用Rhino Mocks作为模拟框架. 非常感谢您的帮助, 解决方法 由于您使用的是mvc,如果您创建一
有什么方法可以用测试凭证模拟FormsAuthentication.Authenticate(“用户名”,“密码”)方法吗?我的测试目标是确保如果身份验证失败,它会重定向到正确的位置.我正在使用Rhino Mocks作为模拟框架.

非常感谢您的帮助,

解决方法

由于您使用的是mvc,如果您创建一个新项目并查看Account控制器的代码,您将找到以下说明:

The FormsAuthentication type is sealed
and contains static members,so it is
difficult to unit test code that calls
its members. The interface and helper
class below demonstrate how to create
an abstract wrapper around such a type
in order to make the AccountController
code unit testable.

在此之下,有以下声明:

public interface IFormsAuthentication
public class FormsAuthenticationService : IFormsAuthentication
public interface IMembershipService
public class AccountMembershipService : IMembershipService

您可以在引用的代码中查找实现.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读