Im just trying to Unit-Test my custom ApiController
. In my custom controller i override the Initialize
method to evaluate the authorization-header.
So my problem is, that i there are 2 request-headers available.
protected override void Initialize(HttpControllerContext controllerContext)
{
base.Initialize(controllerContext);
// Headers 1
var headersOne = controllerContext.Request.Headers;
// Headers 2
var headersTwo = HttpContext.Current.Request.Headers;
}
But this it not the problem itself. The problem is, that the headers don't match. So for the productive operating: Where do i have to look for the authorization-header. And where do i have to apply my authorization-header for my test-scenario.
At the moment i apply the authorization-header to the controllerContext
:
var fakeControllerContext = new HttpControllerContext
{
Request = new HttpRequestMessage
{
RequestUri = new Uri("http://localhost/api/test"),
Headers =
{
{ "Authorization", "Fake Authorization-Header"}
}
}
};
But as i already said. The header is later not available in HttpContext.Current.Request.Headers
.
Can you please help me out? Unfortunately i don't exactly understand which context fulfills what purpose.