public void CreateEntryFromFile_CompressionLevel_ShouldCreateZipArchiveWithFile(CompressionLevel level)
        {
            File.WriteAllLines(FileName, new[] { "this is the only line" });

            using (IZipArchive newZipArchive = mZipFile.Open(ArchiveFileName, ZipArchiveMode.Create))
            {
                newZipArchive.CreateEntryFromFile(FileName, FileName, level);
            }

            using (IZipArchive zipArchive = mZipFile.OpenRead(ArchiveFileName))
            {
                Assert.AreEqual(1, zipArchive.Entries.Count);
            }
        }
        public void ExtractToFile_ShouldThrowIoException_WhenOverwriteIsFalse_AndFileAlreadyExists()
        {
            File.WriteAllLines(FileName, new[] { "this is the only line" });

            using (IZipArchive newZipArchive = mZipFile.Open(ArchiveFileName, ZipArchiveMode.Create))
            {
                newZipArchive.CreateEntryFromFile(FileName, FileName);
            }

            File.WriteAllLines(ExtractionFile, new[] { "a different line" });

            using (IZipArchive zipArchive = mZipFile.OpenRead(ArchiveFileName))
            {
                Assert.Throws <IOException>(() => zipArchive.Entries[0].ExtractToFile(ExtractionFile, false));
            }
        }
        public void ExtractToFile_ShouldExtractToFile_WhenOverwriteIsTrue_AndFileAlreadyExists()
        {
            File.WriteAllLines(FileName, new[] { "this is the only line" });

            using (IZipArchive newZipArchive = mZipFile.Open(ArchiveFileName, ZipArchiveMode.Create))
            {
                newZipArchive.CreateEntryFromFile(FileName, FileName);
            }

            File.WriteAllLines(ExtractionFile, new[] { "a different line" });

            using (IZipArchive zipArchive = mZipFile.OpenRead(ArchiveFileName))
            {
                zipArchive.Entries[0].ExtractToFile(ExtractionFile, true);
            }

            Assert.AreEqual("this is the only line", File.ReadAllLines(ExtractionFile)[0]);
        }
        public void ExtractToFile_ShouldExtractToFile()
        {
            File.WriteAllLines(FileName, new[] { "this is the only line" });

            using (IZipArchive newZipArchive = mZipFile.Open(ArchiveFileName, ZipArchiveMode.Create))
            {
                newZipArchive.CreateEntryFromFile(FileName, FileName);
            }

            //Test sanity check
            Assert.IsFalse(File.Exists(ExtractionFile));

            using (IZipArchive zipArchive = mZipFile.OpenRead(ArchiveFileName))
            {
                zipArchive.Entries[0].ExtractToFile(ExtractionFile);
            }

            Assert.IsTrue(File.Exists(ExtractionFile));
        }
        public void ExtractToDirectory_ShouldExtractFileToDirectory()
        {
            File.WriteAllLines(FileName, new[] { "this is the only line" });

            using (IZipArchive newZipArchive = mZipFile.Open(ArchiveFileName, ZipArchiveMode.Create))
            {
                newZipArchive.CreateEntryFromFile(FileName, FileName);

                //Test sanity check
                Assert.IsFalse(Directory.Exists(ExtractionDir));
            }

            using (IZipArchive zipArchive = mZipFile.OpenRead(ArchiveFileName))
            {
                zipArchive.ExtractToDirectory(ExtractionDir);

                Assert.IsTrue(Directory.Exists(ExtractionDir));
                Assert.IsTrue(Directory.GetFiles(ExtractionDir)[0].Contains(FileName));
            }
        }