public void RemoveAsync_ShouldInvokeHandler_AndRethrow_WhenIdIsGiven_AndInnerThrowsException_AndHandlerReturnsFalse()
        {
            // Arrange
            const int id = 5;
            var       expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.RemoveAsync(id))
            .ThrowsAsync(expectedException);

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

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

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

            _mockInner.VerifyAll();
        }
        public async Task RemoveAsync_ShouldInvokeHandler_WhenEntityIsGiven_AndInnerThrowsException_AndHandlerReturnsTrue()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 5
            };
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.RemoveAsync(entity))
            .ThrowsAsync(expectedException);

            var subject = new AsyncCommandServiceExceptionHandler <FakeEntity <int>, int, InvalidOperationException>(_mockInner.Object, ex =>
            {
                actualException = ex;
                return(true);
            });

            // Act
            await subject.RemoveAsync(entity).ConfigureAwait(false);

            // Assert
            actualException.Should().BeSameAs(expectedException);
            _mockInner.VerifyAll();
        }
        public void RemoveAsync_ShouldNotCatchException_WhenIdIsGiven_AndInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            const int id = 5;
            InvalidOperationException actualException = null;

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

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

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

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

            _mockInner.VerifyAll();
        }
        public async Task RemoveAsync_ShouldCallInner_WhenEntityIsGiven(bool handlerReturnValue)
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 5
            };
            InvalidOperationException actualException = null;

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

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

            // Act
            await subject.RemoveAsync(entity).ConfigureAwait(false);

            // Assert
            actualException.Should().BeNull();
            _mockInner.VerifyAll();
        }