원클릭으로
aspire-integration-testing
Patterns for integration testing Aspire-hosted .NET services with WebApplicationFactory, Testcontainers, and SQLite
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Patterns for integration testing Aspire-hosted .NET services with WebApplicationFactory, Testcontainers, and SQLite
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Full-stack acceptance testing with Aspire.Hosting.Testing — launching entire AppHost including containers
How to wire up .NET Aspire 13.1 AppHost with containers, databases, and service projects
Pattern for hosting Discord.NET bot inside a .NET generic host BackgroundService
Patterns for setting up a .NET CI pipeline with GitHub Actions and xUnit test projects
| name | aspire-integration-testing |
| description | Patterns for integration testing Aspire-hosted .NET services with WebApplicationFactory, Testcontainers, and SQLite |
| domain | testing |
| confidence | medium |
| source | earned |
When writing integration tests for .NET Aspire services that use AddNpgsqlDbContext and AddRedisClient (or similar Aspire component methods). Applies to any service using Aspire 13.x with PostgreSQL + Redis.
WebApplicationFactory<Program> to host the service under test — avoids Aspire AppHost orchestration in testsAddNpgsqlDbContext, AddRedisClient) validate connection strings at registration time — provide fake connection strings via builder.UseSetting("ConnectionStrings:name", "...") in ConfigureWebHostFullName containing "EntityFramework", "Npgsql", "DbContext") then re-registering with AddDbContext<T>(o => o.UseSqlite(...))Cache=Shared requires a keep-alive SqliteConnection that stays open for the entire fixture lifetimeEnsureCreatedAsync() during fixture initialization, before the host startsISubscriber.OnMessage callbacks is brittleIAsyncLifetime on the factory class for container lifecycle (note: xUnit IAsyncLifetime uses Task, not ValueTask)IClassFixture<BridgeApiFactory> to share the factory across tests in a class — avoids container churn// Keep-alive connection pattern for SQLite in-memory
private SqliteConnection _keepAlive = null!;
_keepAlive = new SqliteConnection(connStr);
await _keepAlive.OpenAsync();
// ... in DisposeAsync: await _keepAlive.DisposeAsync();
// Removing Aspire-registered services
var toRemove = services.Where(d => {
var st = d.ServiceType.FullName ?? "";
return st.Contains("EntityFramework", OrdinalIgnoreCase)
|| st.Contains("Npgsql", OrdinalIgnoreCase)
|| st.Contains("DbContext", OrdinalIgnoreCase);
}).ToList();
foreach (var d in toRemove) services.Remove(d);
// Provider-agnostic Max query (works on both Npgsql and SQLite)
var maxIndex = await db.Items.Select(x => (int?)x.Index).MaxAsync();
var nextIndex = (maxIndex ?? -1) + 1;
DefaultIfEmpty(value).MaxAsync() — SQLite provider can't translate itBuildServiceProvider() inside ConfigureServices to call EnsureCreated() — it creates a separate DI container with stale registrations