public void Zip_Reader_Disposal_Test2() { ResetScratch(); using (TestStream stream = new TestStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) { var reader = ReaderFactory.Open(stream, Options.None); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } } Assert.False(stream.IsDisposed); } }
public void Zip_Reader_Disposal_Test() { ResetScratch(); using (TestStream stream = new TestStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) { using (var reader = ReaderFactory.Open(stream)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } Assert.True(stream.IsDisposed); } }
private void ReadImpl(string testArchive, CompressionType expectedCompression, ReaderOptions options) { using (var file = File.OpenRead(testArchive)) { using (var protectedStream = NonDisposingStream.Create(new ForwardOnlyStream(file), throwOnDispose: true)) { using (var testStream = new TestStream(protectedStream)) { using (var reader = ReaderFactory.Open(testStream, options)) { UseReader(reader, expectedCompression); protectedStream.ThrowOnDispose = false; Assert.False(testStream.IsDisposed, "{nameof(testStream)} prematurely closed"); } // Boolean XOR -- If the stream should be left open (true), then the stream should not be diposed (false) // and if the stream should be closed (false), then the stream should be disposed (true) var message = $"{nameof(options.LeaveStreamOpen)} is set to '{options.LeaveStreamOpen}', so {nameof(testStream.IsDisposed)} should be set to '{!testStream.IsDisposed}', but is set to {testStream.IsDisposed}"; Assert.True(options.LeaveStreamOpen != testStream.IsDisposed, message); } } } }
public void Zip_Reader_Disposal_Test() { ResetScratch(); using (TestStream stream = new TestStream(File.OpenRead(Path.Combine(TEST_ARCHIVES_PATH, "Zip.deflate.dd.zip")))) { using (var reader = ReaderFactory.Open(stream, Options.None)) { while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(SCRATCH_FILES_PATH, ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite); } } } Assert.IsTrue(stream.IsDisposed); } }