Skip to content

Instantly share code, notes, and snippets.

@andreidiaconu90
Created April 6, 2022 10:57
Show Gist options
  • Save andreidiaconu90/fb55c9ba7b367bb11ab7e03cf540a2cd to your computer and use it in GitHub Desktop.
Save andreidiaconu90/fb55c9ba7b367bb11ab7e03cf540a2cd to your computer and use it in GitHub Desktop.
Medium.com - C# Mock multiple HttpClient calls support 3
_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