I'm writing some unit tests for a method that takes an HttpContext as a parameter. I want to test that the behavior is as expected when the request is a POST.
When creating a System.Net.HttpWebRequest it's easy to set the method, but I can't see a way to specify the method when creating a System.Web.HttpRequest which is what's used in HttpContext.
Any ideas?
For context the method is called by an httphandler and it is supposed to throw a 405 if the request is not a POST. I know that I can filter the allowable methods with the Verbs property in the web.config, and I will, however there's nothing stopping somebody in the future from changing the verbs property to allow other methods in which case I want the handler to take care of it itself.
Helper method currently in use:
private HttpContext GetHttpContext(string requestUrl)
{
var httpRequest = new HttpRequest("", requestUrl, "");
var stringWriter = new StringWriter();
var httpResponce = new HttpResponse(stringWriter);
return new HttpContext(httpRequest, httpResponce);
}