Skip to content

Instantly share code, notes, and snippets.

@andreidiaconu90
Last active April 6, 2022 10:56
Show Gist options
  • Save andreidiaconu90/4bbc1fd72b134b6f77e2a8fcdfbdff13 to your computer and use it in GitHub Desktop.
Save andreidiaconu90/4bbc1fd72b134b6f77e2a8fcdfbdff13 to your computer and use it in GitHub Desktop.
Medium.com - C# Mock multiple HttpClient calls support 2
var mockedResponseMessage = new HttpResponseMessage {
StatusCode = HttpStatusCode.OK,
Content = new StringContent("mocked-response-data-as-string-here")
};
_httpHandlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>())
.ReturnsAsync(mockedResponseMessage);
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