I've seen a lot of similar threads but none that actually address my particular situation.
I'm writing unit tests in ASP.NET 4.0 web application (ASP.NET Forms, not MVC). There are several spots in the code where I call the ServerVariables
collection to call variables like REMOTE_ADDR
. Since my unit tests do not actually initiate HttpRequests
when executing my code, things like ServerVariables
are Null
and therefore error when I try to call HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
All the solutions I've found to address this issue refer to MVC and so they assume that HttpRequest
derives from HttpRequestBase
, which it does in MVC but not in ASP.NET Forms.
I tried using Moq
but you can't mock a sealed class, and HttpRequest
is unfortunately sealed with no interface.