Example #1
0
        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());
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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]);
        }