Request: Please make it possible to fake HTTP headers
Closed this issue · 4 comments
hiredgunhouse commented
See title
vadimzozulya commented
Is this what are you expect? :
using (new FakeHttpContext { { headerKey, headerValue } })
{
HttpContext.Current.Request.Headers[headerKey].Should().Be(headerValue);
}
hiredgunhouse commented
Yes, that would be perfect.
To explain my need, I had a case where I needed to make sure that this condition is met:
if (request.IsAjaxRequest() && request.AcceptTypes.Contains("application/json"))
hiredgunhouse commented
I can see you already implemented that, huge thanks!
vadimzozulya commented
I've moved headers to Request property just to make clear which headers are set.
using (new FakeHttpContext { Request = { { headerKey, headerValue } } })
...
Also now you can set accept types
using (new FakeHttpContext
{
Request = { AcceptTypes = new[] { "application/json", "application/javascript" } }
})
...