vadimzozulya/FakeHttpContext

Request: Please make it possible to fake HTTP headers

Closed this issue · 4 comments

See title

Is this what are you expect? :

    using (new FakeHttpContext { { headerKey, headerValue } })
    {
        HttpContext.Current.Request.Headers[headerKey].Should().Be(headerValue);
    }

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"))

I can see you already implemented that, huge thanks!

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" } }
    })
...