DockerTests
Docker intergration tests sample
Install / Use
/learn @alex1ozr/DockerTestsREADME
About project
Sample of Web API and tests with Database in Docker, along with "build as code" using Nuke Build.
Key features:
- [x] ASP.NET Core 9.0
- [x] Entity Framework Core 9.0 & PostgreSQL 17
- [x] Build solution using Nuke build
- [x] Dockerfile automatic generation support using Scriban
- [x] API client generation using NSwag
- [x] Integration tests with Docker using TestContainers and Respawn
- [x] .NET Aspire standalone Dashboard
- [x] Docker Compose to run all prerequisites (PostgreSQL, .NET Aspire Dashboard)
- [x] Logging, Metrics, Tracing using OpenTelemetry
Prerequisites
Main
Running API
In order to run the API, you need to have a PostgreSQL database running. You can use the provided Docker Compose file to run it.
List of services:
- PostgreSQL:
localhost:5432 - Aspire Dashboard:
http://localhost:18888
Projects to start
API
Starts the HTTP-server
Tests
Execute all tests
dotnet test
Execute only integration tests
dotnet test --filter Category=IntegrationTests
Create Db Context migrations
#Install EF utils
dotnet tool install --global dotnet-ef
#Create schema migration
dotnet ef migrations add <Name of your migration> --startup-project src/Api -p src/Store -c PopulationDbContext
Build solution using Nuke build
Install the global tool
dotnet tool install Nuke.GlobalTool --global
Run build
Using a global tool
nuke
Using a PowerShell script
Execute from the root of the repository
pwsh build.ps1 -DockerRepositoriesUrl https://some.docker.registry -Branch some-dev-branch -BuildCounter 1 -DockerRepositoryName some-docker-repo-name -NuGetUrl https://some.nuget.registry -NuGetFeedName some-nuget-feed-name -NuGetApiKey some-nuget-api-key
Execution plan
Execute the following command to see the interactive execution plan
nuke --plan

API Client
API client is generated using NSwag tool.
It generates automatically when ClientGenerator project is built.
See more details in NSwag documentation and nswag.json file.
