Beispiel #1
0
        public void TestSingleLineFilter6()
        {
            var filter = new EmptyLogLineFilter();

            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 1, "More stuff", LevelFlags.Debug));
                _entries.Add(new LogLine(2, 2, "", LevelFlags.Debug));
                _entries.Add(new LogLine(3, 3, "And even more stuff", LevelFlags.Debug));
                _entries.Add(new LogLine(4, 4, "And even more stuff", LevelFlags.Debug));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 5));
                _taskScheduler.RunOnce();

                file.OnLogFileModified(_logFile.Object, LogFileSection.Invalidate(3, 2));
                _taskScheduler.RunOnce();

                file.OnLogFileModified(_logFile.Object, new LogFileSection(3, 2));
                _taskScheduler.RunOnce();

                file.Count.Should().Be(4, "because the source represents 4 lines (of which the last two changed over its lifetime)");

                const string reason = "because log entry indices are supposed to be consecutive for a data source";
                file.GetLine(0).LogEntryIndex.Should().Be(0, reason);
                file.GetLine(1).LogEntryIndex.Should().Be(1, reason);
                file.GetLine(2).LogEntryIndex.Should().Be(2, reason);
                file.GetLine(3).LogEntryIndex.Should().Be(3, reason);
            }
        }
Beispiel #2
0
        public void TestPassesFilter1()
        {
            var filter = new EmptyLogLineFilter();

            filter.PassesFilter(new LogEntry(Core.Columns.Minimum)).Should().BeFalse("because the given logline is completely empty");
            filter.PassesFilter(new LogEntry(Core.Columns.Minimum)
            {
                Index = 0, RawContent = "", LogLevel = LevelFlags.All
            })
            .Should()
            .BeFalse("because the given line contains only an empty message");
            filter.PassesFilter(new LogEntry(Core.Columns.Minimum)
            {
                Index = 0, RawContent = " ", LogLevel = LevelFlags.All
            })
            .Should()
            .BeFalse("because the given line contains only spaces");
            filter.PassesFilter(new LogEntry(Core.Columns.Minimum)
            {
                Index = 0, RawContent = " \t \r\n", LogLevel = LevelFlags.All
            })
            .Should()
            .BeFalse("because the given line contains only whitespace");
            filter.PassesFilter(new LogEntry(Core.Columns.Minimum)
            {
                Index = 0, RawContent = " s    \t", LogLevel = LevelFlags.All
            })
            .Should()
            .BeTrue("because the given line contains a non-whitespace character");
        }
Beispiel #3
0
        public void TestDispose1()
        {
            var             filter = new EmptyLogLineFilter();
            FilteredLogFile file   = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null);

            _logFile.Verify(x => x.AddListener(It.Is <ILogFileListener>(y => Equals(y, file)),
                                               It.IsAny <TimeSpan>(),
                                               It.IsAny <int>()), Times.Once, "because the filtered log file should register itself as a listener with its source");

            new Action(() => file.Dispose()).Should().NotThrow("because Dispose() must always succeed");

            _logFile.Verify(x => x.RemoveListener(It.Is <ILogFileListener>(y => Equals(y, file))), Times.Once,
                            "because the filtered log file should unregister itself as a listener from its source when being disposed of");
        }
Beispiel #4
0
        public void TestSingleLineFilter3()
        {
            var filter = new EmptyLogLineFilter();

            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 0, "More stuff", LevelFlags.Debug));
                _entries.Add(new LogLine(2, 0, "", LevelFlags.Debug));
                _entries.Add(new LogLine(3, 0, "And even more stuff", LevelFlags.Debug));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4));
                _taskScheduler.RunOnce();

                file.Count.Should().Be(3, "because the log file should've filtered out the one log line that is empty");
            }
        }
        public void TestPassesFilter1()
        {
            var filter = new EmptyLogLineFilter();

            filter.PassesFilter(new LogLine()).Should().BeFalse("because the given logline is completely empty");
            filter.PassesFilter(new LogLine(0, "", LevelFlags.All))
            .Should()
            .BeFalse("because the given line contains only an empty message");
            filter.PassesFilter(new LogLine(0, " ", LevelFlags.All))
            .Should()
            .BeFalse("because the given line contains only spaces");
            filter.PassesFilter(new LogLine(0, " \t \r\n", LevelFlags.All))
            .Should()
            .BeFalse("because the given line contains only whitespace");
            filter.PassesFilter(new LogLine(0, " s    \t", LevelFlags.All))
            .Should()
            .BeTrue("because the given line contains a non-whitespace character");
        }
Beispiel #6
0
        public void TestSingleLineFilter4()
        {
            var filter = new EmptyLogLineFilter();

            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 1, "More stuff", LevelFlags.Debug));
                _entries.Add(new LogLine(2, 2, "", LevelFlags.Debug));
                _entries.Add(new LogLine(3, 3, "And even more stuff", LevelFlags.Debug));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4));
                _taskScheduler.RunOnce();

                file.Count.Should().Be(3, "because the log file should've filtered out the one log line that is empty");

                const string reason = "because log entry indices are supposed to be consecutive for a data source";
                file.GetLine(0).LogEntryIndex.Should().Be(0, reason);
                file.GetLine(1).LogEntryIndex.Should().Be(1, reason);
                file.GetLine(2).LogEntryIndex.Should().Be(2, reason);
            }
        }
Beispiel #7
0
        public void TestSingleLineFilter5()
        {
            var filter = new EmptyLogLineFilter();

            using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null))
            {
                _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug));
                _entries.Add(new LogLine(1, 1, "More stuff", LevelFlags.Debug));
                _entries.Add(new LogLine(2, 2, "", LevelFlags.Debug));
                _entries.Add(new LogLine(3, 3, "And even more stuff", LevelFlags.Debug));
                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4));
                _taskScheduler.RunOnce();

                file.OnLogFileModified(_logFile.Object, LogFileSection.Reset);
                _taskScheduler.RunOnce();

                file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1));
                _taskScheduler.RunOnce();

                file.Count.Should().Be(1, "because only one line remains in the source");
                file.GetLine(0).LogEntryIndex.Should().Be(0, "because log entry indices should always start at 0");
            }
        }