Esempio n. 1
0
        public async Task TryUpdateAsync_ShouldCallInner_AndTap()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };
            var expectedResult = true;

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

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

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

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
Esempio n. 2
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();
        }
Esempio n. 3
0
        public async Task TryAddAsync_ShouldLogException_WhenLoggerIsGiven_AndTapThrowsException()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };
            var expectedResult = true;

            _mockInner
            .Setup(u => u.TryAddAsync(entity))
            .ReturnsAsync(expectedResult);
            _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
            var actualResult = await subject.TryAddAsync(entity).ConfigureAwait(false);

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
Esempio n. 4
0
        public async Task TryAddAsync_ShouldDoNothing_WhenTapThrowsException()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };
            var expectedResult = true;

            _mockInner
            .Setup(u => u.TryAddAsync(entity))
            .ReturnsAsync(expectedResult);
            _mockTap
            .Setup(u => u.AddOrUpdateAsync(entity))
            .ThrowsAsync(new InvalidOperationException());

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

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

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
Esempio n. 5
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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
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();
        }
Esempio n. 8
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();
        }
Esempio n. 9
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();
        }
Esempio n. 10
0
        public void TryUpdateAsync_ShouldSkipTap_WhenInnerThrowsException()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

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

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

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

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockTap.VerifyAll();
        }
Esempio n. 11
0
        public async Task AddAsync_ShouldDoNothing_WhenTapThrowsException()
        {
            // Arrange
            var entity = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.AddAsync(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.AddAsync(entity).ConfigureAwait(false);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
Esempio n. 12
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();
        }
Esempio n. 13
0
        public async Task TryRemoveAsync_ShouldDoNothing_WhenIdIsGiven_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());

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

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

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

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