Skip to content

SetupRequest only works when calling the Async methods on HttpClient. #19

Description

@tubenator

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions