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); } }
public void TestListener() { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 0, "Yikes", LevelFlags.None)); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("yikes", true, LevelFlags.All))) { var sections = new List <LogFileSection>(); var listener = new Mock <ILogFileListener>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile l, LogFileSection s) => sections.Add(s)); // We deliberately set the batchSize to be greater than the amount of entries that will be matched. // If the FilteredLogFile is implemented correctly, then it will continously notifiy the listener until // the maximum wait time is elapsed. const int batchSize = 10; file.AddListener(listener.Object, TimeSpan.FromMilliseconds(100), batchSize); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(2); sections.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 2) }); } }
public void TestGetSection1() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("yikes", true, LevelFlags.All))) { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 1, "Yikes", LevelFlags.Info)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); var section = file.GetSection(new LogFileSection(0, 1)); section.Should().NotBeNull(); section.Length.Should().Be(1); section[0].LineIndex.Should().Be(0, "because the filtered log file only represents a file with one line, thus the only entry should have an index of 0, not 1, which is the original index"); section[0].OriginalLineIndex.Should().Be(1, "because the given line is the second line in the source file"); section[0].Message.Should().Be("Yikes"); section[0].Level.Should().Be(LevelFlags.Info); var line = file.GetLine(0); line.LineIndex.Should().Be(0, "because the filtered log file only represents a file with one line, thus the only entry should have an index of 0, not 1, which is the original index"); line.OriginalLineIndex.Should().Be(1, "because the given line is the second line in the source file"); line.Message.Should().Be("Yikes"); line.Level.Should().Be(LevelFlags.Info); } }
public void TestSingleLineFilter2() { var filter = new Mock <ILogLineFilter>(); filter.Setup(x => x.PassesFilter(It.IsAny <LogLine>())).Returns(false); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter.Object, null)) { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); file.Count.Should().Be(0, "because the log line filter didn't pass the added line"); _entries.Add(new LogLine(1, 0, "INFO: Something mundane", LevelFlags.Info)); file.OnLogFileModified(_logFile.Object, new LogFileSection(1, 0)); _taskScheduler.RunOnce(); file.Count.Should().Be(0, "because the log line filter didn't pass the added line"); } }
public void TestClear() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Debug))) { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 0, "DEBUG: Yikes", LevelFlags.None)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(2); _entries.Clear(); file.OnLogFileModified(_logFile.Object, LogFileSection.Reset); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(0); } }
public void TestInvalidate2() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Info))) { file.AddListener(_listener.Object, TimeSpan.Zero, 1); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); _entries.AddRange(new[] { new LogLine(0, 0, "A", LevelFlags.Info), new LogLine(1, 1, "B", LevelFlags.Info), new LogLine(2, 2, "C", LevelFlags.Info), new LogLine(3, 3, "D", LevelFlags.Info) }); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(4); file.OnLogFileModified(_logFile.Object, LogFileSection.Invalidate(2, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(2); _sections.Should().Equal(new[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1), new LogFileSection(2, 1), new LogFileSection(3, 1), LogFileSection.Invalidate(2, 2) }); } }
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"); } }
public void TestInvalidate1() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Info))) { _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); _entries.AddRange(new[] { new LogLine(0, 0, "A", LevelFlags.Info), new LogLine(1, 1, "B", LevelFlags.Info), new LogLine(2, 2, "C", LevelFlags.Info), new LogLine(3, 3, "D", LevelFlags.Info) }); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4)); file.OnLogFileModified(_logFile.Object, LogFileSection.Invalidate(2, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(2, "because we've invalidated the last 2 out of 4 lines"); } }
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 TestGetOriginalIndicesFrom3() { var filter = new LevelFilter(LevelFlags.Info); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null)) { _entries.Add(new LogLine(0, 0, "This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 1, "This is a test", LevelFlags.Info)); _entries.Add(new LogLine(2, 2, "This is a test", LevelFlags.Error)); _entries.Add(new LogLine(3, 3, "This is a test", LevelFlags.Info)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4)); _taskScheduler.RunOnce(); var originalIndices = file.GetColumn(new LogFileSection(0, 2), LogFileColumns.OriginalIndex); originalIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(3)); } }
public void TestSingleLineFilter1() { var filter = new Mock <ILogLineFilter>(); filter.Setup(x => x.PassesFilter(It.IsAny <LogLine>())).Returns(true); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter.Object, null)) { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); filter.Verify(x => x.PassesFilter(It.Is <LogLine>(y => Equals(y, _entries[0]))), Times.AtLeastOnce, "because the log file should've used our filter at least once to determine if the given log line should've been added"); file.Count.Should().Be(1, "because the filter should've passed the only log line"); } }
public void TestConstruction() { _logFile.Setup(x => x.Count).Returns(2); _logFile.Setup(x => x.Progress).Returns(1); _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 0, "DEBUG: Yikes", LevelFlags.None)); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Debug))) { file.Progress.Should().Be(0, "because the filtered log file hasn't consumed anything of its source (yet)"); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.Progress.Should().Be(1, "because the filtered log file has consumed the entire source"); } }
public void TestGetLogLineIndexOfOriginalLineIndex1() { var filter = new LevelFilter(LevelFlags.Info); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, filter, null)) { _entries.Add(new LogLine(0, 0, "This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 1, "This is a test", LevelFlags.Info)); _entries.Add(new LogLine(2, 2, "This is a test", LevelFlags.Error)); _entries.Add(new LogLine(3, 3, "This is a test", LevelFlags.Info)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 4)); _taskScheduler.RunOnce(); file.GetLogLineIndexOfOriginalLineIndex(new LogLineIndex(0)).Should().Be(LogLineIndex.Invalid); file.GetLogLineIndexOfOriginalLineIndex(new LogLineIndex(1)).Should().Be(new LogLineIndex(0)); file.GetLogLineIndexOfOriginalLineIndex(new LogLineIndex(2)).Should().Be(LogLineIndex.Invalid); file.GetLogLineIndexOfOriginalLineIndex(new LogLineIndex(3)).Should().Be(new LogLineIndex(1)); } }
public void TestGetLine2() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(LevelFlags.Error))) { _entries.Add(new LogLine(0, 0, new LogLineSourceId(0), "DEBUG: This is a test", LevelFlags.Debug, null)); _entries.Add(new LogLine(1, 1, new LogLineSourceId(42), "ERROR: I feel a disturbance in the source", LevelFlags.Error, null)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(1, "because only one line matches the filter"); var line = file.GetLine(0); line.LineIndex.Should().Be(0); line.LogEntryIndex.Should().Be(0); line.OriginalLineIndex.Should().Be(1); line.Message.Should().Be("ERROR: I feel a disturbance in the source"); line.SourceId.Should().Be(new LogLineSourceId(42), "Because the filtered log file is supposed to simply forward the source id of the log line in question (Issue #154)"); } }
public void TestEntryLevelNone() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("ello", true, LevelFlags.All))) { _entries.Add(new LogLine(0, "Hello world!", LevelFlags.None)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 1)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(1); var section = file.GetSection(new LogFileSection(0, 1)); section.Should().HaveCount(1); section[0].LineIndex.Should().Be(0); section[0].OriginalLineIndex.Should().Be(0); section[0].LogEntryIndex.Should().Be(0); section[0].Message.Should().Be("Hello world!"); section[0].Level.Should().Be(LevelFlags.None); } }
public void TestMultiLineLogEntry2() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("yikes", true, LevelFlags.All))) { _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 0, "Yikes", LevelFlags.None)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(2); file.GetSection(new LogFileSection(0, 2)) .Should().Equal(new[] { new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug), new LogLine(1, 0, "Yikes", LevelFlags.None) }); } }
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); } }
public void TestWait() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Debug))) { var sections = new List <LogFileSection>(); var listener = new Mock <ILogFileListener>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section)); file.AddListener(listener.Object, TimeSpan.FromMilliseconds(100), 3); _entries.Add(new LogLine(0, 0, "DEBUG: This is a test", LevelFlags.Debug)); _entries.Add(new LogLine(1, 0, "DEBUG: Yikes", LevelFlags.None)); file.OnLogFileModified(_logFile.Object, new LogFileSection(0, 2)); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); sections.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(new LogLineIndex(0), 2) }); } }