public void TestCopyFromMultipleColumns() { var buffer = new LogEntryBuffer(2, LogFileColumns.Index, LogFileColumns.Timestamp); buffer.CopyFrom(LogFileColumns.Index, new LogLineIndex[] { 1, 42 }); buffer.CopyFrom(LogFileColumns.Timestamp, new DateTime?[] { DateTime.MinValue, DateTime.MaxValue }); buffer[0].Index.Should().Be(1); buffer[0].Timestamp.Should().Be(DateTime.MinValue); buffer[1].Index.Should().Be(42); buffer[1].Timestamp.Should().Be(DateTime.MaxValue); }
public void TestCopyFromNullColumn() { var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp); new Action(() => buffer.CopyFrom(null, 0, new string[0], 0, 0)) .ShouldThrow <ArgumentNullException>(); }
public void TestCopyFromUnknownColumn() { var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp); new Action(() => buffer.CopyFrom(LogFileColumns.RawContent, 0, new string[0], 0, 0)) .ShouldThrow <NoSuchColumnException>(); }
public void TestCopyFrom() { var buffer = new LogEntryBuffer(1, LogFileColumns.Timestamp); var timestamp = new DateTime(2017, 12, 11, 21, 41, 0); buffer.CopyFrom(LogFileColumns.Timestamp, new DateTime?[] { timestamp }); buffer[0].Timestamp.Should().Be(timestamp, "Because we've just copied this timestamp to the buffer"); }
public void TestCopyFromPartial3() { var buffer = new LogEntryBuffer(2, LogFileColumns.Timestamp); var timestamp = new DateTime(2017, 12, 11, 21, 41, 0); buffer.CopyFrom(LogFileColumns.Timestamp, 1, new DateTime?[] { timestamp }, 0, 1); buffer[0].Timestamp.Should().BeNull("because we didn't copy any data for this timestamp"); buffer[1].Timestamp.Should().Be(timestamp, "Because we've just copied this timestamp to the buffer"); }
public void TestCopyFromOverwrite() { var buffer = new LogEntryBuffer(2, LogFileColumns.RawContent); buffer[0].RawContent.Should().BeNull(); buffer[1].RawContent.Should().BeNull(); buffer.CopyFrom(LogFileColumns.RawContent, new [] { "foo", "bar" }); buffer[0].RawContent.Should().Be("foo"); buffer[1].RawContent.Should().Be("bar"); }
public void TestCopyFromManyRows() { const int count = 1000; var buffer = new LogEntryBuffer(count, LogFileColumns.OriginalIndex); buffer.CopyFrom(LogFileColumns.OriginalIndex, Enumerable.Range(0, count).Select(i => (LogLineIndex)i).ToArray()); for (int i = 0; i < count; ++i) { buffer[i].OriginalIndex.Should().Be(i); } }
public void TestFillAllColumns2() { var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime, LogFileColumns.Timestamp); var deltas = new TimeSpan?[] { TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(5), TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(10) }; buffer.CopyFrom(LogFileColumns.DeltaTime, deltas); var timestamps = new DateTime?[] { new DateTime(2017, 12, 12, 19, 24, 0), new DateTime(2017, 12, 12, 19, 25, 0), new DateTime(2017, 12, 12, 19, 26, 0), new DateTime(2017, 12, 12, 19, 27, 0) }; buffer.CopyFrom(LogFileColumns.Timestamp, timestamps); buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1)); buffer[0].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 24, 0)); buffer[1].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(5)); buffer[1].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 25, 0)); buffer[2].DeltaTime.Should().Be(TimeSpan.FromSeconds(3)); buffer[2].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 26, 0)); buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10)); buffer[3].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 27, 0)); buffer.FillDefault(1, 2); buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1)); buffer[0].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 24, 0)); buffer[1].DeltaTime.Should().BeNull(); buffer[1].Timestamp.Should().BeNull(); buffer[2].DeltaTime.Should().BeNull(); buffer[2].Timestamp.Should().BeNull(); buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10)); buffer[3].Timestamp.Should().Be(new DateTime(2017, 12, 12, 19, 27, 0)); }
public void TestFillDefault3() { var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime); var data = new TimeSpan?[] { TimeSpan.FromMilliseconds(1), TimeSpan.FromMilliseconds(5), TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(10) }; buffer.CopyFrom(LogFileColumns.DeltaTime, data); buffer.FillDefault(LogFileColumns.DeltaTime, 1, 2); buffer[0].DeltaTime.Should().Be(TimeSpan.FromMilliseconds(1)); buffer[1].DeltaTime.Should().Be(null); buffer[2].DeltaTime.Should().Be(null); buffer[3].DeltaTime.Should().Be(TimeSpan.FromSeconds(10)); }
public void TestFillDefault2([Range(0, 10)] int length) { var buffer = new LogEntryBuffer(length, LogFileColumns.Timestamp); var data = Enumerable.Range(0, length).Select(unused => (DateTime?)new DateTime(2017, 12, 12, 18, 58, 0)).ToArray(); buffer.CopyFrom(LogFileColumns.Timestamp, data); for (int i = 0; i < length; ++i) { buffer[i].Timestamp.Should().Be(new DateTime(2017, 12, 12, 18, 58, 0)); } buffer.FillDefault(LogFileColumns.Timestamp, 0, length); for (int i = 0; i < length; ++i) { buffer[i].Timestamp.Should().BeNull(); } }
public void TestFillDefault1([Range(0, 10)] int length) { var buffer = new LogEntryBuffer(length, LogFileColumns.RawContent); var data = Enumerable.Range(0, length).Select(unused => "Foo").ToArray(); buffer.CopyFrom(LogFileColumns.RawContent, data); for (int i = 0; i < length; ++i) { buffer[i].RawContent.Should().Be("Foo"); } buffer.FillDefault(LogFileColumns.RawContent, 0, length); for (int i = 0; i < length; ++i) { buffer[i].RawContent.Should().BeNull(); } }
public void TestColumn() { var buffer = new LogEntryBuffer(4, LogFileColumns.DeltaTime, LogFileColumns.Timestamp); buffer.Column(LogFileColumns.DeltaTime).Should().Equal(new object[] { null, null, null, null }); buffer.CopyFrom(LogFileColumns.DeltaTime, 0, new TimeSpan?[] { TimeSpan.FromDays(1), TimeSpan.FromSeconds(42), null, TimeSpan.FromMinutes(-10) }, 0, 4); buffer.Column(LogFileColumns.DeltaTime).Should().Equal(new object[] { TimeSpan.FromDays(1), TimeSpan.FromSeconds(42), null, TimeSpan.FromMinutes(-10) }); }
public void TestGetElapsedTimesBySection() { var content = new LogEntryBuffer(5, LogFileColumns.Timestamp); content.CopyFrom(LogFileColumns.Timestamp, new DateTime?[] { new DateTime(2017, 12, 19, 15, 49, 0), new DateTime(2017, 12, 19, 15, 49, 2), new DateTime(2017, 12, 19, 15, 49, 4), new DateTime(2017, 12, 19, 15, 49, 8), new DateTime(2017, 12, 19, 15, 49, 16) }); var logFile = CreateFromContent(content); var values = logFile.GetColumn(new LogFileSection(0, 5), LogFileColumns.ElapsedTime); values.Should().Equal(new object[] { null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(4), TimeSpan.FromSeconds(8) }); }