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

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

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
예제 #2
0
        public void RemoveAsync_ShouldSkipTap_WhenLoggerIsGiven_AndIdIsGiven_AndInnerThrowsException()
        {
            // Arrange
            const int id = 7;

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

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

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

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockTap.VerifyAll();
        }
예제 #3
0
        public async Task RemoveAsync_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndIdIsGiven()
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(r => r.RemoveAsync(id))
            .Returns(TaskHelpers.CompletedTask);
            _mockTap
            .Setup(r => r.RemoveAsync(id))
            .Returns(TaskHelpers.CompletedTask);

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

            // Act
            await subject.RemoveAsync(id).ConfigureAwait(false);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
예제 #4
0
        public async Task RemoveAsync_ShouldDoNothing_WhenIdIsGiven_AndTapThrowsException()
        {
            // Arrange
            const int id = 7;

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

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

            // Act
            await subject.RemoveAsync(id).ConfigureAwait(false);

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

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

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

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

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