Beispiel #1
0
        public void TestAddEntry2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello,", LevelFlags.Info, new DateTime(2017, 4, 29, 14, 56, 0));
            logFile.AddEntry(" World!", LevelFlags.Warning, new DateTime(2017, 4, 29, 14, 56, 2));
            logFile.Count.Should().Be(2);

            var entry1 = logFile.GetEntry(0);

            entry1.Index.Should().Be(0);
            entry1.LogEntryIndex.Should().Be(0);
            entry1.LogLevel.Should().Be(LevelFlags.Info);
            entry1.RawContent.Should().Be("Hello,");
            entry1.Timestamp.Should().Be(new DateTime(2017, 4, 29, 14, 56, 0));

            var entry2 = logFile.GetEntry(1);

            entry2.Index.Should().Be(1);
            entry2.LogEntryIndex.Should().Be(1);
            entry2.LogLevel.Should().Be(LevelFlags.Warning);
            entry2.RawContent.Should().Be(" World!");
            entry2.Timestamp.Should().Be(new DateTime(2017, 4, 29, 14, 56, 2));

            logFile.GetProperty(Core.Properties.StartTimestamp).Should().Be(new DateTime(2017, 4, 29, 14, 56, 0));
            logFile.GetProperty(Core.Properties.Duration).Should().Be(TimeSpan.FromSeconds(2));
        }
        public void TestCopyFromLogFile_Contiguous()
        {
            var entries = new LogBufferList(Core.Columns.RawContent);

            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "I" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "want" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "a" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "Clondyke" }
            }));
            entries.Add(new ReadOnlyLogEntry(new Dictionary <IColumnDescriptor, object> {
                { Core.Columns.RawContent, "Bar" }
            }));

            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello", LevelFlags.Debug);
            logFile.AddEntry("World!", LevelFlags.Info);

            entries.CopyFrom(Core.Columns.RawContent, 3, logFile, new LogSourceSection(0, 2));
            entries.Count.Should().Be(5, "because the count shouldn't have been modified");
            entries[0].RawContent.Should().Be("I", "because the first entry's raw content should not have been overwritten");
            entries[1].RawContent.Should().Be("want", "because the second entry's raw content should not have been overwritten");
            entries[2].RawContent.Should().Be("a", "because the third entry's raw content should not have been overwritten");
            entries[3].RawContent.Should().Be("Hello", "because the fourth entry's raw content should have been overwritten");
            entries[4].RawContent.Should().Be("World!", "because the fifth entry's raw content should have been overwritten");
        }
Beispiel #3
0
        public void TestMerge2()
        {
            var source1 = new InMemoryLogSource();
            var source2 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = Listen(merged);

            source1.AddEntry("a", LevelFlags.Info, new DateTime(2019, 5, 28, 21, 59, 0));
            source1.AddEntry("b", LevelFlags.Debug, new DateTime(2019, 5, 28, 22, 0, 0));

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 21, 59, 0));
            entries[0].ElapsedTime.Should().Be(TimeSpan.Zero);
            entries[0].DeltaTime.Should().BeNull();
            entries[1].Index.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].RawContent.Should().Be("b");
            entries[1].LogLevel.Should().Be(LevelFlags.Debug);
            entries[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 0, 0));
            entries[1].ElapsedTime.Should().Be(TimeSpan.FromMinutes(1));
            entries[1].DeltaTime.Should().Be(TimeSpan.FromMinutes(1));
        }
Beispiel #4
0
        public void TestSelectMultipleLinesWithKeyboard5()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = logFile;
            _control.UpdateVisibleSection();
            _control.UpdateVisibleLines();

            _mouse.LeftClickAt(_control, new Point(10, 20));
            _control.SelectedIndices.Should().Equal(new LogLineIndex(1));

            var indices = new List <LogLineIndex>();

            _control.RequestBringIntoView += (index, match) => indices.Add(index);

            _keyboard.Press(Key.LeftShift);
            _keyboard.Click(_control, Key.Up);
            indices.Should().Equal(new object[] { new LogLineIndex(0) }, "because the newly selected log line should've been brought into view");

            indices.Clear();
            _keyboard.Click(_control, Key.Down);
            indices.Should().Equal(new object[] { new LogLineIndex(1) }, "because the newly selected log line should've been brought into view");
        }
