コード例 #1
0
        public void TryAdd_ShouldLogException_WhenLoggerIsGiven_AndTapThrowsException()
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.TryAdd(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.TryAdd(person);

            // Assert
            result.Should().BeTrue();

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #2
0
        public void TryRemove_ShouldLogException_WhenLoggerIsGiven_AndIdIsGiven_AndTapThrowsException(bool expected)
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(u => u.TryRemove(id))
            .Returns(expected);
            _mockTap
            .Setup(u => u.Remove(id))
            .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.TryRemove(id);

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #3
0
        public void TryAdd_ShouldDoNothing_WhenTapThrowsException()
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.TryAdd(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.TryAdd(person);

            // Assert
            result.Should().BeTrue();

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #4
0
        public void TryRemove_ShouldDoNothing_WhenEntityIsGiven_AndTapThrowsException(bool expected)
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.TryRemove(person))
            .Returns(expected);
            _mockTap
            .Setup(u => u.Remove(person))
            .Throws(new InvalidOperationException());

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

            // Act
            var result = subject.TryRemove(person);

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #5
0
        public void Remove_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndIdIsGiven()
        {
            // Arrange
            const int id = 7;

            _mockInner.Setup(u => u.Remove(id));
            _mockTap.Setup(u => u.Remove(id));

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

            // Act
            subject.Remove(id);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #6
0
        public void Remove_ShouldDoNothing_WhenIdIsGiven_AndTapThrowsException()
        {
            // Arrange
            const int id = 7;

            _mockInner.Setup(u => u.Remove(id));
            _mockTap
            .Setup(u => u.Remove(id))
            .Throws(new InvalidOperationException());

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

            // Act
            subject.Remove(id);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #7
0
        public void Remove_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndEntityIsGiven()
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner.Setup(u => u.Remove(person));
            _mockTap.Setup(u => u.Remove(person));

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

            // Act
            subject.Remove(person);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #8
0
        public void Add_ShouldCallInner_AndTap()
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner.Setup(u => u.Add(person));
            _mockTap.Setup(u => u.AddOrUpdate(person));

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

            // Act
            subject.Add(person);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #9
0
        public void Remove_ShouldSkipTap_WhenLoggerIsGiven_AndIdIsGiven_AndInnerThrowsException()
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(u => u.Remove(id))
            .Throws(new InvalidOperationException());

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

            // Act
            Action action = () => subject.Remove(id);

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #10
0
        public void TryRemove_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndIdIsGiven(bool expected)
        {
            // Arrange
            const int id = 7;

            _mockInner
            .Setup(u => u.TryRemove(id))
            .Returns(expected);
            _mockTap.Setup(u => u.Remove(id));

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

            // Act
            var result = subject.TryRemove(id);

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

            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #11
0
        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();
        }
コード例 #12
0
        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();
        }
コード例 #13
0
        public void Remove_ShouldLogException_WhenLoggerIsGiven_AndEntityIsGiven_AndTapThrowsException()
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner.Setup(u => u.Remove(person));
            _mockTap
            .Setup(u => u.Remove(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
            subject.Remove(person);

            // Assert
            _mockInner.VerifyAll();
            _mockTap.VerifyAll();
            _mockLogger.VerifyAll();
        }
コード例 #14
0
        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();
        }
コード例 #15
0
        public void TryRemove_ShouldCallInner_AndTap_WhenLoggerIsGiven_AndEntityIsGiven(bool expected)
        {
            // Arrange
            var person = new FakeEntity <int> {
                Id = 7, Name = "Tiffany"
            };

            _mockInner
            .Setup(u => u.TryRemove(person))
            .Returns(expected);
            _mockTap.Setup(u => u.Remove(person));

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

            // Act
            var result = subject.TryRemove(person);

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

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