Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

adding values to mock IHttpContextAccessor unit test .net core

[Fact]
public async Task test_GetBookByBookId() {
    //Arrange

    //Mock IHttpContextAccessor
    var mockHttpContextAccessor = new Mock<IHttpContextAccessor>();
    var context = new DefaultHttpContext();
    var fakeTenantId = "abcd";
    context.Request.Headers["Tenant-ID"] = fakeTenantId;
    mockHttpContextAccessor.Setup(_ => _.HttpContext).Returns(context);
    //Mock HeaderConfiguration
    var mockHeaderConfiguration = new Mock<IHeaderConfiguration>();
    mockHeaderConfiguration
        .Setup(_ => _.GetTenantId(It.IsAny<IHttpContextAccessor>()))
        .Returns(fakeTenantId);

    var book = new Book(mockHttpContextAccessor.Object, mockHeaderConfiguration.Object);

    var bookId = "100";

    //Act
    var result = await book.GetBookByBookId(bookId);

    //Assert
    result.Should().NotBeNull().And.
        BeOfType<List<BookModel>>();
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: unity no serializefield 
Csharp :: get list length c# 
Csharp :: delegate in c# 
Csharp :: c# linq distinct group by nested list 
Csharp :: c# radio button checked 
Csharp :: c# get last day of month 
Csharp :: char to digit in java 
Csharp :: c# get excel column number from letter 
Csharp :: c# unescape string 
Csharp :: unity text custom color 
Csharp :: convert object to httpcontent c# 
Csharp :: copy class c# 
Csharp :: use raycast unity new input system 
Csharp :: asp.net mvc get current url in view 
Csharp :: c# get type of class 
Csharp :: c# get the first 4 characters in the list 
Csharp :: if debug c# 
Csharp :: how to get row index of selected row in gridview asp.net webforms 
Csharp :: c# add time to datetime 
Csharp :: Terrain Tools unity missing 
Csharp :: how to get file type from base64 in c# 
Csharp :: enum c# 
Csharp :: c# backup sql 
Csharp :: Data at the root level is invalid. Line 1, position 1. 
Csharp :: how to pass id from view to controller in asp.net core 
Csharp :: c# type of string 
Csharp :: convert pdf to image c# 
Csharp :: c# show list in richtextbox 
Csharp :: set file to read only C# 
Csharp :: unity rigidbody2d disable 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =