A small, runnable sample that tells you when an upgrade or a cleanup changes the responses other people depend on.
Unit tests tell you the code still does what the code does. They don't tell you the API still returns what a partner's import job expects. A renamed JSON property, a different date format in a nightly CSV, a column in a new position: all of these can pass every unit test and still break someone downstream.
This post shows a small way to catch that. You record real responses from the current system, store them as files, and replay the same requests against the new build. I built a small sample for it, ran it on .NET 8 and .NET 10, and the code below is copied from that sample. It is a made-up orders API, not a real production system.
The sample
OrdersApi is an ASP.NET Core minimal API with two things a partner might depend on: a JSON endpoint and a CSV export.
app.MapGet("/orders/{id:int}", (int id) => orders.TryGetValue(id, out var o) ? Results.Ok(o) : Results.NotFound(new { error = "order_not_found", id })); app.MapGet("/orders/export.csv", () => { var sb = new StringBuilder("OrderId,Customer,PlacedOn,Total,Status\n"); foreach (var o in orders.Values.OrderBy(o => o.Id)) sb.Append(string.Create(CultureInfo.InvariantCulture, $"{o.Id},{o.Customer},{o.PlacedOn:yyyy-MM-dd},{o.Total:0.00},{o.Status}\n")); return Results.Text(sb.ToString(), "text/csv"); }); The project targets both net8.0 and net10.0, so the same code runs on either.
Step 1: record the current behaviour
Start the system you trust, which is the version that runs today, and capture the responses. A short script is enough. This one calls each path and writes a JSON file per request:
for name, path in cases: r = urllib.request.urlopen(base + path) body = r.read().decode("utf-8").replace("\r\n", "\n") rec = {"name": name, "method": "GET", "path": path, "status": r.status, "contentType": r.headers.get_content_type(), "body": body} (out / f"{name}.json").write_text(json.dumps(rec, indent=2) + "\n") One of the recordings looks like this:
{ "name": "order-1001", "method": "GET", "path": "/orders/1001", "status": 200, "contentType": "application/json", "body": "{\"id\":1001,\"customer\":\"ACME Ltd\",\"placedOn\":\"2026-03-14T09:30:00Z\",\"total\":1249.50,\"status\":\"SHIPPED\"}" } Note the 1249.50. The trailing zero is part of what the API returns today, and a recording keeps it. I'd rather find that out from a file than from a partner.
Step 2: replay them in a test
The test host from Microsoft.AspNetCore.Mvc.Testing runs the API in memory, so there is no port to manage. Each recording becomes one test case:
public class ReplayTests : IClassFixture<WebApplicationFactory<Program>> { private readonly HttpClient _client; public ReplayTests(WebApplicationFactory<Program> factory) => _client = factory.CreateClient(); [Theory] [MemberData(nameof(Recording.LoadAll), MemberType = typeof(Recording))] public async Task Response_matches_what_the_old_system_returned(Recording rec) { var response = await _client.SendAsync(new HttpRequestMessage(new HttpMethod(rec.Method), rec.Path)); var body = (await response.Content.ReadAsStringAsync()).Replace("\r\n", "\n"); Assert.Equal(rec.Status, (int)response.StatusCode); Assert.Equal(rec.ContentType, response.Content.Headers.ContentType?.MediaType); Assert.Equal(rec.Body, body); } } It compares the status code, the content type and the exact body. I normalise line endings so the CSV doesn't fail only because of Windows versus Linux.
Step 3: run it on both versions
dotnet test ReplayTests -f net8.0 dotnet test ReplayTests -f net10.0 In my run, all four recordings passed on both .NET 8 and .NET 10. For this small API, retargeting changed nothing a partner would see. A real system will have more surface than this, but the check is the same.
Step 4: see it catch a change
Upgrades are rarely the only thing that changes. People tidy things while they are in the code. To show what a failure looks like, I made two small "cleanups" on a copy of the sample: a snake_case JSON naming policy, and a different date format in the CSV (dd/MM/yyyy instead of yyyy-MM-dd). Three of the four tests failed on .NET 10:
Failed ... (rec: export-csv) Expected: ···"tatus\n1001,ACME Ltd,2026-03-14,1249.50,SH"··· Actual: ···"tatus\n1001,ACME Ltd,14/03/2026,1249.50,SH"··· Failed ... (rec: order-1001) Expected: ···"":"ACME Ltd","placedOn":"2026-03-14T09:30"··· Actual: ···"":"ACME Ltd","placed_on":"2026-03-14T09:3"··· Both changes look harmless in a code review. Neither would fail a typical unit test. Anyone parsing placedOn by name would break.
When a replay test fails
A failure doesn't always mean you should revert. It means the contract changed, and someone should decide that on purpose. If the change is intended, tell the consumers, then re-record. If it isn't, fix the code.
What this doesn't cover
It is a snapshot of a few requests, so it only protects what you recorded. Things that change between runs, such as timestamps or generated ids, need to be fixed in the test data or masked before comparing. It doesn't test performance, and it doesn't replace testing against real partner systems.
Take it further
- Record more paths from real traffic, with sensitive values removed.
- Run the replay in your CI pipeline on every commit.
- Keep recordings in the repository, so a change to a response shows up in the pull request.
The full sample, with the recording script and both projects, is on GitHub: dotnet-upgrade-replay-tests.