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 ReadOnlyStreamThrowsOnCompress() { var ms = new LocalMemoryStream(); ms.SetCanWrite(false); Assert.Throws <ArgumentException>(() => { var gzip = new GZipStream(ms, CompressionMode.Compress); }); }
public void ReadOnlyStreamThrowsOnCompress() { var ms = new LocalMemoryStream(); ms.SetCanWrite(false); AssertExtensions.Throws <ArgumentException>("stream", () => { var gzip = new DeflateStream(ms, CompressionMode.Compress); }); }
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 ReadOnlyStreamThrowsOnCompress() { var ms = new LocalMemoryStream(); ms.SetCanWrite(false); Assert.Throws<ArgumentException>(() => { var gzip = new DeflateStream(ms, CompressionMode.Compress); }); }