예제 #1
0
        public void TestRemoveAt()
        {
            var entries = new LogEntryList(LogFileColumns.DeltaTime);

            entries.Add(TimeSpan.FromSeconds(5));
            entries.Add(TimeSpan.FromSeconds(6));
            entries.Add(TimeSpan.FromSeconds(7));

            entries.Count.Should().Be(3);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(5));
            entries[1].DeltaTime.Should().Be(TimeSpan.FromSeconds(6));
            entries[2].DeltaTime.Should().Be(TimeSpan.FromSeconds(7));

            entries.RemoveAt(2);
            entries.Count.Should().Be(2);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(5));
            entries[1].DeltaTime.Should().Be(TimeSpan.FromSeconds(6));

            entries.RemoveAt(0);
            entries.Count.Should().Be(1);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(6));

            entries.RemoveAt(0);
            entries.Count.Should().Be(0);
        }
예제 #2
0
        public void TestGetOriginalIndicesByIndices()
        {
            var content = new LogEntryList(LogFileColumns.Timestamp);

            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 0, 0, 0)
            });
            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 0, 0, 1)
            });
            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 0, 0, 2)
            });
            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 0, 0, 3)
            });
            var logFile = CreateFromContent(content);

            var indices = new LogLineIndex[5];

            indices[0] = new LogLineIndex(42);
            indices[4] = new LogLineIndex(9001);

            logFile.GetColumn(new LogLineIndex[] { 3, 1, 2 }, LogFileColumns.OriginalIndex, indices, 1);
            indices[0].Should().Be(42, "because the original value shouldn't have been written over");
            indices[1].Should().Be(3);
            indices[2].Should().Be(1);
            indices[3].Should().Be(2);
            indices[4].Should().Be(9001, "because the original value shouldn't have been written over");
        }
예제 #3
0
        public void TestRemoveRangeInvalidIndex2([Values(3, 42)] int invalidIndex)
        {
            var entries = new LogEntryList(LogFileColumns.RawContent);

            entries.Add("foo");
            entries.Add("bar");
            entries.Count.Should().Be(2);

            new Action(() => entries.RemoveRange(invalidIndex, 1)).Should().Throw <ArgumentException>();
            entries.Count.Should().Be(2);
            entries[0].RawContent.Should().Be("foo");
            entries[1].RawContent.Should().Be("bar");
        }
예제 #4
0
        public async Task If_a_build_is_in_fly_the_second_one_will_wait_and_do_not_continue()
        {
            var buildEvents         = new LogEntryList();
            var buildEventsMessages = new List <string>();
            var package             = await Create.ConsoleWorkspaceCopy(isRebuildable : true);

            var barrier = new Barrier(2);

            using (LogEvents.Subscribe(e =>
            {
                buildEvents.Add(e);
                buildEventsMessages.Add(e.Evaluate().Message);
                if (e.Evaluate().Message.StartsWith("Attempting building package "))
                {
                    barrier.SignalAndWait(10.Minutes());
                }
            }))
            {
                await Task.WhenAll(
                    Task.Run(() => package.FullBuild()),
                    Task.Run(() => package.FullBuild()));
            }

            buildEventsMessages.Should()
            .Contain(e => e.StartsWith($"Building package {package.Name}"))
            .And
            .Contain(e => e.StartsWith($"Skipping build for package {package.Name}"));
        }
예제 #5
0
        public void TestClearMany()
        {
            var entries = new LogEntryList(LogFileColumns.LineNumber);

            entries.Add(42);
            entries.Add(9001);
            entries.Count.Should().Be(2);

            entries.Clear();
            entries.Count.Should().Be(0);

            entries.AddEmpty();
            entries.AddEmpty();
            entries.Count.Should().Be(2);
            entries[0].LineNumber.Should().Be(0);
            entries[1].LineNumber.Should().Be(0);
        }
예제 #6
0
        public When_publishing_from_ILogger_to_PocketLogger(ITestOutputHelper output)
        {
            loggerFactory = new LoggerFactory()
                            .AddConsole()
                            .AddPocketLogger();

            disposables.Add(LogEvents.Subscribe(e => output.WriteLine(e.ToLogString())));
            disposables.Add(LogEvents.Subscribe(e => log.Add(e)));
        }
