NUnit - 使用成员资格提供程序进行身份验证时出现NullReferenceException

时间:2017-01-10 15:53:53

标签: asp.net .net asp.net-mvc nunit membership-provider

我正在尝试在单元测试中测试身份验证:

 // code in Unit Test method
 var loginModel = new LoginModel();
 loginModel.UserName = "userhere";
 loginModel.Password = "passhere";
 loginModel.RememberMe = false;
 var accountController = CreateAccountController();
 accountController.Login(loginModel, ""); 

protected static AccountController CreateAccountController()
{
        var routes = new RouteCollection();
        var controller = new AccountController();
        controller.ControllerContext = new ControllerContext(HttpContextBaseMock.Object, new RouteData(), controller);
        controller.Url = new UrlHelper(new RequestContext(HttpContextBaseMock.Object, new RouteData()), routes);
        return controller;
}

但是当调用WebSecurity.Login方法时,我得到一个NullReferenceException。调用SetAuthCookie时,似乎错误是成员资格提供者失败。

知道如何解决这个问题吗?

我应该尝试模仿这种方法吗?

0 个答案:

没有答案