public async Task Emits_WhenKeepingIncomingHeaderButCorrelationIdGenerated_ExpectCorrelationIdEmittedWithPredefinedHeader() { // arrange var headerName = "X-Incoming-Request-Id"; var options = CreateEmitOptions(PropagationSettings.KeepIncomingHeaderName(headerName)); var httpContext = new DefaultHttpContext(); var correlationContext = new GeneratedCorrelationContext(CorrelationId.FromString("123")); // act var emitter = new CorrelationEmitter(options, _logger); await emitter .Emit(httpContext, correlationContext) .ConfigureAwait(false); // assert Assert.Contains(headerName, httpContext.Response.Headers); Assert.Equal("123", httpContext.Response.Headers[headerName].ToString()); }
public async Task Emits_WhenNoEmit_ExpectNoCorrelationIdEmitted() { // arrange var incomingHeader = HttpHeaders.AspNetRequestId; var options = CreateEmitOptions(PropagationSettings.NoPropagation); var httpContext = new DefaultHttpContext(); var correlationContext = new RequestCorrelationContext( CorrelationId.FromString("123"), incomingHeader); // act var emitter = new CorrelationEmitter(options, _logger); await emitter .Emit(httpContext, correlationContext) .ConfigureAwait(false); // assert Assert.DoesNotContain(incomingHeader, httpContext.Response.Headers); }
public async Task Emits_WhenEmmitingUsingCustomHeader_ExpectCorrelationIdEmittedWithPredefinedHeader() { // arrange var incomingHeader = HttpHeaders.AspNetRequestId; var outgoingHeader = "X-Le-Custom-Request-Id"; var options = CreateEmitOptions(PropagationSettings.PropagateAs(outgoingHeader)); var httpContext = new DefaultHttpContext(); var correlationContext = new RequestCorrelationContext( CorrelationId.FromString("123"), incomingHeader); // act var emitter = new CorrelationEmitter(options, _logger); await emitter .Emit(httpContext, correlationContext) .ConfigureAwait(false); // assert Assert.Contains(outgoingHeader, httpContext.Response.Headers); Assert.Equal("123", httpContext.Response.Headers[outgoingHeader]); }