How do you unit test a HttpModule
in asp.net given that HttpApplication
and HttpContext
do no implement an interface ?
Essentially you need to remove the HttpModule's reliance on HttpApplication and HttpContext, replacing them with an interface. You could create your own IHttpApplication and IHttpContext (along with IHttpResonse, IHttpRequest, etc) or use the ones mentioned by @Dale Ragan or use the shiny new ones in System.Web.Abstractions that are bundled with the asp.net mvc previews.
In the past before moving to ASP.NET MVC, I used this library Phil Haack created for Unit Testing anything that used the HttpApplication and HttpContext. It in turned used a Duck Typing library.
Unfortunately, this was the best way to do it. ASP.NET was not made to be easily testable. When they worked on ASP.NET MVC, one of the goals is to get rid of these headaches by making the framework more testable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With