TestResponses 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TestResponses --version 0.2.0
                    
NuGet\Install-Package TestResponses -Version 0.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TestResponses" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TestResponses" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TestResponses" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TestResponses --version 0.2.0
                    
#r "nuget: TestResponses, 0.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TestResponses@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TestResponses&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TestResponses&version=0.2.0
                    
Install as a Cake Tool

TestResponses

Readable, contextual API test responses for .NET

Overview

TestResponses is a set of HttpResponseMessage decorators that make API integration tests more readable and more informative, while keeping everything you need easy to access.

Here’s a plain HttpResponseMessage example:

var httpResponse = await _weatherApi.GetTodayWeather("Saratov");
httpResponse.EnsureSuccessStatusCode();
var dto = await httpResponse.Content.ReadFromJsonAsync<WeatherForecast>();

dto!.City.Should().Be("Saratov");

With TestResponses, test code becomes much simpler:

var response = await _weatherApi.GetTodayWeather("Saratov");

response.AsDto!.City.Should().Be("Saratov");

The main value is in failure messages. Instead of a generic HttpRequestException, TestResponses shows response context, which makes it easier to understand the failure without debugging:

TestResponses.TestResponseAssertionException
Response status code is not 200
Status code: 400 (Bad Request)
Response:
{
  "type": "Validation",
  "title": "Request validation failed",
  "status": 400,
  "errors": {
    "date": ["'00000000-0000-0000-0000-000000000000' is not a valid date"]
  }
}

It is not restricted to 200 status code - you can assert any status code you need.

It is not restricted to JSON responses either, because TestResponses - is a family of response types that support different responses - from empty to JSON and files. And they are designed to be extensible, so you can create a type that fits your scenario.

Get started

1. Install

dotnet add package TestResponses

2. Instantiate

Wrap the request task in a suitable TestResponse type with ReadAs:

public Task<TestJsonResponse<WeatherForecast>> GetTodayWeather(string city)
{
    return httpClient
        .GetAsync($"forecasts?city={city}&date=today")
        .ReadAs<TestJsonResponse<WeatherForecast>>(expectedStatusCode: 200);
}

3. Await and use

var response = await _weatherApi.GetTodayWeather("Saratov");

var statusCode = response.StatusCode;
var rawResponse = response.HttpResponse;
var dto = response.AsDto;

Documentation

For more information you can read the docs.
Docs →

Project also has usage examples with failing tests that you can run and play around with
Examples →

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.1 113 5/16/2026
0.2.0 102 5/4/2026
0.2.0-prerelease.2 64 5/1/2026
0.2.0-prerelease.1 62 4/22/2026
0.1.0 948 12/19/2025

This release is mostly a cleanup with a few features that were missing

## Changes

### Added
- XML-docs throughout public members
- `TestFileResponse` exposes `FileName` and `FileNameStar` values
- Formatters for response type are configurable now (`TestJsonResponse.GlobalJsonConfig.Formatter` for example)

### Changed
- README should be more friendly now
- TestResponseAssertionException is now rendering the response info in the message (requires a new argument)
- Deserialization failure message shows generic-friendly name (`List<WeatherDto>` instead of just ``List`1``)

### Fixed
- ReadAs is now safe for async with synchronization context


## Repo changes

- tests are multitargeted like the package
- pipeline for feature branches (checks the tests)
- pipeline for release branches (packs a prerelease package and can publish it)
- pipeline for automatic release creation (with publishing) after release branch merge