public async Task Should_return_null_response_if_exception_was_caught( Exception exception) { var logger = Substitute.For <IInternalLogger>(); async Task <Verdict> DoRequest() { return(await Task.FromException <Verdict>(exception)); } var result = await ExceptionGuard.Try(DoRequest, logger); result.Should().BeNull(); }
public async Task Should_not_rethrow_non_external_exceptions( Exception exception) { var logger = Substitute.For <IInternalLogger>(); async Task <Verdict> DoRequest() { return(await Task.FromException <Verdict>(exception)); } Func <Task> act = async() => await ExceptionGuard.Try(DoRequest, logger); await act.Should().NotThrowAsync <Exception>(); }
public async Task Should_log_exceptions_as_errors( Exception exception) { var logger = Substitute.For <IInternalLogger>(); async Task <Verdict> DoRequest() { return(await Task.FromException <Verdict>(exception)); } await ExceptionGuard.Try(DoRequest, logger); logger.Received().Error(exception.ToString); }
public async Task Should_return_request_response_if_no_exception_is_thrown( Verdict response) { var logger = Substitute.For <IInternalLogger>(); async Task <Verdict> DoRequest() { return(await Task.FromResult(response)); } var result = await ExceptionGuard.Try(DoRequest, logger); result.Should().Be(response); }
private async Task <T> TryRequest <T>(Func <Task <T> > request) where T : class { return(await ExceptionGuard.Try(request, _logger)); }