Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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();
            }
        }
Example #4
0
        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 });
            }
        }
Example #5
0
        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));
            }
        }
Example #6
0
        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));
            }
        }
Example #7
0
        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");
            }
        }
Example #8
0
        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");
            }
        }