title: HttpContextBaseExtensions.GetOwinContext throws NullReferenceException when trying to run Unit tests
body: <p>I get a NullReferenceException when trying to run Unit tests for a program written in the ASP.NET MVC framework.</p>
  
  <blockquote>
    <p>Test(s) failed. System.NullReferenceException : Object reference not
    set to an instance of an object.    at
    System.Web.HttpContextBaseExtensions.GetOwinContext(HttpContextBase
    context)</p>
  </blockquote>
  
  <p>This error happens when I try to execute the <code>Logoff</code> method.</p>
  
  <pre><code>public ActionResult LogOff()
  {
       SessionWrapper.SetInSession("_Settings", null);  
       AuthenticationManager.SignOut();
       return RedirectToAction("Index", "Home");
  }
  
  public class HttpContextSessionWrapper : ISessionWrapper
  {
          public T GetFromSession&lt;T&gt;(string key)
          {
              if (!string.IsNullOrEmpty(key))
                  return (T)HttpContext.Current.Session[key];
              else    
                  return default(T);
          }
  
          public void SetInSession(string key, object value)
          {
              if (!string.IsNullOrEmpty(key))
                  HttpContext.Current.Session[key] = value;
          }
  }
  </code></pre>
  
  <p>How do I fix this NullReferenceException when writing unit tests in ASP.NET MVC?</p>