title: How to unit test a service which uses caching?
body: <p>I have a service layer, which has a range of methods. These methods have implemented caching, like the following:</p>
  
  <pre><code>string key = "GetCategories";
  if (CacheHandler.IsCachingEnabled() &amp;&amp; !CacheHandler.ContainsKey(key))
  {
      var categories = RequestHelper.MakeRequest("get_category_index")["categories"];
      var converted = categories.ToObject&lt;List&lt;Category&gt;&gt;();
      CacheHandler.InsertToCache(key,converted);
      return converted;
  }
  return CacheHandler.GetCache(key) as List&lt;Category&gt;;
  </code></pre>
  
  <p>Now, problem is I also want to make a unit test, like the following:</p>
  
  <pre><code>[TestMethod]
  public void GetCategories()
  {
      IContentService contentService = new ContentService();
      var resp = contentService.GetCategories();
      Assert.IsNotNull(resp,"Should not be null");
  }
  </code></pre>
  
  <p>Problem is, that the <code>HttpContext.Current</code> inside my <code>CacheHandler</code> is null during the unit test (obviously).</p>
  
  <p>What is the easiest way to fix this?</p>
  
  <p>(Please be as specific as possible because I haven't done a lot of unit testing before)</p>