In API Controller, it fetches HttpContextRequest header to get access token. When I using UnitTest how I will pass access_token value to controller action. Please help.
var _access_token = HttpContext.Current.Request.Headers["access_token"];
In API Controller, it fetches HttpContextRequest header to get access token. When I using UnitTest how I will pass access_token value to controller action. Please help.
var _access_token = HttpContext.Current.Request.Headers["access_token"];
You can write like this,
//Arrange
var client = new HttpClient { BaseAddress = new Uri("http://localhost:55442/")
};
client.DefaultRequestHeaders.Add("access_token", "YWtoaWw6YWtoaWw=");
Employee emp = new Employee {
Id=1,
name = "Test Name",
salary = "2000"
};
//Act
var _response =
client.PostAsJsonAsync(client.BaseAddress +"/"+ "myController"+ "/"+
"methodName",emp).Result;
//Assert
Assert.IsTrue(true);
Cheers...