예제 #7
0
        public void TestStartEndTimestamp2()
        {
            var content = new LogEntryList(LogFileColumns.Timestamp);

            content.Add(ReadOnlyLogEntry.Empty);
            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 14, 12, 0)
            });
            content.Add(ReadOnlyLogEntry.Empty);
            content.Add(new LogEntry2 {
                Timestamp = new DateTime(2017, 12, 21, 14, 13, 0)
            });
            content.Add(ReadOnlyLogEntry.Empty);
            var logFile = CreateFromContent(content);

            logFile.GetValue(LogFileProperties.StartTimestamp).Should().Be(new DateTime(2017, 12, 21, 14, 12, 0));
            logFile.GetValue(LogFileProperties.EndTimestamp).Should().Be(new DateTime(2017, 12, 21, 14, 13, 0));
        }
예제 #8
0
        public void TestAddPartialEntry()
        {
            var entries = new LogEntryList(LogFileColumns.RawContent, LogFileColumns.Timestamp);

            var logEntry = new LogEntry2();

            logEntry.Add(LogFileColumns.RawContent, "Foobar");
            entries.Add(logEntry);

            logEntry = new LogEntry2();
            logEntry.Add(LogFileColumns.Timestamp, new DateTime(2017, 12, 19, 16, 08, 0));
            entries.Add(logEntry);

            entries[0].RawContent.Should().Be("Foobar");
            entries[0].Timestamp.Should().BeNull();

            entries[1].RawContent.Should().BeNull();
            entries[1].Timestamp.Should().Be(new DateTime(2017, 12, 19, 16, 08, 0));
        }
예제 #9
0
        public void TestClearOneEntry()
        {
            var entries = new LogEntryList();

            entries.Add();
            entries.Count.Should().Be(1);

            entries.Clear();
            entries.Count.Should().Be(0);
        }
예제 #10
0
        public void TestAddOneEntry()
        {
            var entries = new LogEntryList(LogFileColumns.RawContent);

            entries.Count.Should().Be(0);

            entries.Add(ReadOnlyLogEntry.Create(new[] { LogFileColumns.RawContent },
                                                new[] { "Foobar" }));
            entries.Count.Should().Be(1);
            entries[0].RawContent.Should().Be("Foobar");
        }
예제 #11
0
        public void TestInsertEmpty2()
        {
            var entries = new LogEntryList(LogFileColumns.DeltaTime);

            entries.Add(TimeSpan.FromSeconds(10));
            entries.Count.Should().Be(1);

            entries.InsertEmpty(1);
            entries.Count.Should().Be(2);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(10));
            entries[1].DeltaTime.Should().BeNull();
        }
예제 #12
0
        public void TestInsertEmpty1()
        {
            var entries = new LogEntryList(LogFileColumns.RawContent);

            entries.Add("Foo");
            entries.Count.Should().Be(1);

            entries.InsertEmpty(1);
            entries.Count.Should().Be(2);
            entries[0].RawContent.Should().Be("Foo");
            entries[1].RawContent.Should().BeNull();
        }
예제 #13
0
        public void TestRemoveAtInvalidIndex([Values(-1, 1, 2)] int invalidIndex)
        {
            var entries = new LogEntryList(LogFileColumns.DeltaTime, LogFileColumns.RawContent);

            entries.Add(TimeSpan.FromSeconds(44), "stuff");
            entries.Count.Should().Be(1);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(44));
            entries[0].RawContent.Should().Be("stuff");

            new Action(() => entries.RemoveAt(invalidIndex)).Should().Throw <ArgumentOutOfRangeException>();
            entries.Count.Should().Be(1);
            entries[0].DeltaTime.Should().Be(TimeSpan.FromSeconds(44));
            entries[0].RawContent.Should().Be("stuff");
        }
예제 #14
0
        protected override IReadOnlyLogEntries Create(IEnumerable <IReadOnlyLogEntry> entries)
        {
            if (entries.Any())
            {
                var list = new LogEntryList(entries.First().Columns);
                foreach (var entry in entries)
                {
                    list.Add(entry);
                }
                return(list);
            }

            return(CreateEmpty(new ILogFileColumn[0]));
        }
