Hi,
I have always been faking/mocking/stubbing HttpContext somehow in ASP.NET (much easier in ASP.NET MVC/MonoRail).
But I can see that HttpContext itself can be constructed easily, literally with couple of lines of code.
var tw = new StringWriter();
var workerReq = new SimpleWorkerRequest("/webapp", @"c:\here\there\wwwroot", "page.aspx", tw);
var context = new HtpContext(workerReq);
If we'll wrap this code into something like this it should work fine, and probably we can even render ASPX using that:
using(Simulate.HttpContext()) {
HttpContext.Current.BlaBla;
}
So the questions are:
- Reasons why it should NOT be done.
- Reasons why it SHOULD be done.
- Why it is not widely used (in fact I do not remember ANY posts about it).
I remember one post where Phill Haack constructed HttpContext using Reflection hacks.
But it seems it is just not needed.
Cheers,
Dmitriy.