Пример #1
0
        public void TestManyEntries2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Debug));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(2, 2, "C", LevelFlags.Warning));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(2, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(3, 3, "D", LevelFlags.Error));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(3, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(4, 4, "E", LevelFlags.Fatal));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(4, 1));
            _taskScheduler.RunOnce();

            logFile.Count.Should().Be(5);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "A", LevelFlags.Debug));
            logFile.GetLine(1).Should().Be(new LogLine(1, 1, "B", LevelFlags.Info));
            logFile.GetLine(2).Should().Be(new LogLine(2, 2, "C", LevelFlags.Warning));
            logFile.GetLine(3).Should().Be(new LogLine(3, 3, "D", LevelFlags.Error));
            logFile.GetLine(4).Should().Be(new LogLine(4, 4, "E", LevelFlags.Fatal));
        }
Пример #2
0
        public void TestManyEntries4()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "Foo", LevelFlags.None));
            _lines.Add(new LogLine(1, 1, "INFO: Bar", LevelFlags.Info));

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2));
            _taskScheduler.RunOnce();
            logFile.GetSection(new LogFileSection(0, 2))
            .Should().Equal(new object[]
            {
                new LogLine(0, 0, "Foo", LevelFlags.None),
                new LogLine(1, 1, "INFO: Bar", LevelFlags.Info)
            });

            logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(1, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);

            _lines[1] = new LogLine(1, 1, "Bar", LevelFlags.None);
            _lines.Add(new LogLine(2, 2, "INFO: Sup", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 2));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(3);
            logFile.GetSection(new LogFileSection(0, 3))
            .Should().Equal(new object[]
            {
                new LogLine(0, 0, "Foo", LevelFlags.None),
                new LogLine(1, 0, "Bar", LevelFlags.None),
                new LogLine(2, 1, "INFO: Sup", LevelFlags.Info)
            });
        }
Пример #3
0
        public void TestReset2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Info));
            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Warning));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(2);

            _lines.Clear();
            logFile.OnLogFileModified(_source.Object, LogFileSection.Reset);
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(0);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Info));
            _lines.Add(new LogLine(1, 1, "A continued", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 2));
            _taskScheduler.RunOnce();

            logFile.GetSection(new LogFileSection(0, 2)).Should().Equal(new object[]
            {
                new LogLine(0, 0, "A", LevelFlags.Info),
                new LogLine(1, 0, "A continued", LevelFlags.Info)
            }, "because the log file should now represent the new content where both lines belong to the same entry");
        }
Пример #4
0
        public void TestManyEntries7()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 3);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();

            _lines[1] = new LogLine(1, 1, "B", LevelFlags.None);
            _lines.Add(new LogLine(2, 2, "C", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(1, 1));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 2));
            _taskScheduler.RunOnce();

            logFile.GetSection(new LogFileSection(0, 3))
            .Should().Equal(
                new LogLine(0, 0, "A", LevelFlags.None),
                new LogLine(1, 1, "B", LevelFlags.None),
                new LogLine(2, 2, "C", LevelFlags.None));
        }
Пример #5
0
        public void TestTwoEntries1()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "DEBUG: Starting...", LevelFlags.Debug));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 10);
            _lines.Add(new LogLine(1, 1, "INFO: hello", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();
            _changes.Should().Equal(new object[]
            {
                LogFileSection.Reset,
                new LogFileSection(0, 1),
                new LogFileSection(1, 1)
            });

            _changes.Clear();
            _lines.Add(new LogLine(2, 2, "world!", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(2, 1));
            _taskScheduler.RunOnce();
            _changes.Should().Equal(new object[]
            {
                LogFileSection.Invalidate(1, 1),
                new LogFileSection(1, 2)
            });
        }
Пример #6
0
        public void TestOneLine2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 10);

            _lines.Add(new LogLine(0, 0, "INFO: Hello ", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            _changes.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1) });

            _lines[0] = new LogLine(0, 0, "Hello World!", LevelFlags.None);
            logFile.OnLogFileModified(_source.Object, LogFileSection.Invalidate(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(0);

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            _changes.Should().Equal(new object[]
            {
                LogFileSection.Reset,
                new LogFileSection(0, 1),
                LogFileSection.Invalidate(0, 1),
                new LogFileSection(0, 1)
            });

            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "Hello World!", LevelFlags.None));
        }