Beispiel #5
0
        public void TestSelectMultipleLinesWithKeyboard1()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = 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(0)
            };
            _keyboard.Press(Key.LeftShift);
            _keyboard.Click(_control, Key.Down);

            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1));

            _keyboard.Click(_control, Key.Down);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1), new LogLineIndex(2));

            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0), new LogLineIndex(1));

            _keyboard.Click(_control, Key.Up);
            _control.SelectedIndices.Should().Equal(new LogLineIndex(0));
        }
        public void TestClear()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 053));
            source.AddEntry("B", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("C", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));

            var index = new MergedLogSourceIndex(source);

            index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 3)));

            index.Count.Should().Be(3);
            var indices = index.Get(new LogSourceSection(0, 3));

            indices[0].SourceLineIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[2].SourceLineIndex.Should().Be(2);

            index.Clear();
            index.Count.Should().Be(0);
            indices = index.Get(new LogSourceSection(0, 3));
            indices[0].SourceLineIndex.Should().Be(-1);
            indices[1].SourceLineIndex.Should().Be(-1);
            indices[2].SourceLineIndex.Should().Be(-1);
        }
        public void TestAppendTwoSourcesWrongOrderSeparateChangesPartialInvalidation()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 34, 0));
            source1.AddEntry("C", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 36, 0));
            var source2 = new InMemoryLogSource();

            source2.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 35, 0));
            source2.AddEntry("D", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 37, 0));

            var index   = new MergedLogSourceIndex(source1, source2);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 2)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 2)
            });

            changes = index.Process(new MergedLogSourcePendingModification(source2, LogSourceModification.Appended(0, 2)));
            changes.Should().Equal(new object[]
            {
                LogSourceModification.Removed(1, 1),
                LogSourceModification.Appended(1, 3)
            });
        }
Beispiel #8
0
        public void TestGetTimestampsOneSource2([Range(0, 3)] int offset)
        {
            var source  = new InMemoryLogSource();
            var logFile = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source);

            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 27, 0));
            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 28, 23));
            source.AddEntry("", LevelFlags.Other, new DateTime(2017, 12, 14, 23, 29, 1));
            int count = source.Count;

            _taskScheduler.Run(2);

            var buffer = new DateTime?[offset + count];

            for (int i = 0; i < offset + count; ++i)
            {
                buffer[i] = DateTime.MinValue;
            }

            logFile.GetColumn(new LogLineIndex[] { 2, 1 }, Core.Columns.Timestamp, buffer, offset);

            for (int i = 0; i < offset; ++i)
            {
                buffer[i].Should().Be(DateTime.MinValue, "because we've specified an offset and thus values before that offset shouldn't have been touched");
            }
            buffer[offset + 0].Should().Be(source.GetEntry(2).Timestamp);
            buffer[offset + 1].Should().Be(source.GetEntry(1).Timestamp);
        }
Beispiel #9
0
        public void TestMergeResetOneSource()
        {
            var source1 = new InMemoryLogSource();

            var source2 = new InMemoryLogSource();

            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = Listen(merged);
            var changes = ListenToChanges(merged, 100);

            source2.AddEntry("a", LevelFlags.Warning, new DateTime(2021, 2, 28, 22, 15, 0));
            source1.AddEntry("b", LevelFlags.Info, new DateTime(2021, 2, 28, 22, 16, 0));
            source2.AddEntry("c", LevelFlags.Error, new DateTime(2021, 2, 28, 22, 17, 0));

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            entries.Count.Should().Be(3);
            changes.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 3) });


            source1.Clear();
            _taskScheduler.RunOnce();
            entries.Count.Should().Be(2, "because the one entry from source should have been removed from the merged source");
            changes.Should().Equal(new object[] { LogSourceModification.Reset(), LogSourceModification.Appended(0, 3), LogSourceModification.Removed(1, 2), LogSourceModification.Appended(1, 1) });
        }
        public void TestAppendOneSourceThreeOneLinesOneWithoutTimestamp()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 19, 30, 1));
            source.AddEntry("B", LevelFlags.Other);
            source.AddEntry("C", LevelFlags.Other, new DateTime(2019, 5, 28, 19, 30, 42));

            var index   = new MergedLogSourceIndex(source);
            var changes = index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 3)));

            changes.Should().Equal(new object[] { LogSourceModification.Appended(0, 2) });

            index.Count.Should().Be(2);

            var indices = index.Get(new LogSourceSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].SourceId.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, 30, 1));

            indices[1].SourceId.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(2);
            indices[1].OriginalLogEntryIndex.Should().Be(2);
            indices[1].MergedLogEntryIndex.Should().Be(1);
            indices[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 19, 30, 42));
        }
