I have a unit test for an Http handler. In it I create a HttpResponse object and pass it to one of my Http handler’s methods.
One of my tests attempts to verify that the response headers have been set correctly:
Assert.AreEqual( "gzip", response.Headers["Content-Encoding"]);
However, the Headers property throws a PlatformNotSupportedException with the message “This operation requires IIS integrated pipeline mode”.
The strange thing is that as I understand it, that exception is related to setting reponse headers – not reading them. I’m using TDD, so I don’t set the headers anywhere (yet), but still I’m getting the exception.
Why am I getting this exception and is there a good or better way to unit test response headers?
From the Response.Headers documentation:
Basically you can’t even attempt to access it unless you’re running with those conditions.
If I were you, I would create a constructor for your Handler that accepts an HttpContextBase object and use a mock in order to test your headers properly.