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

            _mockInner
            .Setup(i => i.Remove(id))
            .Throws(expectedException);

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

            // Act
            Action action = () => subject.Remove(id);

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

            _mockInner.VerifyAll();
        }
        public void Remove_ShouldNotCatchException_WhenIdIsGiven_AndInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            const int id = 5;
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.Remove(id))
            .Throws(new Exception());

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

            // Act
            Action action = () => subject.Remove(id);

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

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

            _mockInner
            .Setup(i => i.Remove(entity))
            .Throws(expectedException);

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

            // Act
            subject.Remove(entity);

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

            _mockInner.Setup(i => i.Remove(id));

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

            // Act
            subject.Remove(id);

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