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

Add some more fluent APIs #15

Closed
richardszalay opened this issue Apr 27, 2016 · 0 comments
Closed

Add some more fluent APIs #15

richardszalay opened this issue Apr 27, 2016 · 0 comments

Comments

@richardszalay
Copy link
Owner

richardszalay commented Apr 27, 2016

Currently, creating a mock HttpClient looks like this:

var mockHandler = new MockHttpMessageHandler();
mockHandler.When("urAl").Respond(responseA);
mockHandler.When("urlA").Respond(responseB);
var httpClient = new HttpClient(mockHandler);

This could be made cleaner, at least for single-url mocks, via an AsHttpClient() method:

var httpClient = new MockHttpMessageHandler()
    .When("urlA").Respond(responseA)
    .AsHttpClient();

This could be taken one step further by having Respond return the MockHttpMessageHandler, allowing the following:

var httpClient = new MockHttpMessageHandler()
    .When("urlA").Respond(responseA)
    .When("urlB").Respond(responseB)
    .AsHttpClient();

It would even work for complex requirements with some imaginative spacing:

var httpClient = new MockHttpMessageHandler()
    .When("urlA")
        .WithQueryString("key", "value")
        .Respond(responseA)
    .When("urlB")
        .Respond(responseB)
    .AsHttpClient();

It's important that these changes be made in a backward-compatible fashion.

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

No branches or pull requests

1 participant