Exemple #1
0
        public void PARSER_SHOULD_ADD_MESSAGE_OBJECT_WHEN_REQUIRED_AND_SERIALIZE_OBJECTS_IS_ENABLED_AND_IS_NOT_EXCEPTION()
        {
            //Arrange
            var messageObject    = new object();
            var loggingEvent     = new LoggingEvent(GetType(), null, null, Level.Info, messageObject, null);
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.Message, true, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary["MessageObject"].Should().Be(messageObject);
        }
Exemple #2
0
        public void PARSER_SHOULD_NOT_ADD_MESSAGE_OBJECT_WHEN_REQUIRED_AND_MESSAGE_OBJECT_IS_STRING()
        {
            //Arrange
            var messageObject    = "hello";
            var loggingEvent     = new LoggingEvent(GetType(), null, null, Level.Info, messageObject, null);
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.Message, false, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary.ContainsKey("MessageObject").Should().BeFalse();
        }
Exemple #3
0
        public void Log_message()
        {
            var loggingEvent = new LoggingEvent(
                this.GetType(),
                null,
                "logger.name",
                Level.Info,
                "message",
                null);
            var parser           = new BasicLoggingEventParser("machine", FixFlags.Partial, true, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            parser.ParseMessage(loggingEvent, resultDictionary);
            Assert.AreEqual(loggingEvent.RenderedMessage, resultDictionary["Message"]);
        }
Exemple #4
0
        public void PARSER_SHOULD_NOT_ADD_MESSAGE_OBJECT_WHEN_REQUIRED_AND_SERIALIZE_OBJECTS_IS_DISABLED()
        {
            //Arrange
            var loggingEvent = new LoggingEvent(new LoggingEventData {
                Message = "hello"
            });
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.Message, false, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary.ContainsKey("MessageObject").Should().BeFalse();
        }
Exemple #5
0
        public void PARSER_SHOULD_ADD_RENDERED_MESSAGE_WHEN_MESSAGE_IS_REQUIRED()
        {
            //Arrange
            var loggingEvent = new LoggingEvent(new LoggingEventData {
                Message = "hello"
            });
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.Message, true, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary["Message"].Should().BeEquivalentTo(loggingEvent.RenderedMessage);
        }
Exemple #6
0
        public void PARSER_SHOULD_NOT_ADD_MESSAGE_FIELDS_WHEN_NOT_REQUIRED()
        {
            //Arrange
            var loggingEvent = new LoggingEvent(new LoggingEventData {
                Message = "hello"
            });
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.None, true, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary.ContainsKey("Message").Should().BeFalse();
            resultDictionary.ContainsKey("MessageObject").Should().BeFalse();
        }
Exemple #7
0
        public void PARSER_SHOULD_ADD_EXCEPTION_AS_MESSAGE_OBJECT_WHEN_REQUIRED_AND_SERIALIZE_OBJECTS_IS_ENABLED()
        {
            //Arrange
            var exception     = new Exception();
            var jsonException = new JsonSerializableException();

            _exceptionFactory.Create(exception).Returns(jsonException);
            var loggingEvent     = new LoggingEvent(GetType(), null, null, Level.Info, exception, null);
            var parser           = new BasicLoggingEventParser(string.Empty, FixFlags.Message, true, _exceptionFactory);
            var resultDictionary = new Dictionary <string, object>();

            //Act
            parser.ParseMessage(loggingEvent, resultDictionary);

            //Assert
            resultDictionary["MessageObject"].Should().Be(jsonException);
        }