public void ExtractShouldThrowExceptionWhenDisposed() { BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive); archive.Dispose(); var dir = SharedData.CreateTempDirectory(); using (var stream = new MemoryStream()) { Assert.Throws <ObjectDisposedException>(() => archive.Extract(0, dir, false)); Assert.Throws <ObjectDisposedException>(() => archive.Extract("test.txt", dir, false)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractToStream(0, stream)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractAll("", false, CancellationToken.None, null)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new int[] { 0 }, dir, false, CancellationToken.None, null)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false)); Assert.Throws <ObjectDisposedException>(() => archive.ExtractFiles(new string[] { "test.txt" }, dir, false, CancellationToken.None, null)); // These methods should not throw ObjectDisposedException Assert.DoesNotThrow(() => { var files = archive.FileList; archive.GetIndexFromFilename("test.txt"); archive.GetIndexFromFilename("ajkkfajsdlkfjlkasdf"); var total = archive.TotalFiles; var header = archive.Header; }); } }
public void ExtractByIndexFromOneFileArchive() { BA2GeneralArchive archive = BA2Loader.Load <BA2GeneralArchive>(SharedData.GeneralOneFileArchive); using (MemoryStream stream = new MemoryStream()) { Assert.IsTrue(archive.ExtractToStream(0, stream)); TestUtils.AssertExtractedTextFile(stream, "test text"); } archive.Dispose(); }