Last active
April 6, 2022 10:56
-
-
Save andreidiaconu90/4bbc1fd72b134b6f77e2a8fcdfbdff13 to your computer and use it in GitHub Desktop.
Medium.com - C# Mock multiple HttpClient calls support 2
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
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