title: HttpContext is null in the controller during Unit Testing in Asp.net MVC
body: <p>Here is my Asp.net Controller Property and Method</p>
  
  <pre><code>    public ApplicationSignInManager SignInManager
      {
          get
          {
              return _signInManager ?? HttpContext.GetOwinContext().Get&lt;ApplicationSignInManager&gt;();
          }
          private set { _signInManager = value; }
      }
  
  
      [HttpPost]
      [AllowAnonymous]
      [ValidateAntiForgeryToken]
      public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
      {
          if (!ModelState.IsValid)
          {
              return View(model);
          }
  
          // This doesn't count login failures towards account lockout
          // To enable password failures to trigger account lockout, change to shouldLockout: true
          var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
  
  
          switch (result)
          {
              case SignInStatus.Success:
                  return RedirectToLocal(returnUrl);             
  
              default:
                  ModelState.AddModelError("", "Invalid login attempt.");
                  return View(model);
          }
      }
  </code></pre>
  
  <p>My Unit Test </p>
  
  <pre><code> [TestMethod]
      public void Login_WhenEnteredValidCredential_AllowsUserToLogIn()
      {
  
          var model = new LoginViewModel
          {
              Password = "TestPassWord1",
              UserName = "TestUserName",
              RememberMe = true
          };
  
          HttpContext.Current = new HttpContext(
      new HttpRequest(null, "http://tempuri.org", null),
      new HttpResponse(null));
  
         var accountController = new AccountController(); 
          var result= accountController.Login(model,null);
          Assert.AreEqual(result.Status,TaskStatus.RanToCompletion);
  
  
      }
  </code></pre>
  
  <p>The problem here is that whenever i run the unit test HttpContext inside the property SignInManager becomes null. Is there a way to set the HttpContext from the Unit Test? 
  PLease note i have referred to this links but the solution there doesnt work me</p>
  
  <p><a href="https://stackoverflow.com/questions/22604308/mock-httpcontext-using-moq-for-unit-test">Mock HttpContext using moq for unit test</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3234693/using-httpcontext-in-unit-test">Using httpcontext in unit test</a></p>
  
  <p><a href="http://caioproiete.net/en/fake-mock-httpcontext-without-any-special-mocking-framework/" rel="nofollow noreferrer">http://caioproiete.net/en/fake-mock-httpcontext-without-any-special-mocking-framework/</a></p>