public void FetchPageWithHalfSize_Test() { using (var stream = new MemoryStream(new byte[4096 + 1024])) { var reader = new PagedStreamReader(stream, 4096); var page = reader.FetchPage(0); Assert.AreEqual(0, page.PageIndex); Assert.AreEqual(4096, page.Data.Length); page = reader.FetchPage(1); Assert.AreEqual(1, page.PageIndex); Assert.AreEqual(1024, page.Data.Length); } }
public void LogRowDataPoint() { const string row = "2011-01-24 06:29:46.687|Core.State.StartTime|Core|181188615|356.3245\r\n"; string itemID; LogRowIndex index; char[] ptr = row.ToCharArray(); LogStudio.Data.LogFileParser.ParseRow(ptr, row.Length, 0, '|', out index, out itemID); LogRowDataPoint data; using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(row))) { var pagedReader = new PagedStreamReader(stream, 4096); data = LogRowDataFactory.CreateDataPoint(pagedReader, index); } Assert.AreEqual(DateTime.Parse("2011-01-24 06:29:46.687"), data.TimeStamp); Assert.AreEqual(356.3245, data.Value); }
public void ReadPageAndCompareContentWithSource_PageSize_300_Test() { var source = Enumerable.Range(0, 500).Select(p => (byte)(p % 256)).ToArray(); using (var stream = new MemoryStream(source)) { var reader = new PagedStreamReader(stream, 300); var buffer = new byte[137]; var read = reader.Read(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, read); Assert.That(buffer.Compare(0, source, 0, buffer.Length)); read = reader.Read(buffer, 480, buffer.Length); Assert.AreEqual(20, read); Assert.That(buffer.Compare(0, source, 480, read)); } }
public void IncreasingStreamLength_PageSize_300_Test() { var source = Enumerable.Range(0, 500).Select(p => (byte)(p % 256)).ToArray(); using (var stream = new MemoryStream()) { stream.Write(source, 0, source.Length); var reader = new PagedStreamReader(stream, 300); byte[] buffer = new byte[500]; int read = reader.Read(buffer, 0, buffer.Length); var source2 = Enumerable.Range(0, 37).Select(p => (byte)(p % 256)).ToArray(); stream.Write(source2, 0, source2.Length); read = reader.Read(buffer, read, buffer.Length); Assert.AreEqual(37, read); Assert.That(buffer.Compare(0, source2, 0, read)); } }