Beispiel #1
0
        public void GetCountAsync_ShouldInvokeHandler_AndRethrow_WhenInnerThrowsException_AndHandlerReturnsFalse()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCountAsync())
            .ThrowsAsync(expectedException);

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

            // Act
            Func <Task> action = async() => await subject.GetCountAsync().ConfigureAwait(false);

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

            _mockInner.VerifyAll();
        }
Beispiel #2
0
        public async Task GetCountAsync_ShouldCallInner_AndReturnResult(bool handlerReturnValue)
        {
            // Arrange
            const long expectedResult = 123;
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCountAsync())
            .ReturnsAsync(expectedResult);

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

            // Act
            var actualResult = await subject.GetCountAsync().ConfigureAwait(false);

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

            _mockInner.VerifyAll();
        }
Beispiel #3
0
        public async Task GetCountAsync_ShouldInvokeHandler_AndReturnResult_WhenInnerThrowsException_AndHandlerReturnsTrue()
        {
            // Arrange
            var expectedException = new InvalidOperationException();
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCountAsync())
            .ThrowsAsync(expectedException);

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

            // Act
            var actualResult = await subject.GetCountAsync().ConfigureAwait(false);

            // Assert
            actualResult.Should().Be(default);
Beispiel #4
0
        public void GetCountAsync_ShouldNotCatchException_WhenInnerThrowsException_AndTypeIsWrong(bool handlerReturnValue)
        {
            // Arrange
            InvalidOperationException actualException = null;

            _mockInner
            .Setup(i => i.GetCountAsync())
            .ThrowsAsync(new Exception());

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

            // Act
            Func <Task> action = async() => await subject.GetCountAsync().ConfigureAwait(false);

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

            _mockInner.VerifyAll();
        }