If I set up my code like this:
var handlerMock = new Mock<HttpMessageHandler>();
var httpClient = handlerMock.CreateClient();
httpClient.BaseAddress = new Uri("https://google.com/");
handlerMock
.SetupAnyRequest()
.ReturnsResponse(HttpStatusCode.OK, "", "text/plain");
Then this works fine:
await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, "stuff"));
This throws an exception.
httpClient.Send(new HttpRequestMessage(HttpMethod.Get, "stuff"));
The exception is
<System.InvalidOperationException: Handler did not return a response message.
This happens whether I use .SetupAnyRequest() or any .Setup method.
If I set up my code like this:
Then this works fine:
This throws an exception.
The exception is
<System.InvalidOperationException: Handler did not return a response message.This happens whether I use
.SetupAnyRequest()or any.Setupmethod.