Update: Phil Haack has updated his HttpContext Simulator with some new goodies.
Here is an article by Haacked showing how one can create a test friendly httpcontext.
I modified his example some and started using it in some tests; works very nice!
Here is another implementation based on Haack’s example that is supposed to also work with session.
I almost NEVER use session if I can avoid it, but still this could come in handy.
Just curious, but why do you avoid the Session?
It seems like there is almost always a better place to put stuff than in session.
I encrypt data in the querystring to pass data between pages that I don’t want the user to mess with.
A lot of my apps run on a cluster, which is pretty good, but there is always a chance that the user will hit the wrong server, and b/c we are not using state server, their session will be empty.
It also seems like a good way to run into problems, 2 programmers can overwrite each others values in session, if you are looking for a "OrderID" in session, and 2 developers are both using that name for different things in their sections of the application…
For our site, session expires a lot faster than their authentication ticket, so if you are in the middle of working on something that is expecting a value in sesssion, and session has expired, then you are SOL.
Session also dies if your asp.net process recycles.
Some of these problems are fixed if you use a state server… but alas we don’t (yet).
I’m a huge fan of simple, clean URLs, so I’m generally against stashing stuff there if I can avoid it.
One of the first things I did when I started the current project (my first ASP project of any kind) was to build a clone of Ruby on Rails’ Flash, which is a fantastic little idea: it allows me to stash stuff in the Session specifically and only for the next Request, so if a POST comes in, I stash the results in the Flash, then redirect to another page. On that redirected GET I can then access all that stuff. This is currently the only thing I’m using the Session for, but it’s reason enough for me.
Thats interesting. I wasn’t aware of that.
Thanks for posting.