public void PositionAfterRead() { var memoryStream1 = new MemoryStream(new byte[10]); var fileSystem = new FakeFileSystem(memoryStream1, null, null); var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 6, FileAccess.Write); var buffer = new byte[9]; partitioningStream.Read(buffer, 0, 9); Assert.AreEqual(9, partitioningStream.Position); }
public void ReadAcrossTwoFiles() { var memoryStream1 = new MemoryStream(Encoding.ASCII.GetBytes("12345")); var memoryStream2 = new MemoryStream(Encoding.ASCII.GetBytes("67890")); var fileSystem = new FakeFileSystem(memoryStream1, memoryStream2, null); var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 5, FileAccess.Read); var buffer = new byte[10]; var read = partitioningStream.Read(buffer, 0, 10); Assert.AreEqual(10, read); Assert.AreEqual("1234567890", Encoding.ASCII.GetString(buffer)); }
public void Read() { const string helloWorld = "Hello, World!"; var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(helloWorld)); var fileSystem = new FakeFileSystem(memoryStream, null, null); var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Read); var buffer = new byte[helloWorld.Length]; var read = partitioningStream.Read(buffer, 0, helloWorld.Length); Assert.AreEqual(helloWorld.Length, read); Assert.AreEqual(helloWorld, Encoding.ASCII.GetString(buffer)); }
public void PositionAfterReadThenWriteIntoSecondFile() { var memoryStream1 = new MemoryStream(new byte[20]); var memoryStream2 = new MemoryStream(new byte[20]); var fileSystem = new FakeFileSystem(memoryStream1, memoryStream2, null); var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 20, FileAccess.Write); var buffer = new byte[40]; partitioningStream.Read(buffer, 0, 20); partitioningStream.Write(buffer, 0, 10); Assert.AreEqual(30, partitioningStream.Position); }
public void ReadSingleFile() { const string helloWorld = "Hello, World!!"; var memoryStream = new MemoryStream(Encoding.ASCII.GetBytes(helloWorld)); var fileSystem = new FakeFileSystem(memoryStream, null, null); var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Read); var buffer = new byte[helloWorld.Length]; for (int i = 0; i < helloWorld.Length; i += 2) { partitioningStream.Read(buffer, i, 2); } Assert.AreEqual(helloWorld, Encoding.ASCII.GetString(buffer)); }