public void StreamingTest() { string fileName = GetBinFileName(); byte[] data = TestUtils.GenerateData <byte>(10000, 0); if (AllowCreate) { using (var b = new BinIndexedFile <byte>(fileName)) { b.InitializeNewFile(); b.WriteData(0, new ArraySegment <byte>(data)); } } byte[] bytes = File.ReadAllBytes(fileName); using (var b = (BinIndexedFile <byte>)BinaryFile.Open(fileName, false, LegacyResolver)) { var ms = new MemoryStream(bytes); var cs = new ConfigurableStream(ms); var data2 = new byte[data.Length / 2]; cs.AllowSeek = cs.AllowWrite = false; var b2 = (BinIndexedFile <byte>)BinaryFile.Open(cs, LegacyResolver); Assert.IsTrue(b2.IsOpen); Assert.AreEqual(b.ItemSize, b2.ItemSize); b2.ReadData(0, new ArraySegment <byte>(data2)); TestUtils.CollectionAssertEqual(TestUtils.GenerateData <byte>(data.Length / 2, 0), data2); b2.ReadData(0, new ArraySegment <byte>(data2)); TestUtils.CollectionAssertEqual(TestUtils.GenerateData <byte>(data.Length / 2, data.Length / 2), data2); } }
public void StreamingTest() { string fileName = GetBinFileName(); byte[] data = TestUtils.GenerateData<byte>(10000, 0); if (AllowCreate) { using (var b = new BinIndexedFile<byte>(fileName)) { b.InitializeNewFile(); b.WriteData(0, new ArraySegment<byte>(data)); } } byte[] bytes = File.ReadAllBytes(fileName); using (var b = (BinIndexedFile<byte>) BinaryFile.Open(fileName, false, LegacyResolver)) { var ms = new MemoryStream(bytes); var cs = new ConfigurableStream(ms); var data2 = new byte[data.Length/2]; cs.AllowSeek = cs.AllowWrite = false; var b2 = (BinIndexedFile<byte>) BinaryFile.Open(cs, LegacyResolver); Assert.IsTrue(b2.IsOpen); Assert.AreEqual(b.ItemSize, b2.ItemSize); b2.ReadData(0, new ArraySegment<byte>(data2)); TestUtils.CollectionAssertEqual(TestUtils.GenerateData<byte>(data.Length/2, 0), data2); b2.ReadData(0, new ArraySegment<byte>(data2)); TestUtils.CollectionAssertEqual(TestUtils.GenerateData<byte>(data.Length/2, data.Length/2), data2); } }