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

            _mockInner
            .Setup(i => i.GetCount())
            .Throws(expectedException);

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

            // Act
            Action action = () => subject.GetCount();

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

            _mockInner.VerifyAll();
        }
        public void GetCount_ShouldCallInner_AndReturnResult(bool handlerReturnValue)
        {
            // Arrange
            const long expectedResult = 123;
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCount())
            .Returns(expectedResult);

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

            // Act
            var actualResult = subject.GetCount();

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

            _mockInner.VerifyAll();
        }
        public void GetCount_ShouldInvokeHandler_AndReturnResult_WhenInnerThrowsException_AndHandlerReturnsTrue()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCount())
            .Throws(expectedException);

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

            // Act
            var actualResult = subject.GetCount();

            // Assert
            actualResult.Should().Be(default);
        public void GetCount_ShouldNotCatchException_WhenInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

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

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

            // Act
            Action action = () => subject.GetCount();

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

            _mockInner.VerifyAll();
        }