Exemplo n.º 1
0
        public void OverwriteDoesntChangeLength()
        {
            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);

            partitioningStream.Write(new byte[5], 0, 5);
            Assert.AreEqual(20, partitioningStream.Length);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void PositionAfterWrite()
        {
            var memoryStream1 = new MemoryStream();

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

            var buffer = new byte[9];

            partitioningStream.Write(buffer, 0, 9);
            Assert.AreEqual(9, partitioningStream.Position);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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()));
        }