(Similar to .NET how to fudge the HttpContext object!)
I have a method that I want to test:
public void MyMethod()
{
if (HttpContext.Current.Application["myValue"] != null)
Console.WriteLine("Boo!");
}
How can I write a test WITHOUT refactoring the method so that the Console.WriteLine
is hit?
I tried with:
TextWriter tw = new StringWriter();
HttpWorkerRequest wr = new SimpleWorkerRequest("/webapp", @"path...", "logon.asp", "", tw);
HttpContext.Current = new HttpContext(wr);
HttpContext.Current.Application.Add("KeyValue", "myValue");
MyMethod();
but HttpContext.Current.Application.count is always zero, I cannot add values to it!