Beispiel #11
0
        public void TestMerge4()
        {
            var source1 = new InMemoryLogSource();
            var source2 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);
            var entries = 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.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].OriginalIndex.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Warning);
            entries[0].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 40, 0));
            entries[1].Index.Should().Be(1);
            entries[1].OriginalIndex.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].RawContent.Should().Be("c");
            entries[1].LogLevel.Should().Be(LevelFlags.Error);
            entries[1].Timestamp.Should().Be(new DateTime(2019, 5, 28, 22, 41, 0));
        }
Beispiel #12
0
        public void TestSelectMultipleLinesWithKeyboard4()
        {
            var logFile = new InMemoryLogSource(_columns);

            logFile.AddEntry("Hello", LevelFlags.Other);
            logFile.AddEntry("World", LevelFlags.Other);
            logFile.AddEntry("How's it going?", LevelFlags.Other);

            _control.LogSource = logFile;
            _control.UpdateVisibleSection();
            _control.UpdateVisibleLines();

            _mouse.LeftClickAt(_control, new Point(10, 40));
            _control.SelectedIndices.Should().Equal(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));

            // We're now moving "beyond" the first item
            _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));
        }
Beispiel #13
0
        public void TestAddEntry3()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello, World!", LevelFlags.Info);
            logFile.AddEntry("Hi", LevelFlags.Info);
            logFile.GetProperty(TextProperties.MaxCharactersInLine).Should().Be(13);
        }
Beispiel #14
0
        public void TestClear2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello,", LevelFlags.Info);
            logFile.AddEntry(" World!", LevelFlags.Warning);
            logFile.Clear();
            logFile.Count.Should().Be(0);
        }
        public void TestAppendTwoSourcesInterlocked()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 0));
            source1.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 2));
            source1.AddEntry("C", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 4));
            source1.AddEntry("D", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 6));
            source1.AddEntry("E", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 8));
            var source2 = new InMemoryLogSource();

            source2.AddEntry("1", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 1));
            source2.AddEntry("2", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 3));
            source2.AddEntry("3", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 5));
            source2.AddEntry("4", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 7));
            source2.AddEntry("5", LevelFlags.Other, new DateTime(2019, 5, 29, 00, 11, 9));

            var index = new MergedLogSourceIndex(source1, source2);

            index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 5)));
            index.Process(new MergedLogSourcePendingModification(source2, LogSourceModification.Appended(0, 5)));

            var indices = index.Get(new LogSourceSection(0, 10));

            indices[0].SourceId.Should().Be(0);
            indices[0].SourceLineIndex.Should().Be(0);

            indices[1].SourceId.Should().Be(1);
            indices[1].SourceLineIndex.Should().Be(0);

            indices[2].SourceId.Should().Be(0);
            indices[2].SourceLineIndex.Should().Be(1);

            indices[3].SourceId.Should().Be(1);
            indices[3].SourceLineIndex.Should().Be(1);

            indices[4].SourceId.Should().Be(0);
            indices[4].SourceLineIndex.Should().Be(2);

            indices[5].SourceId.Should().Be(1);
            indices[5].SourceLineIndex.Should().Be(2);

            indices[6].SourceId.Should().Be(0);
            indices[6].SourceLineIndex.Should().Be(3);

            indices[7].SourceId.Should().Be(1);
            indices[7].SourceLineIndex.Should().Be(3);

            indices[8].SourceId.Should().Be(0);
            indices[8].SourceLineIndex.Should().Be(4);

            indices[9].SourceId.Should().Be(1);
            indices[9].SourceLineIndex.Should().Be(4);
        }
