dotnet-testing-advanced-webapi-integration-testing_skill

This skill helps you build advanced WebApi integration tests using WebApplicationFactory, ProblemDetails validation, and multi-container test environments.
  • C#

19

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill kevintsengtw/dotnet-testing-agent-skills --skill dotnet-testing-advanced-webapi-integration-testing

  • SKILL.md15.2 KB

Overview

This skill is an advanced, practical guide for ASP.NET Core WebApi integration testing focused on end-to-end scenarios and standardized error verification. It documents how to build a repeatable test infrastructure using WebApplicationFactory, Testcontainers multi-container setups, Flurl for URL building, and AwesomeAssertions for precise HTTP response checks. The content emphasizes validating ProblemDetails and ValidationProblemDetails formats and modern IExceptionHandler-based error handling.

How this skill works

The skill shows how to create a TestWebApplicationFactory that orchestrates PostgreSQL and Redis containers, replaces services like a TimeProvider, and configures the app for a Testing environment. Tests use a Collection Fixture to share the factory, an IntegrationTestBase for common setup/teardown, Flurl to construct request URLs, and AwesomeAssertions to assert HTTP status codes and deserialized ProblemDetails payloads. It also explains implementing IExceptionHandler handlers (including FluentValidation) to produce RFC7807-compliant error responses.

When to use it

  • When you need reliable end-to-end integration tests for ASP.NET Core WebApi endpoints
  • When verifying API error formats (ProblemDetails / ValidationProblemDetails) and status codes
  • When tests require dependent services like PostgreSQL and Redis in isolated containers
  • When you want to assert HTTP responses and response bodies with expressive assertions
  • When simulating time-sensitive behavior using a replaceable TimeProvider

Best practices

  • Keep each test focused: follow Arrange, Act, Assert and one responsibility per test
  • Register specialized exception handlers (e.g., FluentValidation) before generic handlers
  • Share container resources via Collection Fixture to reduce startup overhead
  • Clean or reset database state between tests (use Respawn or database cleanup scripts)
  • Use Flurl for readable query construction and AwesomeAssertions for precise HTTP checks

Example use cases

  • CreateProduct test that asserts 201 Created and validates returned product DTO
  • Validation error test that asserts 400 BadRequest with ValidationProblemDetails errors
  • GetById test that asserts 404 NotFound with ProblemDetails describing missing resource
  • Paged query test using Flurl to build query string and asserting PagedResult structure
  • Multi-container integration test where PostgreSQL and Redis are started for the suite

FAQ

Yes. Testcontainers starts containers via Docker, so a working Docker environment is required on the CI or local machine.

How do I assert ProblemDetails payloads?

Deserialize the response to ProblemDetails or ValidationProblemDetails and use AwesomeAssertions to assert Type, Title, Status, Detail and Errors keys.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
dotnet-testing-advanced-webapi-integration-testing skill by kevintsengtw/dotnet-testing-agent-skills | VeilStrat