I’m writing this as much for my own purposes as yours — I’d found this utility a while ago, and I’d forgotten where it was. So, after searching for roughly half an hour, I found it again and wanted to post it here so I’ll know where it is later (and so you can find it to, of course).
One of the big problems with doing any kind of hard-core OO design or coding with Asp.Net is the dependency on the Asp.Net runtime — it initializes all the cool stuff you get used to using, like the Session, the HttpContext, Requests, etc. Granted, you can (and should) design to where you aren’t dependent on those things directly, but sometimes it’s just not worth the hassle.
At the moment, I’m working on a little project, one I’ll release here shortly, and it uses reflection pretty heavily to get properties from a web control. Given the nature of the project, I’m not wanting to filter out the properties — I want access to everything, because it’s easier to code to get everything in this case, and also because I want it generalized well enough to where it doesn’t need to be re-written by every end user to accomplish what they want to accomplish. The problem arises in the reflection part of the code trying to get the values of Asp.Net-specific properties from a control, stuff like Application and Trace. These, of course, aren’t initialized, and need to be hacked around, or else we get TargetInvokeExceptions that choke the unit tests.
So, I attempted to use Phil Haack’s HTTPSimulator to get around this. Unfortunately, I’m not able to get my stuff to work right even with this, so I need to go back to the drawing board anyways (probably a try/catch block, as much as I hate to do it). But, this little utility is still a great addition to any web developer’s toolbox.
Posted by: mcory
Posts that may or may not be similar to the above:
- Ground-Up ASP.Net Development I: At the…Well…Ground.
- Refactoring Towards Unit Tests
- Unit Testing & Code Coverage
- LSP Revisited: Quick Violation Check
- Improving Page Responsiveness
Categories: