static void CreateArchive(string testPackageFilePath) { IArchiver archiver = new Archiver(); try { archiver.CreateArchive(testPackageFilePath); } catch (ArchiveAlreadyExistsException e) { ExitWithErrorString("Error: Archive already exists: " + e.Message); } }
public void CreateArchiveTest() { string currentDirectory = Directory.GetCurrentDirectory(); string zipDirectory = "zipDirectory"; string zipFolderPath = currentDirectory + "\\" + zipDirectory; Directory.CreateDirectory(zipFolderPath); string nestedFile = "thisIsMyArchiveFile.txt"; string nestedFilePath = zipFolderPath + "\\" + nestedFile; string fileContents = "THIS IS THE CONTENTS OF MY FILE"; File.Create(nestedFilePath).Close(); File.AppendAllText(nestedFilePath, fileContents); string zippedFiles = "zippedDirectory"; ZipFile.CreateFromDirectory(zipFolderPath, zippedFiles + ".zip"); string zipPath = currentDirectory + "\\" + zippedFiles + ".zip"; IArchiver archiver = new Archiver(); archiver.CreateArchive(zipPath); string archiveDirectory = currentDirectory + "\\" + "Archive"; string archive = archiveDirectory + "\\" + zippedFiles + "Archive.zip"; FileInfo archiveFI = new FileInfo(archive); FileInfo zipFI = new FileInfo(zipPath); Assert.IsTrue(archiveFI.Length > 0); Assert.AreEqual(zipFI.Length, archiveFI.Length); Directory.Delete(zipFolderPath, true); Directory.Delete(archiveDirectory, true); File.Delete(zipPath); }