I have the following method to create a Http client with a mocked response:
public static HttpClient GetMockedHttpClient(string responseContent, HttpStatusCode httpStatusCode)
{
var handlerMock = new Mock<HttpMessageHandler>(MockBehavior.Strict);
handlerMock
.Protected()
.Setup<Task<HttpResponseMessage>>(
"SendAsync",
ItExpr.IsAny<HttpRequestMessage>(),
ItExpr.IsAny<CancellationToken>()
)
.ReturnsAsync(new HttpResponseMessage()
{
StatusCode = httpStatusCode,
Content = new StringContent(responseContent),
})
.Verifiable();
return new HttpClient(handlerMock.Object);
}
How can I make the response dependent on a specific url, so that the setup only takes effect when the HttpClient is called with a given address?