示例#1
0
        public async Task AddOrUpdateAsync_ShouldLogException_WhenLoggerIsGiven_AndTapThrowsException()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.AddOrUpdateAsync(entity))
            .Returns(TaskHelpers.CompletedTask);
            _mockTap
            .Setup(u => u.AddOrUpdateAsync(entity))
            .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
            await subject.AddOrUpdateAsync(entity).ConfigureAwait(false);

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

            _mockInner
            .Setup(r => r.AddOrUpdateAsync(entity))
            .ThrowsAsync(new InvalidOperationException());

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

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

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

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

            _mockInner
            .Setup(r => r.AddOrUpdateAsync(entity))
            .Returns(TaskHelpers.CompletedTask);
            _mockTap
            .Setup(r => r.AddOrUpdateAsync(entity))
            .Returns(TaskHelpers.CompletedTask);

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

            // Act
            await subject.AddOrUpdateAsync(entity).ConfigureAwait(false);

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

            _mockInner
            .Setup(u => u.AddOrUpdateAsync(entity))
            .Returns(TaskHelpers.CompletedTask);
            _mockTap
            .Setup(u => u.AddOrUpdateAsync(entity))
            .ThrowsAsync(new InvalidOperationException());

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

            // Act
            await subject.AddOrUpdateAsync(entity).ConfigureAwait(false);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }