# Test Infrastructure Prerequisites

> Reference for step-07-tests.md — verify and scaffold test project before generating tests.

## 1. Verify Test Project Exists

```bash
# Look for existing test project
ls *Tests*/*.csproj 2>/dev/null || ls tests/*/*.csproj 2>/dev/null
```

If NO test project exists, create one:

```bash
dotnet new xunit -n {SolutionName}.Tests -o tests/{SolutionName}.Tests
dotnet sln add tests/{SolutionName}.Tests/{SolutionName}.Tests.csproj
```

## 2. Required NuGet Packages

| Package | Purpose |
|---------|---------|
| `xunit` | Test framework |
| `FluentAssertions` | Assertion library |
| `Moq` | Mocking framework |
| `Microsoft.AspNetCore.Mvc.Testing` | Integration test support |
| `Microsoft.EntityFrameworkCore.Sqlite` | SQLite in-memory for REAL integration tests |
| `Microsoft.Data.Sqlite` | SQLite connection support |
| `Microsoft.EntityFrameworkCore.InMemory` | In-memory DB for repository tests |
| `FluentValidation.TestHelper` | Validator testing support |

```bash
cd tests/{SolutionName}.Tests
dotnet add package FluentAssertions
dotnet add package Moq
dotnet add package Microsoft.AspNetCore.Mvc.Testing
dotnet add package Microsoft.EntityFrameworkCore.Sqlite
dotnet add package Microsoft.Data.Sqlite
dotnet add package Microsoft.EntityFrameworkCore.InMemory
dotnet add package FluentValidation.TestHelper
```

## 3. Project References

The test project MUST reference the API project (for WebApplicationFactory):

```bash
cd tests/{SolutionName}.Tests
dotnet add reference ../../src/{SolutionName}.Api/{SolutionName}.Api.csproj
dotnet add reference ../../src/{SolutionName}.Application/{SolutionName}.Application.csproj
dotnet add reference ../../src/{SolutionName}.Domain/{SolutionName}.Domain.csproj
dotnet add reference ../../src/{SolutionName}.Infrastructure/{SolutionName}.Infrastructure.csproj
```

## 4. Program.cs Accessibility (BLOCKING)

The API project's `Program` class must be accessible for `WebApplicationFactory<Program>`.

Check if `Program.cs` ends with `public partial class Program { }`. If not, add it:

```csharp
// At the very end of Program.cs
public partial class Program { }
```

**Alternatively**, add to the API `.csproj`:

```xml
<ItemGroup>
  <InternalsVisibleTo Include="{SolutionName}.Tests" />
</ItemGroup>
```