Пример #7
0
        public void TestReset1()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "INFO: hello", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            _lines.Clear();
            logFile.OnLogFileModified(_source.Object, LogFileSection.Reset);
            _taskScheduler.RunOnce();

            logFile.Count.Should().Be(0, "because the source is completely empty");
        }
Пример #8
0
        public void TestOneModification6()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.Size).Should().BeNull("because the source doesn't exist (yet)");

            var size = Size.FromGigabytes(42);

            _lines.Add(new LogLine());
            _source.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(size);
            _source.Setup(x => x.GetValues(It.IsAny <ILogFileProperties>()))
            .Callback((ILogFileProperties properties) =>
            {
                properties.SetValue(LogFileProperties.Size, size);
            });

            logFile.GetValue(LogFileProperties.Size).Should().BeNull("because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.GetValue(LogFileProperties.Size).Should().BeNull("because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.Size).Should().Be(size, "because the change should have been applied by now");
        }
Пример #9
0
        public void TestOneModification5()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.LastModified).Should().NotHaveValue("because the source doesn't exist (yet)");

            var timestamp = new DateTime(2017, 3, 15, 22, 40, 0);

            _lines.Add(new LogLine());
            _source.Setup(x => x.GetValue(LogFileProperties.LastModified)).Returns(timestamp);
            _source.Setup(x => x.GetValues(It.IsAny <ILogFileProperties>()))
            .Callback((ILogFileProperties properties) =>
            {
                properties.SetValue(LogFileProperties.LastModified, timestamp);
            });

            logFile.GetValue(LogFileProperties.LastModified).Should().NotHaveValue("because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.GetValue(LogFileProperties.LastModified).Should().NotHaveValue("because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.LastModified).Should().Be(timestamp, "because the change should have been applied by now");
        }
Пример #10
0
        public void TestEndOfSourceReached2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _source.Setup(x => x.EndOfSourceReached).Returns(false);
            _taskScheduler.RunOnce();
            logFile.EndOfSourceReached.Should().BeFalse("because the source isn't finished yet");

            logFile.OnLogFileModified(_source.Object, LogFileSection.Reset);
            logFile.EndOfSourceReached.Should().BeFalse("because the source isn't finished yet");

            logFile.OnLogFileModified(_source.Object, LogFileSection.Reset);
            _source.Setup(x => x.EndOfSourceReached).Returns(true);
            _taskScheduler.RunOnce();
            logFile.EndOfSourceReached.Should().BeTrue("because the log file has processed all events AND the source is finished");
        }
Пример #11
0
        public void TestOneEntry2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            var timestamp = new DateTime(2017, 3, 15, 21, 52, 0);

            _lines.Add(new LogLine(0, 0, "hello", LevelFlags.Info, timestamp));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);

            _lines.Add(new LogLine(1, 1, "world!", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(2);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "hello", LevelFlags.Info, timestamp));
            logFile.GetLine(1).Should().Be(new LogLine(1, 0, "world!", LevelFlags.Info, timestamp));
        }
Пример #12
0
        public void TestOneLine3()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "Hello World!", LevelFlags.None));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            logFile.Count.Should().Be(1);
            logFile.GetLine(0).Should().Be(new LogLine(0, 0, "Hello World!", LevelFlags.None));
        }
Пример #13
0
        public void TestEndOfSourceReached1()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _source.Setup(x => x.EndOfSourceReached).Returns(true);
            _taskScheduler.RunOnce();
            logFile.EndOfSourceReached.Should().BeTrue();

            logFile.OnLogFileModified(_source.Object, LogFileSection.Reset);
            logFile.EndOfSourceReached.Should().BeFalse();
        }
Пример #14
0
        public void TestOneEntry3()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 10);

            _lines.Add(new LogLine(0, 0, "INFO: hello", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();
            _changes.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1) });

            _changes.Clear();
            _lines.Add(new LogLine(1, 1, "world!", LevelFlags.Other));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();
            _changes.Should().Equal(new object[]
            {
                new LogFileSection(1, 1)
            });
        }
