public void TryRemove_ShouldCallInner_AndReturnResult_WhenIdIsGiven(bool handlerReturnValue)
        {
            // Arrange
            const int id             = 5;
            var       expectedResult = true;
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.TryRemove(id))
            .Returns(expectedResult);

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

            // Act
            var actualResult = subject.TryRemove(id);

            // Assert
            actualResult.Should().Be(expectedResult);
            actualException.Should().BeNull();

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

            _mockInner
            .Setup(i => i.TryRemove(entity))
            .Throws(new Exception());

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

            // Act
            Action action = () => subject.TryRemove(entity);

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

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

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

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

            // Act
            var actualResult = subject.TryRemove(entity);

            // Assert
            actualResult.Should().BeFalse();
            actualException.Should().BeSameAs(expectedException);

            _mockInner.VerifyAll();
        }
        public void TryRemove_ShouldInvokeHandler_AndRethrow_WhenIdIsGiven_AndInnerThrowsException_AndHandlerReturnsFalse()
        {
            // Arrange
            const int id = 5;
            var       expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

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

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

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

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

            _mockInner.VerifyAll();
        }