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 TestGetOriginalLineNumbersByIndices() { var filter = new SubstringFilter("B", true); var source = new InMemoryLogFile(); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "A" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "B" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "A" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "B" }); var filteredLogFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null); _taskScheduler.RunOnce(); filteredLogFile.Count.Should().Be(2); var lineNumbers = filteredLogFile.GetColumn(new LogLineIndex[] { 1, 0 }, LogFileColumns.OriginalLineNumber); lineNumbers[0].Should().Be(4); lineNumbers[1].Should().Be(2); lineNumbers = filteredLogFile.GetColumn(new LogLineIndex[] { 1 }, LogFileColumns.OriginalLineNumber); lineNumbers[0].Should().Be(4); }
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 TestGetLineNumbersBySection() { var filter = new SubstringFilter("B", true); var source = new InMemoryLogFile(); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "A" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "B" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "A" }); source.Add(new LogEntry2(LogFileColumns.Minimum) { RawContent = "B" }); var filteredLogFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null); _taskScheduler.RunOnce(); filteredLogFile.Count.Should().Be(2); var lineNumbers = filteredLogFile.GetColumn(new LogFileSection(0, 2), LogFileColumns.LineNumber); lineNumbers[0].Should().Be(1); lineNumbers[1].Should().Be(2); }
public void TestFilter2() { using (var file = new TextLogFile(_scheduler, File20Mb)) { file.Property(x => x.Count).ShouldEventually().Be(165342, TimeSpan.FromSeconds(5)); using (FilteredLogFile filtered = file.AsFiltered(_scheduler, null, Filter.Create("info"))) { var listener = new Mock <ILogFileListener>(); var sections = new List <LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section)); filtered.Property(x => x.Count).ShouldEventually().Be(5, TimeSpan.FromSeconds(5)); filtered.AddListener(listener.Object, TimeSpan.Zero, 1); sections.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, 1), new LogFileSection(1, 1), new LogFileSection(2, 1), new LogFileSection(3, 1), new LogFileSection(4, 1) }); } } }
protected override ILogFile CreateFromContent(IReadOnlyLogEntries content) { var source = new InMemoryLogFile(content); var filter = new NoFilter(); var filtered = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null); _taskScheduler.RunOnce(); return(filtered); }
public void TestEmptyLogFile1() { using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create("Test", true, LevelFlags.All))) { _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue(); file.Count.Should().Be(0); file.GetLogLineIndexOfOriginalLineIndex(new LogLineIndex(0)).Should().Be(LogLineIndex.Invalid); } }
public void TestSize() { var size = Size.FromGigabytes(5); _logFile.Setup(x => x.GetValue(LogFileProperties.Size)).Returns(size); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Info))) { _taskScheduler.RunOnce(); file.GetValue(LogFileProperties.Size).Should().Be(size, "because the size of the source should be forwarded since that is of interest to the user"); } }
public void TestLastModified() { var lastModified = new DateTime(2017, 12, 21, 20, 52, 0); _logFile.Setup(x => x.GetValue(LogFileProperties.LastModified)).Returns(lastModified); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Info))) { _taskScheduler.RunOnce(); file.GetValue(LogFileProperties.LastModified).Should().Be(lastModified, "because the last modification date of the source should be forwarded since that is of interest to the user"); } }
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"); }
public void TestInvalidate4() { var logFile = new InMemoryLogFile(); using (var multiLine = new MultiLineLogFile(_taskScheduler, logFile, TimeSpan.Zero)) using (var filtered = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, multiLine, null, Filter.Create(null, true, LevelFlags.Info))) { logFile.AddRange(new[] { new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 19, 195), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-19.195339; 0; 0; 0; 108; 0; 124; 1;INFO; ; ; ; ; ; 0; Some interesting message" }, new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 19, 751), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-19.751428; 0; 0; 0; 129; 0; 145; 1;INFO; ; ; ; ; ; 0; Very interesting stuff" }, new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.None, RawContent = "2017-03-24 11-45-21.708485; 0; 0; 0; 109; 0; 125; 1;PB_CREATE; ; ; 109; 2;" } }); _taskScheduler.RunOnce(); filtered.Count.Should().Be(3); filtered.GetLine(0).OriginalLineIndex.Should().Be(0); filtered.GetLine(1).OriginalLineIndex.Should().Be(1); filtered.GetLine(2).OriginalLineIndex.Should().Be(2); logFile.RemoveFrom(new LogLineIndex(2)); logFile.AddRange(new [] { new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.None, RawContent = "2017-03-24 11-45-21.708485; 0; 0; 0; 109; 0; 125; 1;PB_CREATE; ; ; 109; 2; Sooo interesting" }, new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-21.708599; 0; 0; 0; 108; 0; 124; 1;INFO; ; ; ; ; ; 0; Go on!" }, new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 811), LogLevel = LevelFlags.Info, RawContent = "2017-03-24 11-45-21.811838; 0; 0; 0; 108; 0; 124; 1;INFO; ; ; ; ; ; 0; done." } }); _taskScheduler.RunOnce(); filtered.Count.Should().Be(5); filtered.GetLine(0).OriginalLineIndex.Should().Be(0); filtered.GetLine(1).OriginalLineIndex.Should().Be(1); filtered.GetLine(2).OriginalLineIndex.Should().Be(2); filtered.GetLine(3).OriginalLineIndex.Should().Be(3); filtered.GetLine(4).OriginalLineIndex.Should().Be(4); } }
public void TestGetDeltaTime1() { var filter = new NoFilter(); var source = new InMemoryLogFile(); using (var logFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null)) { source.AddEntry("", LevelFlags.None, DateTime.MinValue); var deltas = logFile.GetColumn(new LogFileSection(0, 1), LogFileColumns.DeltaTime); deltas.Should().NotBeNull(); deltas.Should().HaveCount(1); deltas[0].Should().BeNull(); } }
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 TestGetTimestamp1() { var filter = new NoFilter(); var source = new InMemoryLogFile(); using (var logFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null)) { var timestamp = new DateTime(2017, 12, 11, 20, 46, 0); source.AddEntry("", LevelFlags.None, timestamp); _taskScheduler.RunOnce(); var timestamps = logFile.GetColumn(new LogFileSection(0, 1), LogFileColumns.Timestamp); timestamps.Should().NotBeNull(); timestamps.Should().Equal(new object[] { timestamp }); } }
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 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 TestGetDeltaTime2() { var filter = new NoFilter(); var source = new InMemoryLogFile(); using (var logFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null)) { source.AddEntry("", LevelFlags.None, new DateTime(2017, 12, 11, 19, 34, 0)); source.AddEntry("", LevelFlags.None, new DateTime(2017, 12, 11, 19, 35, 0)); _taskScheduler.RunOnce(); var deltas = logFile.GetColumn(new LogFileSection(0, 2), LogFileColumns.DeltaTime); deltas.Should().NotBeNull(); deltas.Should().HaveCount(2); deltas[0].Should().BeNull(); deltas[1].Should().Be(TimeSpan.FromMinutes(1)); } }
public void Test() { using (var source1 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Entries)) using (var source2 = new TextLogFile(_scheduler, TextLogFileAcceptanceTest.File2Lines)) { var sources = new List <ILogFile> { source1, source2 }; using (var merged = new MergedLogFile(_scheduler, TimeSpan.FromMilliseconds(10), sources)) { var filter = new SubstringFilter("foo", true); using (var filtered = new FilteredLogFile(_scheduler, TimeSpan.FromMilliseconds(10), merged, null, filter)) { filtered.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); } } } }
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 TestEndOfSourceReached1() { _logFile.Setup(x => x.EndOfSourceReached).Returns(false); using (var file = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, _logFile.Object, null, Filter.Create(null, true, LevelFlags.Debug))) { file.EndOfSourceReached.Should().BeFalse("because the filtered log file hasn't even inspected the source yet"); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeFalse("because the source isn't at its own end yet"); _logFile.Setup(x => x.EndOfSourceReached).Returns(true); file.EndOfSourceReached.Should().BeFalse("because the filtered log file hasn't processed the latest changes to the source yet"); _taskScheduler.RunOnce(); file.EndOfSourceReached.Should().BeTrue("because the source is finished and the filtered log file has processed all changes from the source"); } }
public void TestGetDeltaTime3() { var filter = new LevelFilter(LevelFlags.Info); var source = new InMemoryLogFile(); using (var logFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null)) { source.AddEntry("", LevelFlags.Info, new DateTime(2017, 12, 11, 19, 34, 0)); source.AddEntry("", LevelFlags.Debug, new DateTime(2017, 12, 11, 19, 35, 0)); source.AddEntry("", LevelFlags.Info, new DateTime(2017, 12, 11, 19, 36, 0)); _taskScheduler.RunOnce(); var deltas = logFile.GetColumn(new LogFileSection(0, 2), LogFileColumns.DeltaTime); deltas.Should().NotBeNull(); deltas.Should().HaveCount(2); deltas[0].Should().BeNull(); deltas[1].Should().Be(TimeSpan.FromMinutes(2), "because the delta time should be calculated based on events which match the filter"); } }
public void TestGetTimestamp2() { var filter = new LevelFilter(LevelFlags.Error); var source = new InMemoryLogFile(); using (var logFile = new FilteredLogFile(_taskScheduler, TimeSpan.Zero, source, filter, null)) { var timestamp1 = new DateTime(2017, 12, 11, 20, 46, 0); source.AddEntry("", LevelFlags.Warning, timestamp1); var timestamp2 = new DateTime(2017, 12, 11, 20, 50, 0); source.AddEntry("", LevelFlags.Error, timestamp2); _taskScheduler.RunOnce(); var timestamps = logFile.GetColumn(new LogFileSection(0, 1), LogFileColumns.Timestamp); timestamps.Should().NotBeNull(); timestamps.Should().Equal(new object[] { timestamp2 }, "because the first entry doesn't match the filter and thus the timestamp of the 2nd one should've been returned"); } }
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 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 TestFilter3() { const string fname = "TestFilter3.log"; using (FileStream stream = File.OpenWrite(fname)) using (var writer = new StreamWriter(stream)) { stream.SetLength(0); writer.WriteLine("INFO - Test"); } using (var file = new TextLogFile(_scheduler, fname)) { file.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); file.Property(x => x.Count).ShouldEventually().Be(1, TimeSpan.FromSeconds(5)); using (FilteredLogFile filtered = file.AsFiltered(_scheduler, null, Filter.Create("e", LevelFlags.All), TimeSpan.Zero)) { var listener = new Mock <ILogFileListener>(); var sections = new List <LogFileSection>(); listener.Setup(x => x.OnLogFileModified(It.IsAny <ILogFile>(), It.IsAny <LogFileSection>())) .Callback((ILogFile logFile, LogFileSection section) => sections.Add(section)); filtered.AddListener(listener.Object, TimeSpan.FromHours(1), 1000); filtered.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5)); filtered.GetSection(new LogFileSection(0, filtered.Count)).Should().Equal(new[] { new LogLine(0, "INFO - Test", LevelFlags.Info) }); using (var stream = new FileStream(fname, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) { stream.SetLength(0); } filtered.Property(x => x.Count).ShouldEventually().Be(0, TimeSpan.FromSeconds(5)); filtered.Property(x => x.EndOfSourceReached).ShouldEventually().BeTrue(TimeSpan.FromSeconds(5)); sections.Should().EndWith(LogFileSection.Reset); } } }
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 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); } }