Beispiel #16
0
        public void TestMergeMultiline3()
        {
            var source1   = new InMemoryLogSource();
            var source1Id = new LogEntrySourceId(0);
            var source2   = new InMemoryLogSource();
            var source2Id = new LogEntrySourceId(1);
            var merged    = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source1, source2);

            var t1 = new DateTime(2017, 11, 26, 11, 45, 0);

            source1.AddEntry("Foo", LevelFlags.Info, t1);
            _taskScheduler.RunOnce();

            var t3 = new DateTime(2017, 11, 26, 11, 45, 2);

            source1.AddEntry("bar", LevelFlags.Warning, t3);
            _taskScheduler.RunOnce();

            var t2 = new DateTime(2017, 11, 26, 11, 45, 1);

            source2.AddMultilineEntry(LevelFlags.Debug, t2, "Hello,", "World!");
            _taskScheduler.RunOnce();

            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(4);
            var entries = merged.GetEntries(new LogSourceSection(0, 4));

            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(4);
            entries[0].Index.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(source1Id);
            entries[0].RawContent.Should().Be("Foo");
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(t1);
            entries[1].Index.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(source2Id);
            entries[1].RawContent.Should().Be("Hello,");
            entries[1].LogLevel.Should().Be(LevelFlags.Debug);
            entries[1].Timestamp.Should().Be(t2);
            entries[2].Index.Should().Be(2);
            entries[2].LogEntryIndex.Should().Be(1);
            entries[2].GetValue(Core.Columns.SourceId).Should().Be(source2Id);
            entries[2].RawContent.Should().Be("World!");
            entries[2].LogLevel.Should().Be(LevelFlags.Debug);
            entries[2].Timestamp.Should().Be(t2);
            entries[3].Index.Should().Be(3);
            entries[3].LogEntryIndex.Should().Be(2);
            entries[3].GetValue(Core.Columns.SourceId).Should().Be(source1Id);
            entries[3].RawContent.Should().Be("bar");
            entries[3].LogLevel.Should().Be(LevelFlags.Warning);
            entries[3].Timestamp.Should().Be(t3);
        }
Beispiel #17
0
        public void TestTwoLines()
        {
            var stream  = new MemoryStream();
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello,", LevelFlags.Other);
            logFile.AddEntry("World!", LevelFlags.Other);
            var exporter = new LogFileToStreamExporter(logFile, stream);

            new Action(() => exporter.Export()).Should().NotThrow();

            GetString(stream).Should().Be("Hello,\r\nWorld!");
        }
        public void TestOneSourceManySameTimestamps()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("A", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 053));
            source.AddEntry("B", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("C", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("D", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 100));
            source.AddEntry("E", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("F", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("G", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));
            source.AddEntry("H", LevelFlags.Other, new DateTime(2017, 9, 20, 15, 09, 02, 115));

            var index = new MergedLogSourceIndex(source);

            index.Process(new MergedLogSourcePendingModification(source, LogSourceModification.Appended(0, 8)));

            var indices = index.Get(new LogSourceSection(0, 8));

            indices[0].SourceLineIndex.Should().Be(0);
            indices[1].SourceLineIndex.Should().Be(1);
            indices[2].SourceLineIndex.Should().Be(2);
            indices[3].SourceLineIndex.Should().Be(3);
            indices[4].SourceLineIndex.Should().Be(4);
            indices[5].SourceLineIndex.Should().Be(5);
            indices[6].SourceLineIndex.Should().Be(6);
            indices[7].SourceLineIndex.Should().Be(7);
        }
Beispiel #19
0
        public void TestGetEntriesRawContent2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("foo");
            logFile.AddEntry("bar");
            logFile.AddEntry("some lazy fox");
            var entries = logFile.GetEntries(new LogSourceSection(1, 2), new[] { Core.Columns.RawContent });

            entries.Count.Should().Be(2);
            entries.Columns.Should().Equal(new object[] { Core.Columns.RawContent }, "because we've only retrieved that column");
            entries[0].RawContent.Should().Be("bar");
            entries[1].RawContent.Should().Be("some lazy fox");
        }
        public void TestExportTwoLines()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello,", LevelFlags.Other);
            logFile.AddEntry("World!", LevelFlags.Other);
            var exporter = new LogFileToFileExporter(logFile, _directory, "foo");

            exporter.FullExportFilename.Should().BeNull("because the full filename must be determined from inside Export, NOT beforehand");
            new Action(() => exporter.Export()).Should().NotThrow();
            exporter.FullExportFilename.Should().NotBeNull();
            exporter.FullExportFilename.Should().StartWith(_directory);

            GetString(exporter.FullExportFilename).Should().Be("Hello,\r\nWorld!");
        }
