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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }