示例#1
0
        public async Task TryRemoveAsync_ShouldLogException_WhenLoggerIsGiven_AndIdIsGiven_AndTapThrowsException(bool expected)
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(u => u.TryRemoveAsync(id))
            .Returns(Task.FromResult(expected));
            _mockTap
            .Setup(u => u.RemoveAsync(id))
            .ThrowsAsync(new InvalidOperationException());
            _mockLogger.Setup(l => l.Log(LogLevel.Warning, 0, It.IsAny <object>(), It.IsAny <InvalidOperationException>(), It.IsAny <Func <object, Exception, string> >()));

            var subject = new AsyncCommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object, _mockLogger.Object);

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

            // Assert
            actualResult.Should().Be(expected);

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
示例#2
0
        public async Task TryRemoveAsync_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndEntityIsGiven(bool expected)
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(r => r.TryRemoveAsync(entity))
            .Returns(Task.FromResult(expected));
            _mockTap
            .Setup(r => r.RemoveAsync(entity))
            .Returns(TaskHelpers.CompletedTask);

            var subject = new AsyncCommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object, _mockLogger.Object);

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

            // Assert
            actualResult.Should().Be(expected);

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
示例#3
0
        public async Task TryRemoveAsync_ShouldDoNothing_WhenEntityIsGiven_AndTapThrowsException(bool expected)
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.TryRemoveAsync(entity))
            .Returns(Task.FromResult(expected));
            _mockTap
            .Setup(u => u.RemoveAsync(entity))
            .ThrowsAsync(new InvalidOperationException());

            var subject = new AsyncCommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object);

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

            // Assert
            actualResult.Should().Be(expected);

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
示例#4
0
        public void TryRemoveAsync_ShouldSkipTap_WhenLoggerIsGiven_AndIdIsGiven_AndInnerThrowsException()
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(r => r.TryRemoveAsync(id))
            .ThrowsAsync(new InvalidOperationException());

            var subject = new AsyncCommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object, _mockLogger.Object);

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

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockTap.VerifyAll();
        }