title: Need to add custom header to request in unit test
body: <p>I finally was able to get the <code>HttpContext.Current</code> to be not null by finding some code online.  But I still have not be able to add custom headers to the request in my unit test.  Here is my test:</p>
  
  <pre><code>[TestClass]
  public class TagControllerTest
  {
      private static Mock&lt;IGenericService&lt;Tag&gt;&gt; Service { get; set; }
      private TagController controller;
  
      [TestInitialize]
      public void ThingServiceTestSetUp()
      {
          Tag tag = new Tag(1, "people");
          Response&lt;Tag&gt; response = new Response&lt;Tag&gt;();
          response.PayLoad = new List&lt;Tag&gt;() { tag };
  
          Service = new Mock&lt;IGenericService&lt;Tag&gt;&gt;(MockBehavior.Default);
          Service.Setup(s =&gt; s.FindAll("username", "password", "token")).Returns(response);
  
          controller = new TagController(Service.Object);
          HttpContext.Current = FakeHttpContext();
      }
  
      public static HttpContext FakeHttpContext()
      {
          var httpRequest = new HttpRequest("", "http://kindermusik/", "");
          var stringWriter = new StringWriter();
          var httpResponce = new HttpResponse(stringWriter);
          var httpContext = new HttpContext(httpRequest, httpResponce);
  
          var sessionContainer = new HttpSessionStateContainer("id", new SessionStateItemCollection(),
                                                  new HttpStaticObjectsCollection(), 10, true,
                                                  HttpCookieMode.AutoDetect,
                                                  SessionStateMode.InProc, false);
  
          httpContext.Items["AspSession"] = typeof(HttpSessionState).GetConstructor(
                                      BindingFlags.NonPublic | BindingFlags.Instance,
                                      null, CallingConventions.Standard,
                                      new[] { typeof(HttpSessionStateContainer) },
                                      null)
                              .Invoke(new object[] { sessionContainer });
          httpContext.Request.Headers["username"] = "username"; //It throws a PlatformNotSupportedException exception
          httpContext.Request.Headers["password"] = "password"; //.Headers.Add("blah", "blah") throws same error
          httpContext.Request.Headers["token"] = "token"; //And so to .Headers.Set("blah", "blah")
  
          return httpContext;
      }
  
      [TestMethod]
      public void TagControllerGetTest()
      {
          // Arrange
          Response&lt;Tag&gt; result = controller.Get();
  
          // Assert
          Assert.AreEqual(true, result.IsSuccess);
          Assert.AreEqual(1, result.PayLoad.Count);
          Assert.AreEqual("people", result.PayLoad[0].Name);
      }
  </code></pre>
  
  <p>This is the code that is being tested.</p>
  
  <pre><code>public class TagController : ApiController
  {
      public IGenericService&lt;Tag&gt; _service;
  
      public TagController()
      {
          _service = new TagService();
      }
  
      public TagController(IGenericService&lt;Tag&gt; service)
      {
          this._service = service;
      }
  
      // GET api/values
      public Response&lt;Tag&gt; Get()
      {
          HttpContext context = HttpContext.Current;
          string username = context.Request.Headers["username"].ToString();
          string password = context.Request.Headers["password"].ToString();
          string token = context.Request.Headers["token"].ToString();
          return (Response&lt;Tag&gt;) _service.FindAll(username, password, token);
      }
  }
  </code></pre>