public void TryUpdate_ShouldLogException_WhenLoggerIsGiven_AndTapThrowsException() { // Arrange var person = new FakeEntity <int> { Id = 7, Name = "Tiffany" }; _mockInner .Setup(u => u.TryUpdate(person)) .Returns(true); _mockTap .Setup(u => u.AddOrUpdate(person)) .Throws(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 CommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object, _mockLogger.Object); // Act var result = subject.TryUpdate(person); // Assert result.Should().BeTrue(); _mockInner.VerifyAll(); _mockTap.VerifyAll(); _mockLogger.VerifyAll(); }
public void TryUpdate_ShouldDoNothing_WhenTapThrowsException() { // Arrange var person = new FakeEntity <int> { Id = 7, Name = "Tiffany" }; _mockInner .Setup(u => u.TryUpdate(person)) .Returns(true); _mockTap .Setup(u => u.AddOrUpdate(person)) .Throws(new InvalidOperationException()); var subject = new CommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object); // Act var result = subject.TryUpdate(person); // Assert result.Should().BeTrue(); _mockInner.VerifyAll(); _mockTap.VerifyAll(); _mockLogger.VerifyAll(); }
public void TryUpdate_ShouldSkipTap_WhenInnerThrowsException() { // Arrange var person = new FakeEntity <int> { Id = 7, Name = "Tiffany" }; _mockInner .Setup(u => u.TryUpdate(person)) .Throws(new InvalidOperationException()); var subject = new CommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object); // Act Action action = () => subject.TryUpdate(person); // Assert action.Should().Throw <InvalidOperationException>(); _mockInner.VerifyAll(); _mockTap.VerifyAll(); _mockLogger.VerifyAll(); }
public void TryUpdate_ShouldSkipTap_WhenInnerReturnsFalse() { // Arrange var person = new FakeEntity <int> { Id = 7, Name = "Tiffany" }; _mockInner .Setup(u => u.TryUpdate(person)) .Returns(false); var subject = new CommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object); // Act var result = subject.TryUpdate(person); // Assert result.Should().BeFalse(); _mockInner.VerifyAll(); _mockTap.VerifyAll(); _mockLogger.VerifyAll(); }
public void TryUpdate_ShouldCallInner_AndTap() { // Arrange var person = new FakeEntity <int> { Id = 7, Name = "Tiffany" }; _mockInner .Setup(u => u.TryUpdate(person)) .Returns(true); _mockTap.Setup(u => u.AddOrUpdate(person)); var subject = new CommandServiceTap <FakeEntity <int>, int>(_mockInner.Object, _mockTap.Object); // Act var result = subject.TryUpdate(person); // Assert result.Should().BeTrue(); _mockInner.VerifyAll(); _mockTap.VerifyAll(); _mockLogger.VerifyAll(); }