Skip to content

How to mock HttpTransport.RequestAsync? #105

@KPGDL

Description

@KPGDL

The documentation is very limited.
https://github.com/elastic/elastic-transport-net/blob/main/README.md#mocking-response-objects-for-testing

var elasticsearchClient = new Mock<ElasticsearchClient>();
var response = TestableResponseFactory.CreateSuccessfulResponse<StringResponse>(new(), 200);
elasticsearchClient.Setup(x => x.Transport.RequestAsync<StringResponse>(
                                     It.IsAny<HttpMethod>(),
                                     It.IsAny<string>(),
                                     It.IsAny<PostData>(),
                                     It.IsAny<RequestParameters>(),
                                     It.IsAny<OpenTelemetryData>(),
                                     It.IsAny<CancellationToken>())).ReturnsAsync(response);

I'm getting this in Moq: Non-overridable members (here: HttpTransport.RequestAsync) may not be used in setup / verification expressions.
@flobernd @stevejgordon @Mpdreamz

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions