Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void BeginScope_return_valid_disposable_that_can_be_disposed(LogglyLogger sut, object state)
        {
            var scope = sut.BeginScope(state);

            scope.Dispose();

            Assert.That(scope, Is.InstanceOf <IDisposable>());
        }
Exemplo n.º 3
0
        public void IsEnabled_uses_option_filter([Frozen] LogglyOptions options, LogglyLogger sut, LogLevel level)
        {
            sut.IsEnabled(level);

            Mock.Get(options.Filter).Verify(p => p(sut.Name, 0, level));
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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)));
        }
Exemplo n.º 6
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)));
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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));
 }
Exemplo n.º 9
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);
        }