public void CommitAsync_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.CommitAsync())
            .ThrowsAsync(expectedException);

            var subject = new AsyncUnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex =>
            {
                actualException = ex;
                return(false);
            });

            // Act
            Func <Task> action = async() => await subject.CommitAsync().ConfigureAwait(false);

            // Assert
            action.Should().Throw <InvalidOperationException>();
            actualException.Should().BeSameAs(expectedException);

            _mockInner.VerifyAll();
        }
        public async Task CommitAsync_ShouldCallInner(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.CommitAsync())
            .Returns(TaskHelpers.CompletedTask);

            var subject = new AsyncUnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex =>
            {
                actualException = ex;
                return(handlerReturnValue);
            });

            // Act
            await subject.CommitAsync().ConfigureAwait(false);

            // Assert
            actualException.Should().BeNull();
            _mockInner.VerifyAll();
        }
        public void CommitAsync_ShouldNotCatchException_WhenInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.CommitAsync())
            .ThrowsAsync(new Exception());

            var subject = new AsyncUnitOfWorkExceptionHandler <InvalidOperationException>(_mockInner.Object, ex =>
            {
                actualException = ex;
                return(handlerReturnValue);
            });

            // Act
            Func <Task> action = async() => await subject.CommitAsync().ConfigureAwait(false);

            // Assert
            action.Should().Throw <Exception>();
            actualException.Should().BeNull();

            _mockInner.VerifyAll();
        }