Created
April 6, 2022 10:57
-
-
Save andreidiaconu90/fb55c9ba7b367bb11ab7e03cf540a2cd to your computer and use it in GitHub Desktop.
Medium.com - C# Mock multiple HttpClient calls support 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_httpHandlerMock.Protected().Setup<Task<HttpResponseMessage>>( | |
"SendAsync", | |
ItExpr.Is<HttpRequestMessage>(rm => rm.RequestUri.AbsoluteUri.EndsWith("/getStudentDetails/{identifier}"), | |
ItExpr.IsAny<CancellationToken> ()).ReturnsAsync(mockedStudentDetailsResponse)); | |
_httpHandlerMock.Protected().Setup<Task<HttpResponseMessage>>( | |
"SendAsync", | |
ItExpr.Is<HttpRequestMessage>(rm => rm.RequestUri.AbsoluteUri.EndsWith("/getStudentGrades/{identifier}"), | |
ItExpr.IsAny<CancellationToken> ()).ReturnsAsync(mockedStudentGradesResponse)); | |
var httpClient = new HttpClient(_httpHandlerMock.Object) { | |
BaseAddress = new Uri("https://my-unit-test-url/") | |
}; | |
var myService= new MyService(httpClient); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment