예제 #1
0
        public void StartPosition()
        {
            var fileSystem         = new FakeFileSystem(null, null, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 6, FileAccess.Write);

            Assert.AreEqual(0, partitioningStream.Position);
        }
예제 #2
0
        public void CanWrite()
        {
            var memoryStream       = new MemoryStream(Encoding.ASCII.GetBytes("Hello, World!"));
            var fileSystem         = new FakeFileSystem(memoryStream, null, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Write);

            Assert.IsTrue(partitioningStream.CanWrite);
        }
예제 #3
0
        public void Length()
        {
            var memoryStream1 = new MemoryStream(new byte[10]);
            var memoryStream2 = new MemoryStream(new byte[10]);

            var fileSystem         = new FakeFileSystem(memoryStream1, memoryStream2, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 6, FileAccess.Write);

            Assert.AreEqual(20, partitioningStream.Length);
        }
예제 #4
0
        public void DisposeWillCloseInnerStream()
        {
            var stream             = new TestStream();
            var fileSystem         = new FakeFileSystem(stream, null, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Read);

            partitioningStream.Dispose();

            Assert.IsTrue(stream.HasCalledClose);
        }
예제 #5
0
        public void FlushWillFlushInnerStream()
        {
            var stream             = new TestStream();
            var fileSystem         = new FakeFileSystem(stream, null, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Read);

            partitioningStream.Flush();

            Assert.IsTrue(stream.HasCalledFlush);
        }
예제 #6
0
        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);
        }
예제 #7
0
        public void ExpandLengthTwoFiles()
        {
            var memoryStream1 = new MemoryStream();
            var memoryStream2 = new MemoryStream();

            var fileSystem         = new FakeFileSystem(memoryStream1, memoryStream2, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 10, FileAccess.Write);

            partitioningStream.Write(new byte[20], 0, 15);
            Assert.AreEqual(15, partitioningStream.Length);
        }
예제 #8
0
        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));
        }
예제 #9
0
        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));
        }
예제 #10
0
        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);
        }
예제 #11
0
        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));
        }
예제 #12
0
        public void FilesAreClosed()
        {
            var stream1            = new TestStream();
            var memoryStream2      = new MemoryStream();
            var fileSystem         = new FakeFileSystem(stream1, memoryStream2, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 6, FileAccess.Write);

            const string helloWorld = "Hello, World!";

            var buffer = Encoding.ASCII.GetBytes(helloWorld);

            partitioningStream.Write(buffer, 0, buffer.Length);

            Assert.IsTrue(stream1.HasCalledClose);
        }
예제 #13
0
        public void Write()
        {
            var memoryStream       = new MemoryStream();
            var fileSystem         = new FakeFileSystem(memoryStream, null, null);
            var partitioningStream = new PartitioningFileStream(fileSystem, "FileName", "ext", 100, FileAccess.Write);

            const string helloWorld = "Hello, World!";

            var buffer = Encoding.ASCII.GetBytes(helloWorld);

            partitioningStream.Write(buffer, 0, buffer.Length);
            partitioningStream.Flush();

            Assert.AreEqual(helloWorld, Encoding.ASCII.GetString(memoryStream.ToArray()));
        }