public void Emit()
        {
            string message = "PlainMessageTemplate";

            LogEventLevel logEventLevel      = LogEventLevel.Warning;
            TraceLevel    expectedTraceLevel = TraceLevel.Warning;

            LogEvent logEvent = LogEventHelper.GetLogEvent(message, logEventLevel);

            ITextFormatter formatter = new MessageTemplateTextFormatter("{Message}", null);

            InMemoryTraceWriter traceWriter = new InMemoryTraceWriter(TraceLevel.Verbose);

            TraceWriterSink sink = new TraceWriterSink(traceWriter, formatter);

            Assert.Equal(0, traceWriter.Events.Count);

            sink.Emit(logEvent);

            Assert.Equal(1, traceWriter.Events.Count);

            TraceEvent traceEvent = traceWriter.Events.First();

            Assert.Equal(message, traceEvent.Message);
            Assert.Equal(expectedTraceLevel, traceEvent.Level);
        }
        public void Constructor()
        {
            TraceWriter    traceWriter = new InMemoryTraceWriter(TraceLevel.Verbose);
            ITextFormatter formatter   = new RawFormatter();

            TraceWriterSink t = new TraceWriterSink(traceWriter, formatter);
        }
        public void FormatLogEventMessage_NullFormatter()
        {
            LogEvent logEvent = LogEventHelper.GetLogEvent();

            string formattedMessage = TraceWriterSink.FormatLogEventMessage(logEvent, null);

            Assert.Null(formattedMessage);
        }
        public void FormatLogEventMessage_NullLogEvent()
        {
            ITextFormatter formatter = new RawFormatter();

            string formattedMessage = TraceWriterSink.FormatLogEventMessage(null, formatter);

            Assert.Null(formattedMessage);
        }
        public void BuildTraceEvent_NullFormatter()
        {
            LogEvent logEvent = LogEventHelper.GetLogEvent();

            TraceEvent traceEvent = TraceWriterSink.BuildTraceEvent(logEvent, null);

            Assert.Null(traceEvent);
        }
        public void BuildTraceEvent_NullLogEvent()
        {
            ITextFormatter formatter = new RawFormatter();

            TraceEvent traceEvent = TraceWriterSink.BuildTraceEvent(null, formatter);

            Assert.Null(traceEvent);
        }
        public void GetLogEventSourceProperty_NotInPropertyValues()
        {
            Dictionary <string, LogEventPropertyValue> propertyValues = new Dictionary <string, LogEventPropertyValue>();

            string source = TraceWriterSink.GetLogEventSourceProperty(propertyValues);

            Assert.Null(source);
        }
        public void Constructor_NullFormatter()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                TraceWriter traceWriter = new InMemoryTraceWriter(TraceLevel.Verbose);

                TraceWriterSink t = new TraceWriterSink(traceWriter, null);
            });
        }
        public void Constructor_NullTraceWriter()
        {
            Assert.Throws <ArgumentNullException>(() =>
            {
                ITextFormatter formatter = new RawFormatter();

                TraceWriterSink t = new TraceWriterSink(null, formatter);
            });
        }
        public void GetLogEventSourceProperty_NullScalarValue()
        {
            Dictionary <string, LogEventPropertyValue> propertyValues = new Dictionary <string, LogEventPropertyValue>
            {
                { Constants.SourceContextPropertyName, new ScalarValue(null) }
            };

            string source = TraceWriterSink.GetLogEventSourceProperty(propertyValues);

            Assert.Null(source);
        }
        public void FormatLogEventMessage()
        {
            string message = "PlainMessageTemplate";

            LogEvent logEvent = LogEventHelper.GetLogEvent(message);

            ITextFormatter formatter = new MessageTemplateTextFormatter("{Message}", null);

            string formattedMessage = TraceWriterSink.FormatLogEventMessage(logEvent, formatter);

            Assert.Equal(message, formattedMessage);
        }
        public void GetLogEventSourceProperty()
        {
            string expectedSource = "SomeSource";

            Dictionary <string, LogEventPropertyValue> propertyValues = new Dictionary <string, LogEventPropertyValue>
            {
                { Constants.SourceContextPropertyName, new ScalarValue(expectedSource) }
            };

            string source = TraceWriterSink.GetLogEventSourceProperty(propertyValues);

            Assert.Equal(expectedSource, source);
        }
        public void Emit_NullLogEvent()
        {
            InMemoryTraceWriter traceWriter = new InMemoryTraceWriter(TraceLevel.Verbose);

            ITextFormatter formatter = new RawFormatter();

            TraceWriterSink sink = new TraceWriterSink(traceWriter, formatter);

            Assert.Equal(0, traceWriter.Events.Count);

            sink.Emit(null);

            Assert.Equal(0, traceWriter.Events.Count);
        }
        public void BuildTraceEvent()
        {
            string message = "PlainMessageTemplate";

            LogEventLevel logEventLevel      = LogEventLevel.Warning;
            TraceLevel    expectedTraceLevel = TraceLevel.Warning;

            LogEvent logEvent = LogEventHelper.GetLogEvent(message, logEventLevel);

            ITextFormatter formatter = new MessageTemplateTextFormatter("{Message}", null);

            TraceEvent traceEvent = TraceWriterSink.BuildTraceEvent(logEvent, formatter);

            Assert.Equal(message, traceEvent.Message);
            Assert.Equal(expectedTraceLevel, traceEvent.Level);
        }
        public void GetLogEventTraceLevel(LogEventLevel logEventLevel, TraceLevel expectedTraceLevel)
        {
            TraceLevel traceLevel = TraceWriterSink.GetLogEventTraceLevel(logEventLevel);

            Assert.Equal(expectedTraceLevel, traceLevel);
        }
        public void GetLogEventSourceProperty_NullLogEventProperties()
        {
            string source = TraceWriterSink.GetLogEventSourceProperty(null);

            Assert.Null(source);
        }