Beim Ausführen meiner Komponententestmethode erhalte ich FormsAuthentication.SignOut() Fehler. Ich habe die Httpcontext ähnlicheThrowing-Fehler in Komponententest FormsAuthentication.SignOut()
verspottetenvar httpRequest = new HttpRequest("", "http://localhost/", "");
var stringWriter = new StringWriter();
var httpResponse = new HttpResponse(stringWriter);
var httpContext = new HttpContext(httpRequest, httpResponse);
var sessionContainer = new HttpSessionStateContainer(
"id",
new SessionStateItemCollection(),
new HttpStaticObjectsCollection(),
10,
true,
HttpCookieMode.AutoDetect,
SessionStateMode.InProc,
false);
SessionStateUtility.AddHttpSessionStateToContext(httpContext, sessionContainer);
var controller = new AccountController();
var requestContext = new RequestContext(new HttpContextWrapper(httpContext), new RouteData());
controller.ControllerContext = new ControllerContext(requestContext, controller);
var actual = controller.Login(new CutomerModel() { Login = "admin", Password = "Password1" });
return httpContext;
im Login-Methode
public ActionResult Login(CutomerModel obj)
{
FormsAuthentication.SignOut();
}
FormsAuthentication.SignOut();
wirft
‚Objektverweis auf eine Instanz eines Objekts nicht gesetzt. "