public void Ctor_InvalidStream_Throws(CompressionMode mode) { LocalMemoryStream ms = new LocalMemoryStream(); ms.SetCanRead(mode == CompressionMode.Compress); ms.SetCanWrite(mode == CompressionMode.Decompress); AssertExtensions.Throws <ArgumentException>("stream", () => CreateStream(ms, mode)); }
public void WriteOnlyStreamThrowsOnDecompress() { var ms = new LocalMemoryStream(); ms.SetCanRead(false); Assert.Throws <ArgumentException>(() => { var gzip = new GZipStream(ms, CompressionMode.Decompress); }); }
public static void InvalidConstructors() { //out of range enum values ConstructorThrows <ArgumentOutOfRangeException>(() => new ZipArchive(new MemoryStream(), (ZipArchiveMode)(-1)), "Out of range enum"); ConstructorThrows <ArgumentOutOfRangeException>(() => new ZipArchive(new MemoryStream(), (ZipArchiveMode)(4)), "out of range enum"); ConstructorThrows <ArgumentOutOfRangeException>(() => new ZipArchive(new MemoryStream(), (ZipArchiveMode)(10)), "Out of range enum"); //null/closed stream ConstructorThrows <ArgumentNullException>(() => new ZipArchive((Stream)null, ZipArchiveMode.Read), "Null/closed stream"); ConstructorThrows <ArgumentNullException>(() => new ZipArchive((Stream)null, ZipArchiveMode.Create), "Null/closed stream"); ConstructorThrows <ArgumentNullException>(() => new ZipArchive((Stream)null, ZipArchiveMode.Update), "Null/closed stream"); MemoryStream ms = new MemoryStream(); ms.Dispose(); ConstructorThrows <ArgumentException>(() => new ZipArchive(ms, ZipArchiveMode.Read), "Disposed Base Stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(ms, ZipArchiveMode.Create), "Disposed Base Stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(ms, ZipArchiveMode.Update), "Disposed Base Stream"); //non-seekable to update using (LocalMemoryStream nonReadable = new LocalMemoryStream(), nonWriteable = new LocalMemoryStream(), nonSeekable = new LocalMemoryStream()) { nonReadable.SetCanRead(false); nonWriteable.SetCanWrite(false); nonSeekable.SetCanSeek(false); ConstructorThrows <ArgumentException>(() => new ZipArchive(nonReadable, ZipArchiveMode.Read), "Non readable stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(nonWriteable, ZipArchiveMode.Create), "Non-writable stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(nonReadable, ZipArchiveMode.Update), "Non-readable stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(nonWriteable, ZipArchiveMode.Update), "Non-writable stream"); ConstructorThrows <ArgumentException>(() => new ZipArchive(nonSeekable, ZipArchiveMode.Update), "Non-seekable stream"); } }
public void WriteOnlyStreamThrowsOnDecompress() { var ms = new LocalMemoryStream(); ms.SetCanRead(false); Assert.Throws<ArgumentException>(() => { var gzip = new DeflateStream(ms, CompressionMode.Decompress); }); }