Beispiel #21
0
        public void TestGetLogLineIndexOfOriginalLineIndex2()
        {
            var logFile = new InMemoryLogSource();

            logFile.GetLogLineIndexOfOriginalLineIndex(0).Should().Be(LogLineIndex.Invalid);
            logFile.AddEntry("", LevelFlags.All);
            logFile.GetLogLineIndexOfOriginalLineIndex(0).Should().Be(new LogLineIndex(0));
            logFile.GetLogLineIndexOfOriginalLineIndex(1).Should().Be(LogLineIndex.Invalid);
            logFile.AddEntry("", LevelFlags.All);
            logFile.GetLogLineIndexOfOriginalLineIndex(0).Should().Be(new LogLineIndex(0));
            logFile.GetLogLineIndexOfOriginalLineIndex(1).Should().Be(new LogLineIndex(1));
            logFile.Clear();
            logFile.GetLogLineIndexOfOriginalLineIndex(0).Should().Be(LogLineIndex.Invalid);
            logFile.GetLogLineIndexOfOriginalLineIndex(1).Should().Be(LogLineIndex.Invalid);
        }
 private void AddLines(int count)
 {
     for (int i = 0; i < count; ++i)
     {
         _logSource.AddEntry("", LevelFlags.Fatal);
     }
 }
Beispiel #23
0
        public void TestMerge5()
        {
            var source0 = new InMemoryLogSource();
            var source1 = new InMemoryLogSource();

            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source0, source1);
            var entries = Listen(merged);

            var later   = new DateTime(2016, 2, 16);
            var earlier = new DateTime(2016, 2, 15);

            source0.AddEntry("a", LevelFlags.Warning, later);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);

            source1.AddEntry("c", LevelFlags.Error, earlier);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1));
            entries[0].RawContent.Should().Be("c");
            entries[0].LogLevel.Should().Be(LevelFlags.Error);
            entries[0].Timestamp.Should().Be(earlier);
            entries[1].Index.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0));
            entries[1].RawContent.Should().Be("a");
            entries[1].LogLevel.Should().Be(LevelFlags.Warning);
            entries[1].Timestamp.Should().Be(later);
        }
Beispiel #24
0
        public void TestAddMultilineEntry2()
        {
            var logFile = new InMemoryLogSource();

            logFile.AddEntry("Hello, World!", LevelFlags.Debug);
            var t1 = new DateTime(2017, 11, 26, 11, 56, 0);

            logFile.AddMultilineEntry(LevelFlags.Info, t1, "foo", "bar");
            logFile.Count.Should().Be(3);
            var entry1 = logFile.GetEntry(0);

            entry1.Index.Should().Be(0);
            entry1.LogEntryIndex.Should().Be(0);
            entry1.RawContent.Should().Be("Hello, World!");
            entry1.LogLevel.Should().Be(LevelFlags.Debug);
            entry1.Timestamp.Should().Be(null);

            var entry2 = logFile.GetEntry(1);

            entry2.Index.Should().Be(1);
            entry2.LogEntryIndex.Should().Be(1);
            entry2.RawContent.Should().Be("foo");
            entry2.LogLevel.Should().Be(LevelFlags.Info);
            entry2.Timestamp.Should().Be(t1);

            var entry3 = logFile.GetEntry(2);

            entry3.Index.Should().Be(2);
            entry3.LogEntryIndex.Should().Be(1);
            entry3.RawContent.Should().Be("bar");
            entry3.LogLevel.Should().Be(LevelFlags.Info);
            entry3.Timestamp.Should().Be(t1);
        }
        public void TestOneSourceAppendReset()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 28, 00, 34, 0));

            var index   = new MergedLogSourceIndex(source1);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 1)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 1)
            });

            changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Reset()));
            changes.Should().Equal(new object[]
            {
                LogSourceModification.Reset()
            });
            index.Count.Should().Be(0);
            index.Get(new LogSourceSection(0, 1)).Should().Equal(new object[]
            {
                MergedLogLineIndex.Invalid
            });
        }
        public void TestAppendTwoSourcesWrongOrder()
        {
            var source1 = new InMemoryLogSource();

            source1.AddEntry("B", LevelFlags.Other, new DateTime(2019, 5, 27, 23, 10, 0));
            var source2 = new InMemoryLogSource();

            source2.AddEntry("A", LevelFlags.Other, new DateTime(2019, 5, 27, 23, 09, 0));

            var index   = new MergedLogSourceIndex(source1, source2);
            var changes = index.Process(new MergedLogSourcePendingModification(source1, LogSourceModification.Appended(0, 1)),
                                        new MergedLogSourcePendingModification(source2, LogSourceModification.Appended(0, 1)));

            changes.Should().Equal(new object[]
            {
                LogSourceModification.Appended(0, 2)
            });

            var indices = index.Get(new LogSourceSection(0, 2));

            indices.Count.Should().Be(2);
            indices[0].SourceId.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].SourceId.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));
        }
