moick IHttpContextAccessor add header code example
Example: adding values to mock IHttpContextAccessor unit test .net core
[Fact]
public async Task test_GetBookByBookId() {
var mockHttpContextAccessor = new Mock<IHttpContextAccessor>();
var context = new DefaultHttpContext();
var fakeTenantId = "abcd";
context.Request.Headers["Tenant-ID"] = fakeTenantId;
mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);
var mockHeaderConfiguration = new Mock<IHeaderConfiguration>();
mockHeaderConfiguration
.Setup(_ => _.GetTenantId(It.IsAny<IHttpContextAccessor>()))
.Returns(fakeTenantId);
var book = new Book(mockHttpContextAccessor.Object, mockHeaderConfiguration.Object);
var bookId = "100";
var result = await book.GetBookByBookId(bookId);
result.Should().NotBeNull().And.
BeOfType<List<BookModel>>();
}