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.
- Modified behavior of HTTPClient to provide TestMethod isolation
- 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.
- Fluent asserts on IFluentResponse to make tests more readable
Below is the original README.md content from fork: https://github.com/tmenier/Flurl
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.