Beispiel #27
0
        public void TestGetSection()
        {
            var source = new InMemoryLogSource();

            source.AddEntry("Sting");
            source.AddEntry("I'm an english man in new york");
            source.AddEntry("1987");
            using (var proxy = new LogSourceProxy(_taskScheduler, TimeSpan.Zero, source))
            {
                var entries = proxy.GetEntries(new LogSourceSection(1, 2));
                entries[0].Index.Should().Be(1);
                entries[0].RawContent.Should().Be("I'm an english man in new york");
                entries[1].Index.Should().Be(2);
                entries[1].RawContent.Should().Be("1987");
            }
        }
Beispiel #28
0
        public void TestMerge3()
        {
            var source0 = new InMemoryLogSource();
            var source1 = new InMemoryLogSource();
            var merged  = new MergedLogSource(_taskScheduler, TimeSpan.Zero, source0, source1);
            var entries = Listen(merged);

            DateTime timestamp = DateTime.Now;

            source0.AddEntry("a", LevelFlags.Info, timestamp);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);

            source1.AddEntry("b", LevelFlags.Debug, timestamp);

            _taskScheduler.RunOnce();
            merged.GetProperty(Core.Properties.PercentageProcessed).Should().Be(Percentage.HundredPercent);
            merged.GetProperty(Core.Properties.LogEntryCount).Should().Be(2);
            entries.Count.Should().Be(2);
            entries[0].Index.Should().Be(0);
            entries[0].OriginalIndex.Should().Be(0);
            entries[0].LogEntryIndex.Should().Be(0);
            entries[0].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(0));
            entries[0].RawContent.Should().Be("a");
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(timestamp);
            entries[1].Index.Should().Be(1);
            entries[1].OriginalIndex.Should().Be(1);
            entries[1].LogEntryIndex.Should().Be(1);
            entries[1].GetValue(Core.Columns.SourceId).Should().Be(new LogEntrySourceId(1));
            entries[1].RawContent.Should().Be("b");
            entries[1].LogLevel.Should().Be(LevelFlags.Debug);
            entries[1].Timestamp.Should().Be(timestamp);
        }
Beispiel #29
0
        public void TestGetEntriesRandomAccess()
        {
            var logFile = new InMemoryLogSource();

            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));

            var entries = logFile.GetEntries(new LogSourceSection(1, 2), new IColumnDescriptor[] { Core.Columns.LogLevel, Core.Columns.Timestamp });

            entries.Count.Should().Be(2);
            entries.Columns.Should().Equal(new object[] { Core.Columns.LogLevel, Core.Columns.Timestamp });
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(null);
            entries[1].LogLevel.Should().Be(LevelFlags.Error);
            entries[1].Timestamp.Should().Be(new DateTime(2017, 12, 12, 00, 12, 0));
        }
Beispiel #30
0
        public void TestGetEntriesWithMinimumColumns()
        {
            var logFile = new InMemoryLogSource();

            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));

            var entries = logFile.GetEntries(new LogSourceSection(1, 2), Core.Columns.Minimum);

            entries.Count.Should().Be(2);
            entries.Columns.Should().Equal(Core.Columns.Minimum);
            entries[0].LogLevel.Should().Be(LevelFlags.Info);
            entries[0].Timestamp.Should().Be(null);
            entries[1].LogLevel.Should().Be(LevelFlags.Error);
            entries[1].Timestamp.Should().Be(new DateTime(2017, 12, 12, 00, 12, 0));
        }