BA
balanikas/FluentAssertions.Http
Http extensions package for FluentAssertions
FluentAssertions.Http
Http extensions for FluentAssertions
API Docs
https://balanikas.github.io/FluentAssertions.Http/api/index.html
Usage
Given a response from an http request
var response = await _factory.CreateClient().GetAsync("/api/customers");and an expectation
var expected = new CustomerModel();Headers
//assert content headers
response.Should().HaveContentHeader("X-Custom-Header");
response.Should().HaveContentHeaderValue(HttpResponseHeader.ContentType, "application/json; charset=utf-8");
response.Should().HaveContentHeaderValues(HttpResponseHeader.Allow, new[] { "GET", "PUT" });
//assert response headers
response.Should().HaveResponseHeader("X-Custom-Header");
response.Should().HaveResponseHeaderValue(HttpResponseHeader.AcceptRanges, "range1");
response.Should().HaveResponseHeaderValues(HttpResponseHeader.AcceptRanges, new []{"range1","range2"});Content
//assert string content
response.Should().HaveContentMatching(x => x.StartsWith("hello"));
response.Should().HaveContent("hello world");
//assert typed content
response.Should().HaveContentMatching<CustomerModel>(x => x.Name == "Alex" && x.Addresses.Count == 2);
response.Should().HaveContent<CustomerModel>(expected);
response.Should().HaveContent<CustomerModel>(expected, o => o.Excluding(x => x.Id)); Combine
response.Should()
.HaveResponseHeader("X-Custom-Header")
.And
.HaveContent(expected, options => options.Excluding(x => x.Id));On this page
Languages
C#98.0%PowerShell2.0%
MIT License
Created February 1, 2019
Updated January 3, 2023