public void FixtureSetup()
        {
            Monitor.Enter(monitorObject);
            var assembly         = Assembly.GetAssembly(typeof(ZipArchiveWrap));
            var CurrentDirectory = Path.GetDirectoryName(assembly.Location);

            ArchiveDirectory   = assembly.CodeBase.Substring(8); //remove the "file://" from the front
            ArchiveFileName    = $@"{CurrentDirectory}\ZipArchiveWrapTests.zip";
            ArchiveFileInfo    = new FileInfo(ArchiveFileName);
            UnarchiveDirectory = $@"{CurrentDirectory}\ZipArchiveWrapTests\";

            ArchiveDirectory = $@"{Path.GetDirectoryName(ArchiveDirectory)}\ZipArchiveWrapTestsSource";
            if (!Directory.Exists(ArchiveDirectory))
            {
                Directory.CreateDirectory(ArchiveDirectory);
            }

            File.WriteAllText($@"{ArchiveDirectory}\ZipArchiveWrapTests.txt", "ZipArchiveWrapTests");
            File.WriteAllText($@"{ArchiveDirectory}\AnotherFile.txt", "Another File!");

            if (File.Exists(ArchiveFileName))
            {
                File.Delete(ArchiveFileName);
            }

            zipfile = new ZipFileWrap();
            zipfile.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);

            if (Directory.Exists(UnarchiveDirectory))
            {
                Directory.Delete(UnarchiveDirectory, true);
            }

            zipfile.ExtractToDirectory(ArchiveFileName, UnarchiveDirectory);
        }
示例#2
0
        public void CreateFromDirectory_WithCompressionLevel_Creates_Archive()
        {
            var instance = new ZipFileWrap();

            instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName, System.IO.Compression.CompressionLevel.Fastest, true);
            Assert.IsTrue(File.Exists(ArchiveFileName));
            Assert.IsTrue(ArchiveFileInfo.Length > 0);
        }
示例#3
0
        public void CreateFromDirectory_Creates_Archive()
        {
            var instance = new ZipFileWrap();

            instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);
            Assert.IsTrue(File.Exists(ArchiveFileName));
            Assert.IsTrue(ArchiveFileInfo.Length > 0);
        }
示例#4
0
        public void ExtractToDirectory_WithEncoding_CreatesDirectory()
        {
            var instance = new ZipFileWrap();

            instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);
            instance.ExtractToDirectory(ArchiveFileName, UnarchiveDirectory, Encoding.UTF8);
            Assert.IsTrue(Directory.Exists(UnarchiveDirectory));
            Assert.IsTrue(Directory.GetFiles(UnarchiveDirectory).Length > 0);
        }
示例#5
0
        public void OpenRead_Creates_ZipArchiveWrap()
        {
            var instance = new ZipFileWrap();

            instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);
            using (var archive = instance.OpenRead(ArchiveFileName))
            {
                Assert.IsNotNull(archive);
                Assert.IsInstanceOf <ZipArchiveWrap>(archive);
            }
        }
示例#6
0
        public void Open_Creates_ZipArchiveWrap()
        {
            var instance = new ZipFileWrap();

            instance.CreateFromDirectory(ArchiveDirectory, ArchiveFileName);
            using (var archive = instance.Open(ArchiveFileName, System.IO.Compression.ZipArchiveMode.Read))
            {
                Assert.IsNotNull(archive);
                Assert.IsInstanceOf <ZipArchiveWrap>(archive);
            }
        }
示例#7
0
        public void Open_WithUTF8Encoding_Creates_OpensZipWithCorrectEncoding()
        {
            var assembly     = Assembly.GetAssembly(typeof(ZipFileWrapTests));
            var testFilePath = assembly.CodeBase.Substring(8);  //remove the "file://" from the front

            testFilePath = Path.GetDirectoryName(testFilePath) + @"\TestData\Encoding_UTF8.zip";

            var instance = new ZipFileWrap();

            using (var archive = instance.Open(testFilePath, System.IO.Compression.ZipArchiveMode.Read, Encoding.UTF8))
            {
                Assert.IsNotNull(archive);
                Assert.IsInstanceOf <ZipArchiveWrap>(archive);

                var entry = archive.Entries.First();
                Assert.AreEqual("text-ľščťžýáíé.txt", entry.Name);
            }
        }