コード例 #1
0
        public void Commit_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

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

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

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

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

            _mockInner.VerifyAll();
        }
コード例 #2
0
        public void Commit_ShouldCallInner(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

            _mockInner.Setup(i => i.Commit());

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

            // Act
            subject.Commit();

            // Assert
            actualException.Should().BeNull();
            _mockInner.VerifyAll();
        }
コード例 #3
0
        public void Commit_ShouldNotCatchException_WhenInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

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

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

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

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

            _mockInner.VerifyAll();
        }