예제 #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());
        }