https://github.com/balanikas/fluentassertions.http
Http extensions package for FluentAssertions
https://github.com/balanikas/fluentassertions.http
dotnet fluentassertions nuget-package testing-tools
Last synced: 22 days ago
JSON representation
Http extensions package for FluentAssertions
- Host: GitHub
- URL: https://github.com/balanikas/fluentassertions.http
- Owner: balanikas
- License: mit
- Created: 2019-02-01T18:04:07.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-02-27T08:11:50.000Z (about 2 years ago)
- Last Synced: 2025-04-12T04:07:00.446Z (22 days ago)
- Topics: dotnet, fluentassertions, nuget-package, testing-tools
- Language: C#
- Homepage: https://www.nuget.org/packages/FluentAssertions.Http/1.1.0
- Size: 493 KB
- Stars: 10
- Watchers: 1
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# FluentAssertions.Http
Http extensions for FluentAssertions[](https://github.com/balanikas/FluentAssertions.Http/actions/workflows/dotnet.yml)
[](https://github.com/balanikas/FluentAssertions.Http/actions/workflows/codeql.yml)


[](https://github.com/balanikas/FluentAssertions.Http/stargazers)## API Docs
https://balanikas.github.io/FluentAssertions.Http/api/index.html## Usage
##### Given a response from an http request
```csharp
var response = await _factory.CreateClient().GetAsync("/api/customers");
```
##### and an expectation
```csharp
var expected = new CustomerModel();
```
#### Headers
```csharp
//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
```csharp
//assert string content
response.Should().HaveContentMatching(x => x.StartsWith("hello"));
response.Should().HaveContent("hello world");
//assert typed content
response.Should().HaveContentMatching(x => x.Name == "Alex" && x.Addresses.Count == 2);
response.Should().HaveContent(expected);
response.Should().HaveContent(expected, o => o.Excluding(x => x.Id));
```
#### Combine
```csharp
response.Should()
.HaveResponseHeader("X-Custom-Header")
.And
.HaveContent(expected, options => options.Excluding(x => x.Id));
```