Beispiel #1
0
        private IEmbeddedConfiguration NewConfiguration(int itemCount)
        {
            FileStorage            rafAdapter = new FileStorage();
            IStorage               ioAdapter  = new LoggingStorage(rafAdapter, LogFileName(itemCount));
            IEmbeddedConfiguration config     = Db4oEmbedded.NewConfiguration();

            config.File.Storage = ioAdapter;
            return(config);
        }
Beispiel #2
0
        public void Set_ShouldCall_OriginSet()
        {
            // Arrange
            const string value   = "John Doe Set";
            var          storage = new LoggingStorage <string>(_logger, _origin);

            // Act
            storage.Set(value);

            // Assert
            _origin.Received().Set(value);
        }
Beispiel #3
0
        public void Set_ShouldPass_UnexpectedException()
        {
            // Arrange
            _origin.When(x => x.Set(Arg.Any <string>())).Do(_ => throw new Exception());
            ((IThrowsExpectedExceptions)_origin).IsExpectedException(Arg.Any <Exception>()).Returns(false);
            var storage = new LoggingStorage <string>(_logger, _origin);

            // Act
            Action action = () => storage.Set("ABC");

            // Assert
            action.Should().Throw <Exception>();
        }
Beispiel #4
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);
        }
Beispiel #5
0
        public void IsExpectedException_ShouldBe_Origin_IsExpectedException(bool expected)
        {
            // Arrange
            var exception = new Exception();

            ((IThrowsExpectedExceptions)_origin).IsExpectedException(exception).Returns(expected);

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

            // Act
            var result = storage.IsExpectedException(exception);

            // Assert
            result.Should().Be(expected);
        }
Beispiel #6
0
        public void Get_ShouldPass_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
            Action action = () => storage.Get();

            // Assert
            action.Should().Throw <Exception>();
        }
Beispiel #7
0
        public void Set_ShouldLog_UnexpectedException()
        {
            // Arrange
            _origin.When(x => x.Set(Arg.Any <string>())).Do(_ => throw new Exception());
            ((IThrowsExpectedExceptions)_origin).IsExpectedException(Arg.Any <Exception>()).Returns(false);

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

            // Act
            try
            {
                storage.Set("ABC");
            }
            catch
            {
            }

            // Assert
            _logger.Received().Error(Arg.Any <string>());
        }
Beispiel #8
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>());
        }
Beispiel #9
0
		private IEmbeddedConfiguration NewConfiguration(int itemCount)
		{
			FileStorage rafAdapter = new FileStorage();
			IStorage ioAdapter = new LoggingStorage(rafAdapter, LogFileName(itemCount));
			IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
			config.File.Storage = ioAdapter;
			return config;
		}