# Write Integration Tests for an ASP.NET Core API

An agent adds 15 Catalog API integration tests to eShop's functional suite and runs all 65 against a real Postgres, after adding a way around Aspire.

[Run this on Rush](https://cloud.getrush.ai/run/write-integration-tests/aspnet-core/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads `tests/Catalog.FunctionalTests` first and finds 19 `WebApplicationFactory` theories already there, each run for v1 and v2, whose `CatalogApiFixture` starts Postgres through Aspire and Docker. The sandbox had no Docker, so on the untouched clone the database never started and `dotnet test` was killed after 580 seconds.

It extends that project rather than starting a new one. `CatalogApiFixture.cs` now uses the Postgres in `CATALOG_TEST_POSTGRES` when that variable is set and starts the Aspire container otherwise. The new `CatalogApiPagingAndFilterTests.cs` covers page overlap and ordering, walking every page, the last-page remainder, v2 filters by brand, type and name, empty results and not-found ids. `AssemblyInfo.cs` turns off test parallelism, because existing tests write to the shared database.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Write ASP.NET Core integration tests with WebApplicationFactory for the Catalog API's endpoints, against a real Postgres started in the sandbox, covering paging, filters and not found. Run dotnet test and open a pull request.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

Tried on dotnet/eShop at 913acea: 3 files changed, 250 insertions(+), 5 deletions(-). On the untouched clone `timeout 580 dotnet test tests/Catalog.FunctionalTests` did not finish and exited 124. After the change, with `CATALOG_TEST_POSTGRES` set, the run ended `Test run summary: Passed!` with `succeeded: 65`, exit 0. That needed setup the repository does not provide: the agent installed the .NET 10.0.302 SDK from `global.json` and Postgres 15, and built pgvector 0.8.0 from source. No pull request was opened.

For the reviewer: whether the `CATALOG_TEST_POSTGRES` seam belongs in the fixture, since it exists so the tests run without Docker. The existing `AddCatalogItem` and `DeleteCatalogItem` tests use fixed ids, so a second run on the same database failed 4 tests; the passing run used a freshly dropped database.

## Run it on every night at 2 a.m. Pacific

The nightly tests automation has a `schedule` trigger on cron `0 2 * * *` in America/Los_Angeles, with this request as its prompt. Each night the run rebuilds its own Postgres with pgvector, since Aspire needs Docker, and reruns the Catalog functional suite with its new tests.

## Why run it on Rush?

The run caught behaviour it chose not to pin. A test it wrote expecting a 4xx for `pageIndex=-1` got 500 on both v1 and v2, and the run reports that `pageSize=0` returns 200 with an empty page. It removed that test rather than assert a 500, and reports both as missing validation for a separate change.

## Frequently asked questions

### Why not start Postgres through Aspire as the existing tests do?

Aspire starts Postgres in a Docker container, and the sandbox had none, so the untouched suite ran until the timeout. The fixture still uses Aspire whenever `CATALOG_TEST_POSTGRES` is unset.

### Does the external Postgres need anything special?

pgvector, which the Catalog migration needs. apt had no `postgresql-15-pgvector` package, so the agent built pgvector 0.8.0 from source for Postgres 15.

## More ASP.NET Core jobs

- [Write Unit Tests for an ASP.NET Core Project](https://getrush.ai/run/write-unit-tests/aspnet-core/)
- [Add API Versioning to an ASP.NET Core Web API](https://getrush.ai/run/add-api-versioning/aspnet-core/)
- [Add Test Coverage Reporting to ASP.NET Core CI](https://getrush.ai/run/add-coverage-to-ci/aspnet-core/)

## The same job on other stacks

- [Write Integration Tests for a Knex and Express API](https://getrush.ai/run/write-integration-tests/knex/)
- [Write Integration Tests for a Medusa Backend](https://getrush.ai/run/write-integration-tests/medusa/)
- [Write Integration Tests for a Reflex App](https://getrush.ai/run/write-integration-tests/reflex/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
