Beispiel #1
0
        public void Logs_are_packed_into_LogglyMessage([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter, string message)
        {
            Mock.Get(formatter).Setup(p => p(It.IsAny <object>(), It.IsAny <Exception>())).Returns(message);

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.Is <LogglyMessage>(m => m.Level == level && m.Category == sut.Name && m.Event == eventId && m.Data == state && m.Message == message)));
        }
Beispiel #2
0
        public void Logs_are_discarded_if_formatter_returns_null([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error)
        {
            Func <object, Exception, string> formatter = (s, ex) => null;

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Beispiel #3
0
        public void Logs_are_discarded_if_not_matching_filter([Frozen] ILogglyProcessor processor, [Frozen] LogglyOptions options, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            options.Filter = (name, id, logLevel) => false;

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Beispiel #4
0
        public void Logs_from_LogglyHttpClient_are_ignored(ILogglyProcessor processor, LogglyOptions options, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            var sut = new LogglyLogger(typeof(LogglyHttpClient).FullName, processor, options);

            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.IsAny <LogglyMessage>()), Times.Never);
        }
Beispiel #5
0
        public void Messages_can_be_pre_processed([Frozen] ILogglyProcessor processor, [Frozen] LogglyOptions options, LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error, Func <object, Exception, string> formatter)
        {
            sut.Log(level, eventId, state, error, formatter);

            Mock.Get(options.PreProcessMessage).Verify(p => p(It.IsAny <LogglyMessage>()), Times.Once);
        }
Beispiel #6
0
        public void No_error_is_added_to_message_when_exception_is_null([Frozen] ILogglyProcessor processor, LogglyLogger sut, LogLevel level, EventId eventId, object state, Func <object, Exception, string> formatter)
        {
            sut.Log(level, eventId, state, null, formatter);

            Mock.Get(processor).Verify(p => p.EnqueueMessage(It.Is <LogglyMessage>(o => o.Error == null)));
        }
Beispiel #7
0
 public void Formatter_is_required(LogglyLogger sut, LogLevel level, EventId eventId, object state, Exception error)
 {
     Assert.Throws <ArgumentNullException>(() => sut.Log(level, eventId, state, error, null));
 }