public void TestCopyToByIndices([Range(0, 2)] int destinationIndex) { var entries = Enumerable.Range(0, 5) .Select(i => ReadOnlyLogEntry.Create(new[] { LogFileColumns.DeltaTime }, new object[] { TimeSpan.FromSeconds(i) })); var source = Create(entries); var dest = new TimeSpan?[destinationIndex + 4]; for (int i = 0; i < destinationIndex; ++i) { dest[i] = TimeSpan.FromTicks(42); } var sourceIndices = new[] { 4, 1, 2, 3 }; source.CopyTo(LogFileColumns.DeltaTime, sourceIndices, dest, destinationIndex); for (int i = 0; i < destinationIndex; ++i) { dest[i].Should().Be(TimeSpan.FromTicks(42)); } dest[destinationIndex + 0].Should().Be(source[4].DeltaTime); dest[destinationIndex + 1].Should().Be(source[1].DeltaTime); dest[destinationIndex + 2].Should().Be(source[2].DeltaTime); dest[destinationIndex + 3].Should().Be(source[3].DeltaTime); }
public void TestCopyToRange([Range(0, 2)] int sourceIndex, [Range(0, 2)] int destinationIndex, [Range(1, 2)] int count) { var entries = Enumerable.Range(0, sourceIndex + count).Select(i => ReadOnlyLogEntry.Create(new[] { LogFileColumns.DeltaTime }, new object[] { TimeSpan.FromSeconds(i) })); var buffer = Create(entries); var dest = new TimeSpan?[destinationIndex + count]; for (int i = 0; i < destinationIndex; ++i) { dest[i] = TimeSpan.FromTicks(42); } buffer.CopyTo(LogFileColumns.DeltaTime, sourceIndex, dest, destinationIndex, count); for (int i = 0; i < destinationIndex; ++i) { dest[i].Should().Be(TimeSpan.FromTicks(42)); } for (int i = 0; i < count; ++i) { var actual = dest[destinationIndex + i]; var expected = buffer[sourceIndex + i].DeltaTime; actual.Should().Be(expected); } }
public void TestInsertOneEntry() { var entries = new LogEntryList(LogFileColumns.DeltaTime); entries.Insert(0, ReadOnlyLogEntry.Create(new[] { LogFileColumns.DeltaTime }, new object[] { TimeSpan.FromHours(22) })); entries.Count.Should().Be(1); entries[0].DeltaTime.Should().Be(TimeSpan.FromHours(22)); }
public void TestInsertInvalidIndex([Values(-2, -1, 1, 42)] int invalidIndex) { var entries = new LogEntryList(LogFileColumns.ElapsedTime); var logEntry = ReadOnlyLogEntry.Create(new[] { LogFileColumns.ElapsedTime }, new object[] { TimeSpan.FromHours(22) }); new Action(() => entries.Insert(invalidIndex, logEntry)) .Should().Throw <ArgumentOutOfRangeException>(); 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 TestCopyToPartiallyInvalidSourceIndices() { var entry = ReadOnlyLogEntry.Create(new[] { LogFileColumns.RawContent }, new[] { "bar" }); var buffer = Create(entry); var destination = new[] { "foo", "stuff" }; new Action(() => buffer.CopyTo(LogFileColumns.RawContent, new[] { -1, 0 }, destination, 0)) .Should().NotThrow(); destination[0].Should().BeNull(); destination[1].Should().Be("bar"); }
public void TestAccessNotRetrievedColumn() { var entry = ReadOnlyLogEntry.Create(new[] { LogFileColumns.RawContent }, new[] { "Foo" }); var entries = Create(entry); var actualEntry = entries.First(); actualEntry.RawContent.Should().Be("Foo"); new Action(() => { var unused = actualEntry.Timestamp; }).Should().Throw <ColumnNotRetrievedException>(); }
public void TestCopyToRangeInvalidSourceIndex3() { var entry = ReadOnlyLogEntry.Create(new[] { LogFileColumns.RawContent }, new[] { "stuff" }); var buffer = Create(entry); var destination = new[] { "f", "o", "o" }; new Action(() => buffer.CopyTo(LogFileColumns.RawContent, -1, destination, 0, 3)) .Should().NotThrow(); destination[0].Should().BeNull("because the first index we access (-1) isn't valid and thus should be served with null"); destination[1].Should().Be("stuff"); destination[2].Should().BeNull("because the last index we access (1) isn't valid and thus should be served with null"); }
public void TestAccessAllColumnsByLogEntry() { var columns = new List <ILogFileColumn>(); var values = new List <object>(); columns.Add(LogFileColumns.RawContent); values.Add("Foo"); columns.Add(LogFileColumns.DeltaTime); values.Add(TimeSpan.FromSeconds(10)); columns.Add(LogFileColumns.ElapsedTime); values.Add(TimeSpan.FromDays(44)); columns.Add(LogFileColumns.Index); values.Add(new LogLineIndex(10)); columns.Add(LogFileColumns.OriginalIndex); values.Add(new LogLineIndex(9001)); columns.Add(LogFileColumns.LineNumber); values.Add(5); columns.Add(LogFileColumns.OriginalLineNumber); values.Add(7); columns.Add(LogFileColumns.LogEntryIndex); values.Add(new LogEntryIndex(1)); columns.Add(LogFileColumns.Timestamp); values.Add(new DateTime(2017, 12, 19, 12, 45, 33)); columns.Add(LogFileColumns.LogLevel); values.Add(LevelFlags.Error); var entry = ReadOnlyLogEntry.Create(columns, values); var logEntries = Create(entry); var actualEntry = logEntries.First(); actualEntry.RawContent.Should().Be("Foo"); actualEntry.DeltaTime.Should().Be(TimeSpan.FromSeconds(10)); actualEntry.ElapsedTime.Should().Be(TimeSpan.FromDays(44)); actualEntry.Index.Should().Be(10); actualEntry.OriginalIndex.Should().Be(9001); actualEntry.LineNumber.Should().Be(5); actualEntry.OriginalLineNumber.Should().Be(7); actualEntry.LogEntryIndex.Should().Be(1); actualEntry.Timestamp.Should().Be(new DateTime(2017, 12, 19, 12, 45, 33)); actualEntry.LogLevel.Should().Be(LevelFlags.Error); }
public void TestReuseEnumerator() { var entry = ReadOnlyLogEntry.Create(new[] { LogFileColumns.RawContent }, new[] { "Foo" }); var entries = Create(entry); using (var enumerator = entries.GetEnumerator()) { enumerator.MoveNext().Should().BeTrue(); enumerator.Current.RawContent.Should().Be("Foo"); enumerator.MoveNext().Should().BeFalse(); enumerator.Reset(); enumerator.MoveNext().Should().BeTrue(); enumerator.Current.RawContent.Should().Be("Foo"); enumerator.MoveNext().Should().BeFalse(); } }