Пример #15
0
        public void TestManyEntries6()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            logFile.AddListener(_listener.Object, TimeSpan.Zero, 3);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Other));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Other));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(1, 1));
            _taskScheduler.RunOnce();

            _lines.Add(new LogLine(2, 2, "C", LevelFlags.Info));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(2, 1));
            _taskScheduler.RunOnce();

            _changes.Should().Equal(LogFileSection.Reset,
                                    new LogFileSection(0, 1),
                                    new LogFileSection(1, 1),
                                    new LogFileSection(2, 1));
        }
Пример #16
0
        public void TestOneModification2()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.MaxCharactersPerLine.Should().Be(0);

            _lines.Add(new LogLine());
            _source.Setup(x => x.MaxCharactersPerLine).Returns(42);
            logFile.MaxCharactersPerLine.Should().Be(0, "because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.MaxCharactersPerLine.Should().Be(0, "because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.MaxCharactersPerLine.Should().Be(42, "because the change should have been applied by now");
        }
Пример #17
0
        public void TestGetSection()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.Add(new LogLine(0, 0, "A", LevelFlags.Debug));
            _lines.Add(new LogLine(1, 1, "B", LevelFlags.Info));
            _lines.Add(new LogLine(2, 2, "C", LevelFlags.Warning));
            _lines.Add(new LogLine(3, 3, "D", LevelFlags.Error));
            _lines.Add(new LogLine(4, 4, "E", LevelFlags.Fatal));
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 5));
            _taskScheduler.RunOnce();

            logFile.GetSection(new LogFileSection(0, 5)).Should().Equal(new object[]
            {
                new LogLine(0, 0, "A", LevelFlags.Debug),
                new LogLine(1, 1, "B", LevelFlags.Info),
                new LogLine(2, 2, "C", LevelFlags.Warning),
                new LogLine(3, 3, "D", LevelFlags.Error),
                new LogLine(4, 4, "E", LevelFlags.Fatal)
            });
        }
Пример #18
0
        public void TestManyEntries3()
        {
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _lines.AddRange(Enumerable.Range(0, 10001).Select(i => new LogLine(i, i, "", LevelFlags.Info)));
            _source.Setup(x => x.EndOfSourceReached).Returns(true);
            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 10001));
            _taskScheduler.RunOnce();

            logFile.Count.Should().Be(10000, "because the log file should process a fixed amount of lines per tick");
            logFile.EndOfSourceReached.Should().BeFalse("because the log file hasn't processed the entire source yet");
            logFile.GetSection(new LogFileSection(0, 10000))
            .Should().Equal(_lines.GetRange(0, 10000));

            _taskScheduler.RunOnce();
            logFile.Count.Should()
            .Be(10001, "because the log file should now have enough ticks elapsed to have processed the entire source");
            logFile.EndOfSourceReached.Should().BeTrue("because the log file should've processed the entire source by now");
            logFile.GetSection(new LogFileSection(0, 10001))
            .Should().Equal(_lines);
        }
Пример #19
0
        public void TestOneModification3()
        {
            _source.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.SourceDoesNotExist);
            var logFile = new MultiLineLogFile(_taskScheduler, _source.Object, TimeSpan.Zero);

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the source doesn't exist (yet)");

            _lines.Add(new LogLine());
            _source.Setup(x => x.GetValue(LogFileProperties.EmptyReason)).Returns(ErrorFlags.None);
            _source.Setup(x => x.GetValues(It.IsAny <ILogFileProperties>()))
            .Callback((ILogFileProperties properties) =>
            {
                properties.SetValue(LogFileProperties.EmptyReason, ErrorFlags.None);
            });

            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the change shouldn't have been applied yet");

            logFile.OnLogFileModified(_source.Object, new LogFileSection(0, 1));
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.SourceDoesNotExist, "because the change shouldn't have been applied yet");

            _taskScheduler.RunOnce();
            logFile.GetValue(LogFileProperties.EmptyReason).Should().Be(ErrorFlags.None, "because the change should have been applied by now");
        }