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)); } }
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)); } }
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>()); }