Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response sequence #507

Open
robert-bialy opened this issue Dec 19, 2022 · 1 comment
Open

Response sequence #507

robert-bialy opened this issue Dec 19, 2022 · 1 comment
Labels
feature-request A request for new functionality
Milestone

Comments

@robert-bialy
Copy link

I would like to have an option to setup a sequence of responses for certain request. It would certainly help with testing retry policies.

Describe the solution you'd like

Moq allows for user to setup a sequence of responses like:

consumerService.SetupSequence(c => c.Consume(It.IsAny<CancellationToken>()))
    .Returns(payload)
    .Throws<OperationCanceledException>()
    .Returns(payload);

It would be great if we would be able to do the same in this library:

builder
    .Requests()
    .ForPost()
    .ForHttps()
    .ForHost(host)
    .ForPath(endpoint)
    .RespondsInSequence()
        .WithStatus(HttpStatusCode.InternalServerError)
    .Then()
        .WithStatus(HttpStatusCode.InternalServerError)
    .Then()
        .WithStatus(HttpStatusCode.OK)
    .RegisterWith(options);
@robert-bialy robert-bialy added the feature-request A request for new functionality label Dec 19, 2022
@martincostello
Copy link
Member

Thanks for the suggestion.

This is possible today, albeit not with a Moq-like syntax.

Using the latest available release, you can do something like this:

https://github.com/justeat/httpclient-interception/blob/7216d7cb0237f944c2681aa0db1d81776a1b0d28/tests/HttpClientInterception.Tests/Examples.cs#L698-L757

In the next release, this can be simplified a bit using the new ForAll() method:

https://github.com/justeat/httpclient-interception/blob/2558c1d25498a1160caf6f34fa59e31ba3f29f94/tests/HttpClientInterception.Tests/Examples.cs#L698-L756

I'll leave this open for us to consider if there's a relatively low-effort way we could achieve an API similar to what you suggested with some additional extension methods or similar in a future release.

@martincostello martincostello added this to the Future milestone Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request A request for new functionality
Projects
None yet
Development

No branches or pull requests

2 participants