コード例 #1
0
        public async void Can_Response_Return_Same_Correlation_Id_When_Request_Header_Have_Correlation_Id()
        {
            var contextMock = new DefaultHttpContext();

            contextMock.Request.Headers.Add("testKey", "testValue");

            await _middleware.Invoke(contextMock);

            Assert.True(contextMock.Items.ContainsKey("CorrelationId"));
            Assert.Equal("testValue", contextMock.Items["CorrelationId"]?.ToString());

            _nextMock.Received(1);
        }
コード例 #2
0
        public async void Can_Pass_When_Header_ApiKey_Correct()
        {
            var contextFake = new DefaultHttpContext();

            contextFake.Request.Headers.Add("X-API-KEY", "test");

            await _middleware.Invoke(contextFake);

            _nextMock.Received(1);
            _loggerMock.Received(0).Log <Object>(Arg.Any <LogLevel>(), Arg.Is <EventId>(x => x.Id == LoggingEvents.Authentication), Arg.Any <Object>(), Arg.Any <Exception>(), Arg.Any <Func <Object, Exception, string> >());
        }
        public async Task InvokeAsync_ExecutesRequestDelegate()
        {
            // Arrange
            var context = new DefaultHttpContext();

            // Act
            await _sut.InvokeAsync(context);

            // Assert
            await _requestDelegate.Received(1).Invoke(context);
        }