I try to test Mock HttpContext.Current.Application third library which uses the following methods:
HttpContext.Current.Application.Add ( "key","value"); HttpContext.Current.Application.Get ("key"); I tested Lots of mocking frameworks Moq, RhinoMock, FakeSystemWeb, FakeHttpContext But it is impossible to add value in the Application Dictionary, always HttpContext.Current.Application.Count == 0
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 !!
With Microsoft.Fakes (it works) :
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 = () => httpContext; System.Web.Fakes.ShimHttpContext.AllInstances.ApplicationGet = context => applicationState; } Do you have an idea or how to distribute my test Microsoft.Fakes, or another framework of Mocking?
Thank you.