Hi All,
I have to mock the authorization and headers while calling controller action in the Unit test method.
ValueController.cs ( ASP.Net Web Api(.Net Framework 4.6.1)
Public async Task<HttpResponseMessage> ValueProcessMessageAsync()
{
HttpResponseMessage response = new HttpResponseMessage();
try
{
string user = Decode(Request.Headers.Authorization.Parameter);
string clientName= HttpContext.Current.Request.Headers["ClientName"];
response.StatusCode = HttpStatusCode.OK;
return response;
}
catch (Exception)
{
response.StatusCode = HttpStatusCode.InternalServerError;
return response;
}
}
Unit Test:
I can mock the service and Repository layer by using the MOQ framework and do the same in the header request validation.
Help me to mock Headers and Authorization while calling GET/POST/DELETE/PUT action methods in ASP.NET Web API
Thanks,