private Mock <IDataSource> CreateDataSource() { var dataSource = new Mock <IDataSource>(); var activeFilters = new HashSet <QuickFilterId>(); dataSource.Setup(x => x.ActivateQuickFilter(It.IsAny <QuickFilterId>())) .Callback( (QuickFilterId id) => { activeFilters.Add(id); }); dataSource.Setup(x => x.DeactivateQuickFilter(It.IsAny <QuickFilterId>())) .Returns((QuickFilterId id) => activeFilters.Remove(id)); dataSource.Setup(x => x.IsQuickFilterActive(It.IsAny <QuickFilterId>())) .Returns((QuickFilterId id) => activeFilters.Contains(id)); var logFile = new InMemoryLogFile(); dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile); dataSource.Setup(x => x.FilteredLogFile).Returns(logFile); return(dataSource); }
public void TestUpdate2() { var model = new LogViewMainPanelViewModel(_actionCenter.Object, _dataSources.Object, _quickFilters.Object, _settings.Object); var dataSourceViewModel = new Mock <IDataSourceViewModel>(); var dataSource = new Mock <IDataSource>(); var logFile = new InMemoryLogFile(); dataSource.Setup(x => x.UnfilteredLogFile).Returns(logFile); var filteredLogFile = new InMemoryLogFile(); dataSource.Setup(x => x.FilteredLogFile).Returns(filteredLogFile); dataSourceViewModel.Setup(x => x.DataSource).Returns(dataSource.Object); model.CurrentDataSource = dataSourceViewModel.Object; logFile.AddEntry("", LevelFlags.All); logFile.SetValue(LogFileProperties.Size, Size.OneByte); model.Update(); model.CurrentDataSourceLogView.NoEntriesExplanation.Should().Be("Not a single log entry matches the level selection"); }
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 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 TestSelectMultipleLinesWithKeyboard3() { var logFile = new InMemoryLogFile(); logFile.AddEntry("Hello", LevelFlags.Other); logFile.AddEntry("World", LevelFlags.Other); logFile.AddEntry("How's it going?", LevelFlags.Other); _control.LogFile = logFile; _control.UpdateVisibleSection(); _control.UpdateVisibleLines(); _mouse.LeftClickAt(_control, new Point(10, 24)); _control.SelectedIndices.Should().Equal(new LogLineIndex(1)); _keyboard.Press(Key.LeftShift); _keyboard.Click(_control, Key.Down); _control.SelectedIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(2)); }
public void TestMerge4() { var source1 = new InMemoryLogFile(); var source2 = new InMemoryLogFile(); var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, source1, source2); var data = Listen(merged); source1.AddEntry("a", LevelFlags.Warning, new DateTime(2019, 5, 28, 22, 40, 0)); source1.AddEntry("b", LevelFlags.Info); source1.AddEntry("c", LevelFlags.Error, new DateTime(2019, 5, 28, 22, 41, 0)); _taskScheduler.RunOnce(); merged.Count.Should().Be(2); data.Should().Equal(new object[] { new LogLine(0, 0, 0, "a", LevelFlags.Warning, new DateTime(2019, 5, 28, 22, 40, 0)), new LogLine(1, 1, 1, "c", LevelFlags.Error, new DateTime(2019, 5, 28, 22, 41, 0)) }); }
public void TestOneSourceResetAndAppend() { var source1 = new InMemoryLogFile(); source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 34, 0)); var index = new MergedLogFileIndex(source1); var changes = index.Process( new MergedLogFilePendingModification(source1, new LogFileSection(0, 2)), new MergedLogFilePendingModification(source1, LogFileSection.Reset), new MergedLogFilePendingModification(source1, new LogFileSection(0, 1)) ); changes.Should().Equal(new object[] { new LogFileSection(0, 1) }, "because the index shouldn't process changes belonging to source1 prior to the last reset"); index.Count.Should().Be(1); }
public void TestGetEntriesWithElapsedTimeColumns() { var logFile = new InMemoryLogFile(); logFile.AddEntry("", LevelFlags.Info); logFile.AddEntry("", LevelFlags.Debug, new DateTime(2017, 12, 12, 00, 11, 0)); logFile.AddEntry("", LevelFlags.Info); logFile.AddEntry("", LevelFlags.Error, new DateTime(2017, 12, 12, 00, 12, 0)); logFile.AddEntry("", LevelFlags.Error, new DateTime(2017, 12, 20, 17, 01, 0)); var entries = logFile.GetEntries(new LogFileSection(0, 5), LogFileColumns.ElapsedTime); entries.Count.Should().Be(5); entries.Columns.Should().Equal(LogFileColumns.ElapsedTime); entries[0].ElapsedTime.Should().Be(null); entries[1].ElapsedTime.Should().Be(null); entries[2].ElapsedTime.Should().Be(null); entries[3].ElapsedTime.Should().Be(TimeSpan.FromMinutes(1)); entries[4].ElapsedTime.Should().Be(TimeSpan.FromDays(8) + TimeSpan.FromHours(16) + TimeSpan.FromMinutes(50)); }
public void TestClearScreenShowAll() { var settings = CreateDataSource(); var logFile = new InMemoryLogFile(); logFile.AddEntry("Foo"); logFile.AddEntry("Bar"); using (var dataSource = new SingleDataSource(_scheduler, settings, logFile, TimeSpan.Zero)) { _scheduler.RunOnce(); dataSource.ClearScreen(); _scheduler.RunOnce(); dataSource.FilteredLogFile.Count.Should().Be(0, "because we've just cleared the screen"); dataSource.ShowAll(); _scheduler.RunOnce(); dataSource.FilteredLogFile.Count.Should().Be(2, "because we've just shown everything again"); } }
public void TestGetTimestamp4() { var source = new InMemoryLogFile(); var timestamp1 = new DateTime(2017, 12, 11, 20, 33, 0); source.AddEntry("", LevelFlags.Debug, timestamp1); var timestamp2 = new DateTime(2017, 12, 11, 20, 34, 0); source.AddEntry("", LevelFlags.Debug, timestamp2); source.AddEntry("", LevelFlags.None); var logFile = new MultiLineLogFile(_taskScheduler, source, TimeSpan.Zero); var timestamps = logFile.GetColumn(new LogFileSection(1, 2), LogFileColumns.Timestamp); timestamps.Should().NotBeNull(); timestamps.Should().Equal(new object[] { timestamp2, timestamp2 }); }
public void TestManySources2() { const int sourceCount = 100; var sources = new InMemoryLogFile[sourceCount]; for (int i = 0; i < sourceCount; ++i) { sources[i] = new InMemoryLogFile(); } var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, sources); var end = new DateTime(2017, 11, 26, 17, 56, 0); for (int i = 0; i < sourceCount; ++i) { // Sources are modified in reverse order: This is the worst case. // Reality is somewhere in between... sources[i].AddEntry(i.ToString(), LevelFlags.Info, end - TimeSpan.FromSeconds(i)); } var changes = ListenToChanges(merged, sourceCount); _taskScheduler.RunOnce(); // For once, we expect the content of the merged data source to be as expected... merged.Count.Should().Be(sourceCount, "because every source added one line"); for (int i = 0; i < sourceCount; ++i) { int idx = sourceCount - i - 1; merged.GetLine(i).Should().Be(new LogLine(i, i, new LogLineSourceId((byte)idx), idx.ToString(), LevelFlags.Info, end - TimeSpan.FromSeconds(idx))); } // But then it should also have fired as few changes as possible! changes.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, sourceCount) }); }
public void TestSelectMultipleLines2() { var logFile = new InMemoryLogFile(); logFile.AddEntry("Hello", LevelFlags.None); logFile.AddEntry("World", LevelFlags.None); _control.LogFile = logFile; _control.UpdateVisibleSection(); _control.UpdateVisibleLines(); _control.SelectedIndices.Should().BeEmpty(); _mouse.LeftClickAt(_control, new Point(20, 8)); _control.SelectedIndices.Should().Equal(new LogLineIndex(0)); _mouse.LeftClickAt(_control, new Point(20, 24)); _control.SelectedIndices.Should().Equal(new LogLineIndex(1)); }
public void TestExportTwice() { var logFile = new InMemoryLogFile(); logFile.AddEntry("Hello", LevelFlags.Other); var exporter1 = new LogFileToFileExporter(logFile, _directory, "foo"); exporter1.Export(); logFile.AddEntry("World!", LevelFlags.Other); var exporter2 = new LogFileToFileExporter(logFile, _directory, "foo"); new Action(() => exporter2.Export()).Should().NotThrow(); exporter1.FullExportFilename.Should() .NotBe(exporter2.FullExportFilename, "because previous exports should not be overwritten"); GetString(exporter1.FullExportFilename).Should().Be("Hello"); GetString(exporter2.FullExportFilename).Should().Be("Hello\r\nWorld!"); }
public void TestSelectOneLine1() { var logFile = new InMemoryLogFile(); logFile.AddEntry("Hello", LevelFlags.None); logFile.AddEntry("World", LevelFlags.None); _control.LogFile = logFile; _control.UpdateVisibleSection(); _control.UpdateVisibleLines(); _control.SelectedIndices.Should().BeEmpty(); _mouse.MoveRelativeTo(_control, new Point(20, 8)); _control.RaiseEvent(new MouseButtonEventArgs(Mouse.PrimaryDevice, Environment.TickCount, MouseButton.Left) { RoutedEvent = UIElement.MouseLeftButtonDownEvent }); _control.SelectedIndices.Should().Equal(new LogLineIndex(0)); }
public void TestManySources1() { const int sourceCount = 100; var sources = new InMemoryLogFile[sourceCount]; for (int i = 0; i < sourceCount; ++i) { sources[i] = new InMemoryLogFile(); } var merged = new MergedLogFile(_taskScheduler, TimeSpan.Zero, sources); var start = new DateTime(2017, 11, 26, 17, 56, 0); for (int i = 0; i < sourceCount; ++i) { // Sources are modified in order with perfectly ascending timestamps: // This is a rather unrealistic scenario... sources[i].AddEntry(i.ToString(), LevelFlags.Info, start + TimeSpan.FromSeconds(i)); } var changes = ListenToChanges(merged, sourceCount); _taskScheduler.RunOnce(); // For once, we expect the content of the merged data source to be as expected... merged.Count.Should().Be(sourceCount, "because every source added one line"); for (byte i = 0; i < sourceCount; ++i) { merged.GetLine(i).Should().Be(new LogLine(i, i, new LogLineSourceId(i), i.ToString(), LevelFlags.Info, start + TimeSpan.FromSeconds(i))); } // But then it should also have fired as few changes as possible! changes.Should().Equal(new object[] { LogFileSection.Reset, new LogFileSection(0, sourceCount) }); }
public void TestGetTimestampByIndices() { var source = new InMemoryLogFile(); var timestamp1 = new DateTime(2017, 12, 11, 20, 33, 0); source.AddEntry("", LevelFlags.Debug, timestamp1); var timestamp2 = new DateTime(2017, 12, 11, 20, 34, 0); source.AddEntry("", LevelFlags.Debug, timestamp2); source.AddEntry("", LevelFlags.Other); var logFile = new MultiLineLogFile(_taskScheduler, source, TimeSpan.Zero); _taskScheduler.RunOnce(); var timestamps = logFile.GetColumn(new LogLineIndex[] { 0, 1, 2 }, LogFileColumns.Timestamp); timestamps.Should().NotBeNull(); timestamps.Should().Equal(new object[] { timestamp1, timestamp2, timestamp2 }); }
public void TestSelectMultipleLinesWithKeyboard2() { var logFile = new InMemoryLogFile(); logFile.AddEntry("Hello", LevelFlags.None); logFile.AddEntry("World", LevelFlags.None); logFile.AddEntry("How's", LevelFlags.None); logFile.AddEntry("it", LevelFlags.None); logFile.AddEntry("going?", LevelFlags.None); _control.LogFile = logFile; _control.UpdateVisibleSection(); _control.UpdateVisibleLines(); // This time we'll do the first selection programatically (which happens when // switching between data sources, for example) _control.SelectedIndices = new List <LogLineIndex> { new LogLineIndex(2) }; _keyboard.Press(Key.LeftShift); _keyboard.Click(_control, Key.Up); _control.SelectedIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(2)); _keyboard.Click(_control, Key.Up); _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1), new LogLineIndex(2)); _keyboard.Click(_control, Key.Down); _control.SelectedIndices.Should().Equal(new LogLineIndex(1), new LogLineIndex(2)); _keyboard.Click(_control, Key.Down); _control.SelectedIndices.Should().Equal(new LogLineIndex(2)); _keyboard.Click(_control, Key.Down); _control.SelectedIndices.Should().Equal(new LogLineIndex(2), new LogLineIndex(3)); _keyboard.Click(_control, Key.Down); _control.SelectedIndices.Should().Equal(new LogLineIndex(2), new LogLineIndex(3), new LogLineIndex(4)); }
public void TestAppendTwoSourcesWrongOrderSeparateChangesFullInvalidation() { var source1 = new InMemoryLogFile(); source1.AddEntry("B", LevelFlags.None, new DateTime(2019, 5, 27, 23, 10, 0)); var source2 = new InMemoryLogFile(); source2.AddEntry("A", LevelFlags.None, new DateTime(2019, 5, 27, 23, 09, 0)); var index = new MergedLogFileIndex(source1, source2); var changes = index.Process(new MergedLogFilePendingModification(source1, new LogFileSection(0, 1))); changes.Should().Equal(new object[] { new LogFileSection(0, 1) }); changes = index.Process(new MergedLogFilePendingModification(source2, new LogFileSection(0, 1))); changes.Should().Equal(new object[] { LogFileSection.Invalidate(0, 1), new LogFileSection(0, 2) }); var indices = index.Get(new LogFileSection(0, 2)); indices.Count.Should().Be(2); indices[0].LogFileIndex.Should().Be(1); indices[0].SourceLineIndex.Should().Be(0); indices[0].OriginalLogEntryIndex.Should().Be(0); indices[0].MergedLogEntryIndex.Should().Be(0); indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 9, 0)); indices[1].LogFileIndex.Should().Be(0); indices[1].SourceLineIndex.Should().Be(0); indices[1].OriginalLogEntryIndex.Should().Be(0); indices[1].MergedLogEntryIndex.Should().Be(1); indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 27, 23, 10, 0)); }
public void TestAppendOneSourceOneLine() { var source = new InMemoryLogFile(); source.AddEntry("Hello, World!", LevelFlags.None, new DateTime(2019, 5, 28, 19, 55, 10)); var index = new MergedLogFileIndex(source); var changes = index.Process(new MergedLogFilePendingModification(source, new LogFileSection(0, 1))); changes.Should().Equal(new object[] { new LogFileSection(0, 1) }); var indices = index.Get(new LogFileSection(0, 1)); indices.Count.Should().Be(1); indices[0].LogFileIndex.Should().Be(0); indices[0].SourceLineIndex.Should().Be(0); indices[0].OriginalLogEntryIndex.Should().Be(0); indices[0].MergedLogEntryIndex.Should().Be(0); indices[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 55, 10)); }
public void TestClearScreen() { var settings = CreateDataSource(); var logFile = new InMemoryLogFile(); logFile.AddEntry("Foo"); logFile.AddEntry("Bar"); using (var dataSource = new SingleDataSource(_scheduler, settings, logFile, TimeSpan.Zero)) { _scheduler.RunOnce(); dataSource.FilteredLogFile.Count.Should().Be(2); dataSource.ClearScreen(); _scheduler.RunOnce(); dataSource.FilteredLogFile.Count.Should().Be(0, "because we've just cleared the screen"); logFile.AddEntry("Hello!"); _scheduler.Run(2); dataSource.FilteredLogFile.Count.Should().Be(1, "because newer log entries should still appear"); dataSource.FilteredLogFile.GetLine(0).Message.Should().Be("Hello!"); } }
public void TestPartialInvalidate() { var logFile = new InMemoryLogFile(); var index = new PresentationLogFile(_scheduler, logFile, TimeSpan.Zero); logFile.Add(new LogEntry2 { RawContent = "Foo" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(19.8, 0.1); index.LineCount.Should().Be(1); logFile.Add(new LogEntry2 { RawContent = "Hello,\r\nWorld!" }); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(46.2, 0.1); index.LineCount.Should().Be(3); logFile.RemoveFrom(1); _scheduler.RunOnce(); index.MaximumWidth.Should().BeApproximately(19.8, 0.1); index.LineCount.Should().Be(1); }
public void Setup() { _scheduler = new ManualTaskScheduler(); _source = new InMemoryLogFile(); }
protected override ILogFile CreateEmpty() { var source = new InMemoryLogFile(); return(new MultiLineLogFile(_taskScheduler, source, TimeSpan.Zero)); }
protected override ILogFile CreateFromContent(IReadOnlyLogEntries content) { var source = new InMemoryLogFile(content); return(new NoThrowLogFile(source, "")); }
protected override ILogFile CreateEmpty() { var source = new InMemoryLogFile(); return(new NoThrowLogFile(source, "")); }
public void TestTimestampsAndMixedInfos() { var logFile = new InMemoryLogFile(); using (var multiLine = new MultiLineLogFile(_taskScheduler, logFile, TimeSpan.Zero)) { 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.Other, RawContent = "2017-03-24 11-45-21.708485; 0; 0; 0; 109; 0; 125; 1;PB_CREATE; ; ; 109; 2;" } }); _taskScheduler.RunOnce(); multiLine.Count.Should().Be(3); var line0 = multiLine.GetLine(0); line0.OriginalLineIndex.Should().Be(0); line0.LineIndex.Should().Be(0); line0.LogEntryIndex.Should().Be(0, "because every line is an individual log entry"); var line1 = multiLine.GetLine(1); line1.OriginalLineIndex.Should().Be(1); line1.LineIndex.Should().Be(1); line1.LogEntryIndex.Should().Be(1, "because every line is an individual log entry"); var line2 = multiLine.GetLine(2); line2.OriginalLineIndex.Should().Be(2); line2.LineIndex.Should().Be(2); line2.LogEntryIndex.Should().Be(2, "because every line is an individual log entry"); logFile.RemoveFrom(new LogLineIndex(2)); logFile.AddRange(new [] { new LogEntry2 { Timestamp = new DateTime(2017, 3, 24, 11, 45, 21, 708), LogLevel = LevelFlags.Other, 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(); multiLine.Count.Should().Be(5); line0 = multiLine.GetLine(0); line0.OriginalLineIndex.Should().Be(0); line0.LineIndex.Should().Be(0); line0.LogEntryIndex.Should().Be(0, "because every line is an individual log entry"); line1 = multiLine.GetLine(1); line1.OriginalLineIndex.Should().Be(1); line1.LineIndex.Should().Be(1); line1.LogEntryIndex.Should().Be(1, "because every line is an individual log entry"); line2 = multiLine.GetLine(2); line2.OriginalLineIndex.Should().Be(2); line2.LineIndex.Should().Be(2); line2.LogEntryIndex.Should().Be(2, "because every line is an individual log entry"); var line3 = multiLine.GetLine(3); line3.OriginalLineIndex.Should().Be(3); line3.LineIndex.Should().Be(3); line3.LogEntryIndex.Should().Be(3, "because every line is an individual log entry"); var line4 = multiLine.GetLine(4); line4.OriginalLineIndex.Should().Be(4); line4.LineIndex.Should().Be(4); line4.LogEntryIndex.Should().Be(4, "because every line is an individual log entry"); } }
public void TestGetEntriesEmpty() { var logFile = new InMemoryLogFile(); logFile.GetEntries(new LogFileSection()).Should().BeEmpty("because the log file is empty"); }
protected override ILogFile CreateFromContent(IReadOnlyLogEntries content) { var logFile = new InMemoryLogFile(content); return(logFile); }
public void Setup() { _column = new Tailviewer.Ui.Controls.LogView.LineNumbers.OriginalLineNumberColumnPresenter(); _logFile = new InMemoryLogFile(); }
public void TestConstruction2() { var logFile = new InMemoryLogFile(LogFileColumns.ElapsedTime); logFile.Columns.Should().Equal(LogFileColumns.Minimum, "because a log file should never offer less columns than the minimum set"); }