Exemplo n.º 1
0
        public void TestMerge5()
        {
            var             source0  = new List <LogLine>();
            Mock <ILogFile> logFile1 = CreateLogFile(source0);

            var             source1  = new List <LogLine>();
            Mock <ILogFile> logFile2 = CreateLogFile(source1);

            var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object);
            var data   = Listen(merged);

            var later   = new DateTime(2016, 2, 16);
            var earlier = new DateTime(2016, 2, 15);

            source0.Add(new LogLine(0, "a", LevelFlags.Warning, later));
            merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1));

            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            source1.Add(new LogLine(0, "c", LevelFlags.Error, earlier));
            merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1));

            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();
            merged.Count.Should().Be(2);
            data.Should().Equal(new object[]
            {
                new LogLine(0, 0, new LogLineSourceId(1), source1[0]),
                new LogLine(1, 1, new LogLineSourceId(0), source0[0])
            });
        }
Exemplo n.º 2
0
        public void TestMerge3()
        {
            var             source0  = new List <LogLine>();
            Mock <ILogFile> logFile0 = CreateLogFile(source0);

            var             source1  = new List <LogLine>();
            Mock <ILogFile> logFile1 = CreateLogFile(source1);

            var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile0.Object, logFile1.Object);
            var data   = Listen(merged);

            DateTime timestamp = DateTime.Now;

            source0.Add(new LogLine(0, "a", LevelFlags.Info, timestamp));
            merged.OnLogFileModified(logFile0.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            source1.Add(new LogLine(1, "b", LevelFlags.Debug, timestamp));
            merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1));

            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();
            merged.Count.Should().Be(2);
            data.Should().Equal(new object[]
            {
                new LogLine(new LogLineSourceId(0), source0[0]),
                new LogLine(new LogLineSourceId(1), source1[0])
            });
        }
Exemplo n.º 3
0
        public void TestMerge6()
        {
            var             source0  = new List <LogLine>();
            Mock <ILogFile> logFile0 = CreateLogFile(source0);

            var      source1   = new List <LogLine>();
            DateTime timestamp = DateTime.Now;

            source1.Add(new LogLine(0, 0, "Hello World", LevelFlags.Info, timestamp));
            Mock <ILogFile> logFile1 = CreateLogFile(source1);

            var merged  = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), logFile0.Object, logFile1.Object);
            var data    = Listen(merged);
            var changes = ListenToChanges(merged, 1);

            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile0.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1));

            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            data.Should().Equal(new LogLine(new LogLineSourceId(1), source1[0]));

            int count = changes.Count;

            changes.ElementAt(count - 2).Should().Equal(LogFileSection.Reset);
            changes.ElementAt(count - 1).Should().Equal(new LogFileSection(0, 1));
        }
Exemplo n.º 4
0
        public void TestMerge6()
        {
            var source0 = new InMemoryLogFile();
            var source1 = new InMemoryLogFile();

            var merged  = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source0, source1);
            var data    = Listen(merged);
            var changes = ListenToChanges(merged, 1);

            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source0, LogFileSection.Reset);
            merged.OnLogFileModified(source1, LogFileSection.Reset);

            DateTime timestamp = DateTime.Now;

            source1.AddEntry("Hello World", LevelFlags.Info, timestamp);

            _taskScheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            data.Should().Equal(new object[]
            {
                new LogLine(0, 0, new LogLineSourceId(1), "Hello World", LevelFlags.Info, timestamp)
            });

            int count = changes.Count;

            changes.ElementAt(count - 2).Should().Equal(LogFileSection.Reset);
            changes.ElementAt(count - 1).Should().Equal(new LogFileSection(0, 1));
        }
Exemplo n.º 5
0
        public void TestMerge1()
        {
            var source = new List<LogLine>();
            Mock<ILogFile> source1 = CreateLogFile(source);
            var source2 = new Mock<ILogFile>();
            source2.Setup(x => x.EndOfSourceReached).Returns(true);
            var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object);
            IEnumerable<LogLine> data = Listen(merged);

            source.Add(new LogLine(0, 0, "foobar", LevelFlags.Info, DateTime.Now));
            merged.OnLogFileModified(source1.Object, new LogFileSection(0, 1));

            _scheduler.RunOnce();
            merged.Count.Should().Be(1);
            data.Should().Equal(source);
        }
Exemplo n.º 6
0
        public void TestMerge1()
        {
            var             source  = new List <LogLine>();
            Mock <ILogFile> source1 = CreateLogFile(source);
            var             source2 = new Mock <ILogFile>();

            source2.Setup(x => x.EndOfSourceReached).Returns(true);
            var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object);
            IEnumerable <LogLine> data = Listen(merged);

            source.Add(new LogLine(0, 0, "foobar", LevelFlags.Info, DateTime.Now));
            merged.OnLogFileModified(source1.Object, new LogFileSection(0, 1));

            _taskScheduler.RunOnce();
            merged.Count.Should().Be(1);
            data.Should().Equal(source);
        }
