I am trying to write a unit test for our log out method. Among other things it FormsAuthentication.SignOut(). However, it throws a System.NullReferenceException.
I’ve created a mock; HttpContext (using Moq), but it is obviously missing something.
My mock context contains:
- A mocked
HttpRequestBaseonRequest - A mocked
HttpResponseBaseonResponse - With a
HttpCookieCollectiononRequest.Cookiesand another onResponse.Cookies - A mocked
IPrincipalonUser
I am aware I could go the wrapper route and inject an empty FormsAuth wrapper object in it’s place, but I would really like to avoid the 3 additional files just to fix one line of code. That and I am still curious for an answer
So my question is “What is needed in the HttpContext to allow FormsAuthentication.SignOut() to execute.“
Here’s the code for signout.
Looks like you need a CookielessHelperClass instance. Too bad it’s internal and sealed – there’s no way to mock it unless you’re using TypeMock. +1 for wrapper suggestions 🙂