Example #1
0
        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();
        }
Example #2
0
        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>();
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
 private async Task <T> TryRequest <T>(Func <Task <T> > request)
     where T : class
 {
     return(await ExceptionGuard.Try(request, _logger));
 }