for a unit test I am trying to add a value to the HttpApplicationState object, which is the Application property of the HttpContext.Current class. I try with the following code
TextWriter tw = new StringWriter();
HttpWorkerRequest wr = new SimpleWorkerRequest("/webapp", @"path...", "logon.asp", "", tw);
HttpContext.Current = new HttpContext(wr);
//I try the following 2 lines
HttpContext.Current.Application["KeyValue"] = "myValue";
HttpContext.Current.Application.Add("KeyValue", "myValue");
var count = HttpContext.Current.Application.Count;
var get1 = HttpContext.Current.Application["KeyValue"];
var get2 = HttpContext.Current.Application.Get("KeyValue");
But HttpContext.Current.Application.Count is always zero. The values do not get
What am I doing wrong?