1

In order to facilitate unit testing of components that reference the HttpApplication, we have a class that uses a lambda + proxy wrapper to direct the call to either a mocked HttpApplication or the real HttpApplication (via a proxy class), using HttpContext.Current.ApplicationInstance.

However, we have code in an IHttpModule that is added to our pipeline, and one of the parameters of the event being fired is the Object sender, which is cast to an HttpApplication. In order to mock this appropriately, I would like to use the proxy class that refers to HttpContext.Current.ApplicationInstance rather than the sender parameter on the event. Based on my reading of the request pipeline documentation, I'm not sure how the two would ever be different, but I'm not certain enough to throw that in production and see if it's true. :)

Are they always the same? If not, does anyone have a good suggestion on how to mock references to HttpApplication in an IHttpModule where we are explicitly passed the HttpApplication reference?

wibarr
  • 276
  • 1
  • 3
  • 13
  • This actually sounds like an integration test (http://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test).The HttpApplication is passed to IHttpModule Init so passing HttpContext.Current.ApplicationInstance should do it. Alternatively you can achieve this without the proxy, using a mocking tool like Typemock (www.typemock.com), which is more straightforward and gives you better control over the flow of the test. Can you please share a code snippet? – Gregory Prescott Mar 31 '16 at 08:30

0 Answers0