[TestMethod]
public void UnitTestMethod1()
{
Test1Controller controller = new Test1Controller();
//This call throws NullReferenceException "Object reference not set to an instance of an object."
WebSecurity.Login("User1", "password1");
controller.TestMethod();
}
在上面的代码中如何使WebSecurity.Login调用工作?用户信息如何从UnitTest传递到控制器?
我没有研究,但它并没有帮助much
感谢。
http://stackoverflow.com/questions/12408180/how-to-unit-test-methods-that-use- system-web-security-membership-inside –
谢谢,尼尔。 WebSecurity.Login使用FormsAuthentication.SetAuthCookie,它实际上会引发异常。 – yW0K5o