Test-friendly implementation of IHttpCorrelationIdProvider with predictable correlation ID generation.
This package provides a deterministic correlation ID provider specifically designed for testing scenarios. It generates predictable, sequential correlation IDs that make test assertions easier and test output more readable.
- Predictable IDs: Generates sequential, deterministic correlation IDs
- Test-Friendly: Simplifies test assertions and debugging
- Configurable Format: Customize ID format and prefix
- Reset Capability: Reset counter between test runs
- Multi-Framework Support: Compatible with .NET 8.0, 9.0, and 10.0
dotnet add package NetEvolve.Http.Correlation.TestGeneratorConfigure services to use test correlation IDs in your test setup:
using NetEvolve.Http.Correlation;
using Microsoft.AspNetCore.Mvc.Testing;
public class IntegrationTests : IClassFixture<WebApplicationFactory<Program>>
{
private readonly WebApplicationFactory<Program> _factory;
public IntegrationTests(WebApplicationFactory<Program> factory)
{
_factory = factory.WithWebHostBuilder(builder =>
{
builder.ConfigureServices(services =>
{
services
.AddHttpCorrelation()
.WithTestGenerator(); // Use test provider
});
});
}
[Fact]
public async Task Request_ShouldHaveCorrelationId()
{
// Arrange
var client = _factory.CreateClient();
// Act
var response = await client.GetAsync("/api/data");
// Assert
response.Headers.Should().Contain(h =>
h.Key == "X-Correlation-ID" &&
h.Value.First() == "test-00000001");
}
}Configure custom test ID:
services
.AddHttpCorrelation()
.WithTestGenerator("my-custom-test-id");
// Always generates: my-custom-test-idDefault: Generated_Test_Id
Custom example:
.WithTestGenerator("my-test-123")
// Always generates: my-test-123- Integration Tests: Verify correlation ID flow through the system
- Unit Tests: Mock correlation ID behavior with predictable values
- E2E Tests: Trace requests with readable correlation IDs
- Debug Sessions: Identify test requests in logs
- NetEvolve.Http.Correlation.Abstractions - Core abstractions and interfaces
- NetEvolve.Http.Correlation.AspNetCore - ASP.NET Core middleware and services
- NetEvolve.Http.Correlation.HttpClient - HTTP client correlation forwarding
- NetEvolve.Http.Correlation.Ulid - ULID-based provider for production
NetEvolve.Http.Correlation.Abstractions
Licensed under the MIT License. See LICENSE for details.