Reusable integration-test helpers for SimpleModule applications.
TestAuthHandler— header-based test auth handler that turns a semicolon-separated list oftype=valueclaims into an authenticatedClaimsPrincipal.TestAuthDefaults— scheme name (TestScheme) and header name (X-Test-Claims) constants.services.AddTestAuthentication()— registers the handler as the default authenticate/challenge scheme.factory.CreateAuthenticatedClient(params Claim[])andfactory.CreateAuthenticatedClient(string[] permissions, params Claim[])extensions onWebApplicationFactory<TEntryPoint>that produce HTTP clients with the appropriateX-Test-Claimsheader.
using SimpleModule.Testing;
public sealed class MyAppFactory : WebApplicationFactory<Program>
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
builder.ConfigureServices(services =>
{
services.AddTestAuthentication();
});
}
}
public sealed class MyEndpointTests(MyAppFactory factory) : IClassFixture<MyAppFactory>
{
[Fact]
public async Task Authenticated_request_succeeds()
{
var client = factory.CreateAuthenticatedClient(
new Claim("permission", "Things.View")
);
var response = await client.GetAsync("/api/things");
response.EnsureSuccessStatusCode();
}
}This package is intentionally narrow: it ships only the auth-related plumbing.
Wire your own WebApplicationFactory for module-specific setup (DB swap,
hosted-service removal, etc.).
MIT