public async Task HandleThrowsNullReferenceOnNullContext() { // arrange var options = new StubHttpLogOptions(); var handler = new DefaultHttpMessageLogTraceIdHandler(options); // act and assert await Assert.ThrowsAsync <NullReferenceException>(() => handler.Handle(null, null).AsTask()); }
public async Task HandleSetsTraceIdHeaderInResponse() { // arrange var options = new StubHttpLogOptions(); var context = new DefaultHttpContext(); var logMessage = new HttpMessageLog(); var handler = new DefaultHttpMessageLogTraceIdHandler(options); // act await handler.Handle(context, logMessage); // assert Assert.Equal(context.Response.Headers[options.Value.TraceIdHeaderName], logMessage.TraceId); }
public async Task HandleInitializeTraceId() { // arrange var options = new StubHttpLogOptions(); var context = new DefaultHttpContext(); var logMessage = new HttpMessageLog(); var handler = new DefaultHttpMessageLogTraceIdHandler(options); // act await handler.Handle(context, logMessage); // assert Assert.Equal(context.TraceIdentifier, logMessage.TraceId); }
public async Task HandleDoesNotSetsTraceIdHeaderWhenResponseHasStarted() { // arrange var options = new StubHttpLogOptions(); var context = new DefaultHttpContext(); var logMessage = new HttpMessageLog(); var handler = new DefaultHttpMessageLogTraceIdHandler(options); context.Features.Set <IHttpResponseFeature>(new StartedResponseFeature()); // act await handler.Handle(context, logMessage); // assert Assert.Empty(context.Response.Headers[options.Value.TraceIdHeaderName]); }