Mocking HttpContext.Current.Application
<p>I try to test Mock <strong>HttpContext.Current.Application</strong> third library which uses the following methods:
  </p>

<pre><code>HttpContext.Current.Application.Add ( "key","value");
HttpContext.Current.Application.Get ("key");
</code></pre>

<p>I tested Lots of mocking frameworks Moq, RhinoMock, FakeSystemWeb, FakeHttpContext
But it is impossible to add value in the Application Dictionary, always <strong>HttpContext.Current.Application.Count == 0</strong></p>

<p>The only solution that works is with Microsoft.Fakes, but alas it is only with the Premium and Ultimate versions, and developers to whom I provided the tests only the Professional Version !!</p>

<p>With Microsoft.Fakes (it works) :</p>

<pre><code> public MockHttpContext()
 {
      //MOCK System.Web
      _shimsContext = ShimsContext.Create();
      var httpRequest = new HttpRequest("", "http://www.monsite.com", "");
      var httpContext = new HttpContext(httpRequest, new(HttpResponse(new(StringWriter()));
      var applicationState = httpContext.Application;
      System.Web.Fakes.ShimHttpContext.CurrentGet = () =&gt; httpContext;
      System.Web.Fakes.ShimHttpContext.AllInstances.ApplicationGet = context =&gt; applicationState;
   }
</code></pre>

<p>Do you have an idea or how to distribute my test Microsoft.Fakes, or another framework of Mocking?</p>

<p>Thank you.</p>