public void OverwriteFiles() { sp.SourceFile = Path.Combine(inputPath, @"testzip.zip"); Options opt = new Options() { DestinationFileExistsAction = FileExistAction.Overwrite, CreateDestinationDirectory = true }; dp.DirectoryPath = Path.Combine(dp.DirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory")); //extract testzip.zip Unzip.Output output = UnzipTask.ExtractArchive(sp, dp, opt, new CancellationToken()); //read first line from each file var lines = Directory.EnumerateFiles(dp.DirectoryPath, "*", SearchOption.AllDirectories).Select(x => File.ReadLines(x).First()).ToList(); Assert.True(lines.Contains("First file") && lines.Contains("Second file") && lines.Contains("Third file")); sp.SourceFile = Path.Combine(inputPath, @"testzip2.zip"); //Extract testzip2.zip. Should overwrite existing files from previous step output = UnzipTask.ExtractArchive(sp, dp, opt, new CancellationToken()); var lines2 = Directory.EnumerateFiles(dp.DirectoryPath, "*", SearchOption.AllDirectories).Select(x => File.ReadLines(x).First()).ToList(); Assert.False(lines2.Contains("First file") && lines2.Contains("Second file") && lines2.Contains("Third file")); Assert.True(lines2.Contains("Fourth file") && lines2.Contains("Fifth file") && lines2.Contains("Sixth file")); }
public void SourceFileDoesNotExist() { //throws System.IO.FileNotFoundException sp.SourceFile = Path.Combine(inputPath, @"doesnotexist.zip"); opt.DestinationFileExistsAction = FileExistAction.Overwrite; dp.DirectoryPath = outputPath; Assert.That(() => UnzipTask.ExtractArchive(sp, dp, opt, new System.Threading.CancellationToken()), Throws.TypeOf <FileNotFoundException>()); }
public void DestinatioDirectoryNotFound() { //throws directory not found exception //destination directory does not exist and create destination directory == false sp.SourceFile = Path.Combine(inputPath, @"HiQLogos.zip"); opt.DestinationFileExistsAction = FileExistAction.Error; opt.CreateDestinationDirectory = false; dp.DirectoryPath = Path.Combine(outputPath, @"\doesnot\exist"); Assert.That(() => UnzipTask.ExtractArchive(sp, dp, opt, new System.Threading.CancellationToken()), Throws.TypeOf <DirectoryNotFoundException>()); }
public void PasswordError() { //Should throw Ionic.Zip.BadPasswordException sp.SourceFile = Path.Combine(inputPath, @"HiQLogosWithPassword.zip"); opt.DestinationFileExistsAction = FileExistAction.Overwrite; opt.CreateDestinationDirectory = true; dp.DirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory"); Assert.That(() => UnzipTask.ExtractArchive(sp, dp, opt, new System.Threading.CancellationToken()), Throws.TypeOf <BadPasswordException>()); }
public void ExtractWithPassword() { //extract password protected archive sp.SourceFile = Path.Combine(inputPath, @"HiQLogosWithPassword.zip"); sp.Password = "******"; opt.DestinationFileExistsAction = FileExistAction.Overwrite; opt.CreateDestinationDirectory = true; dp.DirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory"); Output output = UnzipTask.ExtractArchive(sp, dp, opt, new System.Threading.CancellationToken()); Assert.True(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory\logo1.png"))); Assert.True(File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory\logo2.png"))); }
public void CreateDirectory() { //create destination directory if it does not exist sp.SourceFile = Path.Combine(inputPath, @"HiQLogos.zip"); opt.DestinationFileExistsAction = FileExistAction.Error; opt.CreateDestinationDirectory = true; dp.DirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory\"); outputFiles = new List <string>(); fileNames.ToList().ForEach(x => outputFiles.Add(Path.Combine(dp.DirectoryPath, x))); Output output = UnzipTask.ExtractArchive(sp, dp, opt, new CancellationToken()); foreach (string s in outputFiles) { Assert.True(File.Exists(s)); } Assert.AreEqual(output.ExtractedFiles.Count, 7); }
public void ThrowErrorOnOverwrite() { sp.SourceFile = Path.Combine(inputPath, @"HiQLogos.zip"); Options opt2 = new Options() { DestinationFileExistsAction = FileExistAction.Overwrite, CreateDestinationDirectory = true }; opt.DestinationFileExistsAction = FileExistAction.Error; opt.CreateDestinationDirectory = true; dp.DirectoryPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\TestData\TestOut\new_directory"); //unzip files to TestOut, so that there are existing files UnzipTask.ExtractArchive(sp, dp, opt2, new CancellationToken()); Assert.That(() => UnzipTask.ExtractArchive(sp, dp, opt, new System.Threading.CancellationToken()), Throws.TypeOf <Ionic.Zip.ZipException>()); }
public void RenameFiles() { sp.SourceFile = Path.Combine(inputPath, @"HiQLogos.zip"); opt.DestinationFileExistsAction = FileExistAction.Rename; opt.CreateDestinationDirectory = true; dp.DirectoryPath = outputPath; //extract files to TestOut, so that there are existing files UnzipTask.ExtractArchive(sp, dp, opt, new CancellationToken()); Output output = UnzipTask.ExtractArchive(sp, dp, opt, new CancellationToken()); //create filenames to test against outputFiles = new List <string>(); renamedFilenames.ToList().ForEach(x => outputFiles.Add(Path.Combine(dp.DirectoryPath, x))); foreach (string s in outputFiles) { Assert.True(File.Exists(s)); } Assert.AreEqual(output.ExtractedFiles.Count, 7); }