public async Task GivenAnInternalServerException_WhenMiddlewareIsExecuted_ThenMessageShouldBeOverwritten() { ExceptionHandlingMiddleware baseExceptionMiddleware = CreateExceptionHandlingMiddleware(innerHttpContext => throw new Exception("Unhandled exception.")); baseExceptionMiddleware.ExecuteResultAsync(Arg.Any <HttpContext>(), Arg.Any <IActionResult>()).Returns(Task.CompletedTask); await baseExceptionMiddleware.Invoke(_context); await baseExceptionMiddleware .Received() .ExecuteResultAsync( Arg.Any <HttpContext>(), Arg.Is <ContentResult>(x => x.Content == DicomApiResource.InternalServerError)); }
public async Task GivenAnException_WhenMiddlewareIsExecuted_ThenCorrectStatusCodeShouldBeRetruned(Exception exception, HttpStatusCode expectedStatusCode) { ExceptionHandlingMiddleware baseExceptionMiddleware = CreateExceptionHandlingMiddleware(innerHttpContext => throw exception); baseExceptionMiddleware.ExecuteResultAsync(Arg.Any <HttpContext>(), Arg.Any <IActionResult>()).Returns(Task.CompletedTask); await baseExceptionMiddleware.Invoke(_context); await baseExceptionMiddleware .Received() .ExecuteResultAsync( Arg.Any <HttpContext>(), Arg.Is <ContentResult>(x => x.StatusCode == (int)expectedStatusCode)); }