Exemplo n.º 7
0
        public void TestMerge4()
        {
            var             source1Lines = new List <LogLine>();
            Mock <ILogFile> source1      = CreateLogFile(source1Lines);
            var             source2      = new Mock <ILogFile>();

            source2.Setup(x => x.EndOfSourceReached).Returns(true);
            var merged = new MergedLogFile(_taskScheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object);
            var data   = Listen(merged);

            source1Lines.Add(new LogLine(0, "a", LevelFlags.Warning, DateTime.Now));
            source1Lines.Add(new LogLine(1, "b", LevelFlags.Info));
            source1Lines.Add(new LogLine(2, "c", LevelFlags.Error, DateTime.Now));
            merged.OnLogFileModified(source1.Object, new LogFileSection(0, 3));

            _taskScheduler.RunOnce();
            merged.Count.Should().Be(2);
            data.Should().Equal(new LogLine(0, 0, new LogLineSourceId(0), source1Lines[0]),
                                new LogLine(1, 1, new LogLineSourceId(0), source1Lines[2]));
        }
Exemplo n.º 8
0
        public void TestMerge6()
        {
            var source1 = new List<LogLine>();
            Mock<ILogFile> logFile1 = CreateLogFile(source1);

            var source2 = new List<LogLine>();
            DateTime timestamp = DateTime.Now;
            source2.Add(new LogLine(0, 0, "Hello World", LevelFlags.Info, timestamp));
            Mock<ILogFile> logFile2 = CreateLogFile(source2);

            var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object);
            var data = Listen(merged);
            var changes = ListenToChanges(merged);

            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile1.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile2.Object, LogFileSection.Reset);
            merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1));

            _scheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            data.Should().Equal(source2);

            int count = changes.Count;
            changes.ElementAt(count - 2).Should().Be(LogFileSection.Reset);
            changes.ElementAt(count - 1).Should().Be(new LogFileSection(0, 1));
        }
Exemplo n.º 9
0
        public void TestMerge5()
        {
            var source1 = new List<LogLine>();
            Mock<ILogFile> logFile1 = CreateLogFile(source1);

            var source2 = new List<LogLine>();
            Mock<ILogFile> logFile2 = CreateLogFile(source2);

            var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object);
            var data = Listen(merged);

            var later = new DateTime(2016, 2, 16);
            var earlier = new DateTime(2016, 2, 15);

            source1.Add(new LogLine(0, "a", LevelFlags.Warning, later));
            merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1));

            _scheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            source2.Add(new LogLine(0, "c", LevelFlags.Error, earlier));
            merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1));

            _scheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();
            merged.Count.Should().Be(2);
            data.Should().Equal(new object[]
                {
                    new LogLine(0, 0, source2[0]),
                    new LogLine(1, 1, source1[0])
                });
        }
Exemplo n.º 10
0
        public void TestMerge4()
        {
            var source = new List<LogLine>();
            Mock<ILogFile> source1 = CreateLogFile(source);
            var source2 = new Mock<ILogFile>();
            source2.Setup(x => x.EndOfSourceReached).Returns(true);
            var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), source1.Object, source2.Object);
            var data = Listen(merged);

            source.Add(new LogLine(0, "a", LevelFlags.Warning, DateTime.Now));
            source.Add(new LogLine(1, "b", LevelFlags.Info));
            source.Add(new LogLine(2, "c", LevelFlags.Error, DateTime.Now));
            merged.OnLogFileModified(source1.Object, new LogFileSection(0, 3));

            _scheduler.RunOnce();
            merged.Count.Should().Be(2);
            data.Should().Equal(new[]
                {
                    new LogLine(0, 0, source[0]),
                    new LogLine(1, 1, source[2])
                });
        }
Exemplo n.º 11
0
        public void TestMerge3()
        {
            var source1 = new List<LogLine>();
            Mock<ILogFile> logFile1 = CreateLogFile(source1);

            var source2 = new List<LogLine>();
            Mock<ILogFile> logFile2 = CreateLogFile(source2);

            var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(1), logFile1.Object, logFile2.Object);
            var data = Listen(merged);

            DateTime timestamp = DateTime.Now;
            source1.Add(new LogLine(0, "a", LevelFlags.Info, timestamp));
            merged.OnLogFileModified(logFile1.Object, new LogFileSection(0, 1));
            _scheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();

            source2.Add(new LogLine(1, "b", LevelFlags.Debug, timestamp));
            merged.OnLogFileModified(logFile2.Object, new LogFileSection(0, 1));

            _scheduler.RunOnce();
            merged.EndOfSourceReached.Should().BeTrue();
            merged.Count.Should().Be(2);
            data.Should().Equal(new object[] {source1[0], source2[0]});
        }