Ejemplo n.º 1
0
        public void PushingWithNoTargetsShouldThrow()
        {
            var eventDispatcher = new DefaultEventDispatcher();

            var loggingEvent = new LoggingEvent { Text = "Event" };
            Executing.This(() => eventDispatcher.Push(loggingEvent, false)).Should().Throw<InvalidOperationException>();
        }
Ejemplo n.º 2
0
        public void CanPushToDefaultTargets()
        {
            var target1Mock = new Mock<ITarget>();
            var target2Mock = new Mock<ITarget>();

            var eventDispatcher = new DefaultEventDispatcher { DefaultTargets = new[] { target1Mock.Object, target2Mock.Object } };

            var loggingEvent = new LoggingEvent { Text = "Event" };
            eventDispatcher.Push(loggingEvent, false);

            target1Mock.Verify(o => o.Log(loggingEvent));
            target2Mock.Verify(o => o.Log(loggingEvent));
        }
Ejemplo n.º 3
0
        public void CanAddAndPushToTargets()
        {
            var target1Mock = new Mock<ITarget>();
            var target2Mock = new Mock<ITarget>();

            var eventDispatcher = new DefaultEventDispatcher();

            eventDispatcher.AddTarget(target1Mock.Object);
            eventDispatcher.AddTarget(target2Mock.Object);

            var loggingEvent = new LoggingEvent { Text = "Event" };
            eventDispatcher.Push(loggingEvent, false);

            target1Mock.Verify(o => o.Log(loggingEvent));
            target2Mock.Verify(o => o.Log(loggingEvent));
        }
        public void CanPushToTargets()
        {
            var target1Mock = new Mock<Target>();
            var target2Mock = new Mock<Target>();

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", target1Mock.Object);
            configuration.AddTarget("2", target2Mock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);

            var loggingEvent = new LoggingEvent { Text = "Event" };
            var loggingEvents = new[] { loggingEvent };

            eventDispatcher.Push(loggingEvents);

            target1Mock.Verify(o => o.Push(loggingEvents));
            target2Mock.Verify(o => o.Push(loggingEvents));
        }
        public void Event_Complying_With_Level_Filters_Should_Be_Pushed()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.MinLevel).Returns(LoggingEventLevel.Warning);
            targetMock.SetupGet(x => x.MaxLevel).Returns(LoggingEventLevel.Error);

            var loggingEvent = new LoggingEvent()
            {
                Level = LoggingEventLevel.Error
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Once);
        }
        public void Event_Matching_LogKeyStartsWith_Ignore_Filter_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { LogKeyStartsWith = "Sample." }
            });

            var loggingEvent = new LoggingEvent()
            {
                LogKey = "Sample.LogKey"
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }
        public void Event_Matching_TextContains_Ignore_Filter_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { TextContains = "description" }
            });

            var loggingEvent = new LoggingEvent()
            {
                Text = "A description of the error"
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }
        public void Event_Matching_TagContains_Ignore_Should_Be_Ignored()
        {
            var targetMock = new Mock<Target>();
            targetMock.SetupGet(x => x.Ignores).Returns(new List<Ignore>()
            {
                new Ignore() { TagsContains = "tag2" }
            });

            var loggingEvent = new LoggingEvent()
            {
                Tags = new List<string>() { "tag1", "tag2", "tag3", "tag4" }
            };

            var configuration = new PulsusConfiguration();
            configuration.AddTarget("1", targetMock.Object);

            var eventDispatcher = new DefaultEventDispatcher(configuration);
            eventDispatcher.Push(new[] { loggingEvent });

            targetMock.Verify(x => x.Push(It.IsAny<LoggingEvent[]>()), Times.Never);
        }