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

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

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

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

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

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

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

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

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

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

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

            _mockInner
            .Setup(i => i.TryUpdate(entity))
            .Returns(expectedResult);

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

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

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

            _mockInner.VerifyAll();
        }