Ejemplo n.º 1
0
        public void Get_ShouldPass_UnexpectedException()
        {
            // Arrange
            _origin.When(x => x.Get()).Do(_ => throw new Exception());
            ((IThrowsExpectedExceptions)_origin).IsExpectedException(Arg.Any <Exception>()).Returns(false);
            var storage = new LoggingStorage <string>(_logger, _origin);

            // Act
            Action action = () => storage.Get();

            // Assert
            action.Should().Throw <Exception>();
        }
Ejemplo n.º 2
0
        public void Get_ShouldBe_OriginGet()
        {
            // Arrange
            const string expected = "John Doe";

            _origin.Get().Returns(expected);
            var storage = new LoggingStorage <string>(_logger, _origin);

            // Act
            var value = storage.Get();

            // Assert
            value.Should().Be(expected);
        }
Ejemplo n.º 3
0
        public void Get_ShouldLog_WhenOriginThrows_ExpectedException()
        {
            // Arrange
            var exception = new Exception();

            _origin.When(x => x.Get()).Do(_ => throw exception);
            ((IThrowsExpectedExceptions)_origin).IsExpectedException(exception).Returns(true);

            var storage = new LoggingStorage <string>(_logger, _origin);

            // Act
            try
            {
                storage.Get();
            }
            catch
            {
            }

            // Assert
            _logger.Received().Error(Arg.Any <string>());
        }