title: Mocking HttpRequest in ASP.NET 4.0
body: <p>I've seen a lot of similar threads but none that actually address my particular situation.</p>
  
  <p>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 <code>ServerVariables</code> collection to call variables like <code>REMOTE_ADDR</code>. Since my unit tests do not actually initiate <code>HttpRequests</code> when executing my code, things like <code>ServerVariables</code> are <code>Null</code> and therefore error when I try to call <code>HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")</code></p>
  
  <p>All the solutions I've found to address this issue refer to MVC and so they assume that <code>HttpRequest</code> derives from <code>HttpRequestBase</code>, which it does in MVC but not in ASP.NET Forms.</p>
  
  <p>I tried using <code>Moq</code> but you can't mock a sealed class, and <code>HttpRequest</code> is unfortunately sealed with no interface.</p>