title: Unit testing with dependency on HttpContext
body: <p>I need to test some static methods that rely on the current context.  Now, I can certainly use the <code>HttpContextWrapper</code> to remove this dependency from my own code.  The problem lies with the 3rd party API I am using in these methods.  THEY are relying on the <code>HttpContext</code> and so I can't do anything about that.  However, what I'm trying to do is set the <code>HttpContext</code> with my <code>HttpContextBase</code>.</p>
  
  <p>So my code looks something like this:</p>
  
  <pre><code>public static bool IsSignedUpUser()
  {
      //This calls IsSignedUpUser with the production context
      return IsSignedUpUser(new HttpContextWrapper(HttpContext.Current));
  }
  
  public static bool IsSignedUpUser(HttpContextBase context)
  {
      HttpCookie objCookie = SomeExternalAPIThatReliesOnHttpContextBeingSet();
  
      return (objCookie != null)
  }
  </code></pre>
  
  <p>What I want to do is something like:</p>
  
  <pre><code>HttpContext.Current = context; //where context is a mocked HttpContextBase
  </code></pre>
  
  <p>This way when the 3rd party API is looking in the <code>HttpContext</code> for querystring, cookie values, etc, it doesn't throw a <code>NullReferenceException</code>.</p>
  
  <p><strong>Why isn't this a dupe?</strong></p>
  
  <p>In the code in the question referenced as a dupe, the author looks to be in complete control with no external dependencies.  I'm using third party libraries that have a dependency on <code>HttpContext</code>, I can't change their method signatures to accept <code>HttpContextBase</code> so I need a way to assign my <code>HttpContextBase</code> to <code>HttpContext</code>.</p>
  
  <p>If this is not possible, and so far I am lead to believe that it isn't, then good answers should suggest how to remove these dependencies.  500 - Internal Server Error has at least one good suggestion.</p>