<p>How do you unit test a <code>HttpModule</code> in asp.net given that <code>HttpApplication</code> and <code>HttpContext</code> do no implement an interface ?</p>

[{'answer_id': 25250, 'author': 'Dale Ragan', 'author_id': 1117, 'author_profile': 'https://Stackoverflow.com/users/1117', 'pm_score': 2, 'selected': False, 'text': '<p>In the past before moving to ASP.NET MVC, I used <a href="http://haacked.com/archive/2007/09/09/ihttpcontext-and-other-interfaces-for-your-duck-typing-benefit.aspx" rel="nofollow noreferrer">this library</a> Phil Haack created for Unit Testing anything that used the HttpApplication and HttpContext.  It in turned used a <a href="http://www.deftflux.net/blog/page/Duck-Typing-Project.aspx" rel="nofollow noreferrer">Duck Typing library</a>.</p>\n\n<p>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.</p>\n'}, {'answer_id': 25256, 'author': 'Mike', 'author_id': 1573, 'author_profile': 'https://Stackoverflow.com/users/1573', 'pm_score': 2, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 4555694, 'author': 'Dror Helper', 'author_id': 11361, 'author_profile': 'https://Stackoverflow.com/users/11361', 'pm_score': 0, 'selected': False, 'text': '<p>You can use an Isolation (mocking) framework. I know of two tools that enable you to fake/mock any .NET objects - <a href="http://www.typemock.com/typemock-isolator-product3" rel="nofollow">Typemock Isolator</a> and <a href="http://www.telerik.com/products/mocking.aspx" rel="nofollow">Telerik JustMock</a> i think that you can also use <a href="http://social.msdn.microsoft.com/Forums/en/pex/thread/d73f730b-37df-40f9-8c62-afb76993fbbe" rel="nofollow">Moles</a>.</p>\n\n<p>All of the above will enable you to fake any .NET object event if it does not implement an interface or even have a public c\'tor.</p>\n'}]
['https://Stackoverflow.com/questions/25241', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1725/']