Ejemplo n.º 1
0
 public void SetLengthOpensFile()
 {
     using (var stream = new LazyFileStream(tempFile, FileOpenMode.ReadWrite)) {
         stream.SetLength(1);
         Assert.That(stream.BaseStream, Is.Not.Null);
         Assert.That(File.Exists(tempFile), Is.True);
         Assert.That(stream.Length, Is.EqualTo(1));
         Assert.That(stream.BaseStream.Length, Is.EqualTo(1));
     }
 }
Ejemplo n.º 2
0
 public void LengthSyncWithStream()
 {
     using (var stream = new LazyFileStream(tempFile, FileOpenMode.ReadWrite)) {
         stream.SetLength(1);
         Assert.That(stream.Length, Is.EqualTo(1));
         stream.BaseStream.Position = 1;
         stream.BaseStream.WriteByte(0xAA);
         Assert.That(stream.Length, Is.EqualTo(2));
     }
 }
Ejemplo n.º 3
0
        public void PublicMethodThrowAfterDispose()
        {
            var stream = new LazyFileStream(tempFile, FileOpenMode.ReadWrite);

            stream.Dispose();

            byte[] buffer = new byte[1];
            Assert.That(
                () => stream.SetLength(10),
                Throws.InstanceOf <ObjectDisposedException>());
            Assert.That(
                () => stream.WriteByte(0x00),
                Throws.InstanceOf <ObjectDisposedException>());
            Assert.That(
                () => stream.Write(buffer, 0, 1),
                Throws.InstanceOf <ObjectDisposedException>());
            Assert.That(
                () => stream.ReadByte(),
                Throws.InstanceOf <ObjectDisposedException>());
            Assert.That(
                () => stream.Read(buffer, 0, 1),
                Throws.InstanceOf <ObjectDisposedException>());
        }