Skip to content

Fluent URL builder and testable HTTP client for .NET expanded to integration test APIs with support for fluently asserting

License

Notifications You must be signed in to change notification settings

tookinaboot/Flurl.Http.Testing

 
 

Repository files navigation

Flurl.Http.Testing

Flurl.Http.Testing is a variation of Flurl.Http, which modifies and extends features to provide support for things commonly needed to effectively test HTTP APIs from the API consumer's perspective. This library removes the unit testing features of Flurl.Http, which provide features needed to unit test code, which uses Flurl.Http to make HTTP calls. Instead, this library's testing features are strictly related to consuming an API in a deployed environment - In other words, to integration test, not unit test the API.

What is different or added from vanilla Flurl.Http

  1. Modified behavior of HTTPClient to provide TestMethod isolation
  2. Fluent skipping serialization of properties within HTTP bodies to enable easily testing things like backwards compatibility without having different versions of C# classes with JsonIgnore attributes.
  3. Fluent asserts on IFluentResponse to make tests more readable

Below is the original README.md content from fork: https://github.com/tmenier/Flurl

Build status Flurl-stable Flurl.Http-stable Flurl-pre-release Flurl.Http-pre-release

Flurl is a modern, fluent, asynchronous, testable, portable, buzzword-laden URL builder and HTTP client library.

var result = await "https://api.mysite.com"
    .AppendPathSegment("person")
    .SetQueryParams(new { api_key = "xyz" })
    .WithOAuthBearerToken("my_oauth_token")
    .PostJsonAsync(new { first_name = firstName, last_name = lastName })
    .ReceiveJson<T>();

[Test]
public void Can_Create_Person() {
    // fake & record all http calls in the test subject
    using (var httpTest = new HttpTest()) {
        // arrange
        httpTest.RespondWith("OK", 200);

        // act
        await sut.CreatePersonAsync("Claire", "Underwood");
        
        // assert
        httpTest.ShouldHaveCalled("http://api.mysite.com/*")
            .WithVerb(HttpMethod.Post)
            .WithContentType("application/json");
    }
}

Get it on NuGet:

PM> Install-Package Flurl.Http

Or get just the stand-alone URL builder without the HTTP features:

PM> Install-Package Flurl

For updates and announcements, follow @FlurlHttp on Twitter.

For detailed documentation, please visit the main site.

About

Fluent URL builder and testable HTTP client for .NET expanded to integration test APIs with support for fluently asserting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 100.0%