I am trying to write a unit test for our log out method. Amoung other things it FormsAuthentication.SignOut()
. However, it throws a System.NullReferenceException
.
I've created myself a mock HttpContext
(using Moq) but it is obviously missing something.
My mock context contains:
- A mocked
HttpRequestBase
onRequest
- A mocked
HttpResponseBase
onResponse
- With a
HttpCookieCollection
onRequest.Cookies
and another onResponse.Cookies
- A mocked
IPrincipal
onUser
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.
"