예제 #15
0
        public void When_no_confirmation_is_required_then_IsOperationSuccessful_is_null()
        {
            var log = new LogEntryList();

            using (Subscribe(e => log.Add(e)))
                using (Log.OnExit())
                {
                }

            log.Single()
            .Operation
            .IsSuccessful
            .Should()
            .BeNull();
        }
예제 #16
0
        public void TestAddManyEntries()
        {
            const int count   = 101;
            var       entries = new LogEntryList(LogFileColumns.Index, LogFileColumns.RawContent);

            for (int i = 0; i < count; ++i)
            {
                entries.Add(new LogLineIndex(i), i.ToString());
                entries.Count.Should().Be(i + 1);
            }

            for (int i = 0; i < count; ++i)
            {
                entries[i].Index.Should().Be(i);
                entries[i].RawContent.Should().Be(i.ToString());
            }
        }
예제 #17
0
        public void TestEnumerateItems([Range(1, 10)] int count)
        {
            var entries = new LogEntryList(LogFileColumns.LineNumber);

            for (int i = 0; i < count; ++i)
            {
                entries.Add(42 + i);
            }

            int n = 0;

            foreach (var logEntry in entries)
            {
                logEntry.LineNumber.Should().Be(42 + n);

                ++n;
            }
        }
예제 #18
0
        public void Verbosity_can_be_specified()
        {
            var factory = new LoggerFactory()
                          .AddPocketLogger((category, logLevel) =>
                                           category == "awesome" ||
                                           logLevel == Microsoft.Extensions.Logging.LogLevel.Critical);

            var log = new LogEntryList();

            using (LogEvents.Subscribe(e => log.Add(e)))
            {
                factory.CreateLogger("awesome").LogInformation("this should absolutely be in the log!");

                factory.CreateLogger <string>().LogCritical("this should also be in the log");

                factory.CreateLogger <string>().LogError("this should NOT be in the log");
            }

            log.Should().HaveCount(2);
            log.Should().NotContain(e => e.LogLevel == (int)LogLevel.Error);
        }
예제 #19
0
        private void Add(ILogFile logFile, LogFileSection section)
        {
            // !!!We deliberately retrieve this section OUTSIDE of our own lock!!!
            logFile.GetEntries(section, _buffer);

            // Calculating the max width of a line takes time and is therefore done outside
            // the lock!
            var indices = new List <ILogEntry>(section.Count);

            for (var i = 0; i < section.Count; ++i)
            {
                var logEntry = _buffer[i];
                indices.Add(CreateIndex(logEntry));
            }

            lock (_syncRoot)
            {
                if (!ReferenceEquals(logFile, _source))
                {
                    // We've retrieved data from a different log file than we wanted to...
                    Log.WarnFormat("Ignoring add '{0}': It's probably from a previous log file", section);
                }
                else
                {
                    foreach (var index in indices)
                    {
                        if (_indices.Count > 0)
                        {
                            var last     = _indices[_indices.Count - 1];
                            var maxWidth = last.GetValue(LogFileColumns.PresentationStartingLineNumber) +
                                           last.GetValue(LogFileColumns.PresentationLineCount);
                            index.SetValue(LogFileColumns.PresentationStartingLineNumber, maxWidth);
                        }
                        _indices.Add(index);
                        _maxWidth   = Math.Max(_maxWidth, index.GetValue(LogFileColumns.RawContentMaxPresentationWidth));
                        _lineCount += index.GetValue(LogFileColumns.PresentationLineCount);
                    }
                }
            }
        }
예제 #20
0
        public void TestRemoveRangePartiallyInvalidRange([Values(0, 1, 2)] int index)
        {
            var entries = new LogEntryList(LogFileColumns.RawContent);

            entries.Add("f");
            entries.Add("o");
            entries.Add("o");
            entries.Add("b");
            entries.Add("a");
            entries.Add("r");
            entries.Count.Should().Be(6);

            new Action(() => entries.RemoveRange(index, 7)).Should().Throw <ArgumentException>();
            entries.Count.Should().Be(6);
            entries[0].RawContent.Should().Be("f");
            entries[1].RawContent.Should().Be("o");
            entries[2].RawContent.Should().Be("o");
            entries[3].RawContent.Should().Be("b");
            entries[4].RawContent.Should().Be("a");
            entries[5].RawContent.Should().Be("r");
        }