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); }
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"); }
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"); }
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}")); }
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); }
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))); }
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)); }
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)); }
public void TestClearOneEntry() { var entries = new LogEntryList(); entries.Add(); entries.Count.Should().Be(1); entries.Clear(); entries.Count.Should().Be(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"); }
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(); }
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(); }
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"); }
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])); }
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(); }
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()); } }
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; } }
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); }
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); } } } }
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"); }