コード例 #1
0
        public async Task HandleExceptionsTestWithHandlerButNoExceptionWritesResponse()
        {
            // Act
            await ExceptionMiddlewareExtensions.HandleExceptions(_httpContext, _mockLogger.Object)
            .ConfigureAwait(false);

            // Assert
            await VerifyResponse().ConfigureAwait(false);

            _mockLogger.VerifyExact(LogLevel.Error, "Request failed.", Times.Once());
        }
コード例 #2
0
        public async Task HandleExceptionsTestNoExceptionHandlerWritesResponse()
        {
            // Arrange
            _httpContext.Features.Set <IExceptionHandlerFeature>(null);

            // Act
            await ExceptionMiddlewareExtensions.HandleExceptions(_httpContext, _mockLogger.Object)
            .ConfigureAwait(false);

            // Assert
            await VerifyResponse().ConfigureAwait(false);
        }
コード例 #3
0
        public async Task HandleExceptionsTestWithHandlerWithExceptionWritesResponse()
        {
            // Arrange
            var exMessage = "This is an exception";
            var exception = new System.Exception(exMessage);

            _mockExHandlerFeature.SetupGet(x => x.Error).Returns(exception);

            // Act
            await ExceptionMiddlewareExtensions.HandleExceptions(_httpContext, _mockLogger.Object)
            .ConfigureAwait(false);

            // Assert
            await VerifyResponse(exMessage).ConfigureAwait(false);

            _mockLogger.VerifyContains(LogLevel.Error, "Request failed.", Times.Once());
        }