Beispiel #1
0
        public void CreateZipFileWithFilesAndADirectory()
        {
            var          zipFilePath = TestHelper.GetCurrentMethodName() + ".zip";
            const string file1Path   = @".\file1.txt";
            const string file2Path   = @".\dir\file2.txt";

            DeleteFilesIfExist(new [] { zipFilePath, file1Path, file2Path });

            Directory.CreateDirectory(@".\dir");

            CreateTestFile(file1Path);
            CreateTestFile(file2Path);

            ZipFileUtils.Create(zipFilePath, new List <string> {
                file1Path, file2Path
            });

            var zipfileExists = File.Exists(zipFilePath);

            Directory.Delete(@".\dir", true);
            DeleteFilesIfExist(new [] { file1Path, file2Path });

            ZipFileUtils.Extract(zipFilePath, ".");

            DeleteFilesIfExist(new [] { zipFilePath });

            var file1Exists = File.Exists(file1Path);
            var file2Exists = File.Exists(file2Path);

            DeleteFilesIfExist(new[] { zipFilePath, file1Path, file2Path });

            Assert.IsTrue(zipfileExists);
            Assert.IsTrue(file1Exists);
            Assert.IsTrue(file2Exists);
        }
Beispiel #2
0
        public void CreateEmptyZipFile()
        {
            var path = TestHelper.GetCurrentMethodName() + ".zip";

            DeleteFilesIfExist(new[] { path });

            ZipFileUtils.Create(path, null);
            var fileExists = File.Exists(path);

            DeleteFilesIfExist(new[] { path });

            Assert.IsTrue(fileExists);
        }
Beispiel #3
0
        public void CreateEmptyZipFileWithoutOverwrite()
        {
            var path = TestHelper.GetCurrentMethodName() + ".zip";

            DeleteFilesIfExist(new[] { path });

            File.Create(path).Close();

            try
            {
                ZipFileUtils.Create(path, null, false);
                Assert.Fail("ZipFileUtils.Create should throw an error if file already exists and the parameter 'overwriteIfExits' is false.");
            }
            catch (Exception)
            {
                DeleteFilesIfExist(new[] { path });
            }
        }
Beispiel #4
0
        public void AddToZipFile()
        {
            string textpath = TestHelper.GetCurrentMethodName() + ".txt";

            using (TextWriter writer = new StreamWriter(textpath))
            {
                writer.Write("silly text");
            }

            string textpath2 = TestHelper.GetCurrentMethodName() + "1.txt";

            File.Copy(textpath, textpath2, true);
            string zipFilePath = TestHelper.GetCurrentMethodName() + ".zip";

            if (File.Exists(zipFilePath))
            {
                File.Delete(zipFilePath);
            }
            Assert.IsTrue(ZipFileUtils.AddFileToOrReplaceFileInZipFile(Path.GetFullPath(textpath), Path.GetFullPath(zipFilePath)));
            Assert.IsTrue(ZipFileUtils.AddFileToOrReplaceFileInZipFile(textpath2, zipFilePath));
        }
Beispiel #5
0
        public void CreateZipFileWithFiles()
        {
            var          zipFilePath = TestHelper.GetCurrentMethodName() + ".zip";
            const string file1Path   = @".\file1.txt";
            const string file2Path   = @".\file2.txt";

            DeleteFilesIfExist(new[] { zipFilePath, file1Path, file2Path });

            var file1 = File.CreateText(file1Path);
            var file2 = File.CreateText(file2Path);

            file1.WriteLine("TestFile1");
            file2.WriteLine("TestFile2");

            file1.Close();
            file2.Close();

            ZipFileUtils.Create(zipFilePath, new List <string> {
                file1Path, file2Path
            });

            var zipfileExists = File.Exists(zipFilePath);

            DeleteFilesIfExist(new[] { file1Path, file2Path });

            ZipFileUtils.Extract(zipFilePath, ".");

            var file1Exists = File.Exists(file1Path);
            var file2Exists = File.Exists(file2Path);

            DeleteFilesIfExist(new[] { zipFilePath, file1Path, file2Path });

            Assert.IsTrue(zipfileExists);
            Assert.IsTrue(file1Exists);
            Assert.IsTrue(file2Exists);
        }
Beispiel #6
0
        public void CreateEmptyZipFileWithOverwrite()
        {
            var path = TestHelper.GetCurrentMethodName() + ".zip";

            DeleteFilesIfExist(new[] { path });

            File.Create(path).Close();

            try
            {
                ZipFileUtils.Create(path, null, true);
            }
            catch (Exception)
            {
                DeleteFilesIfExist(new[] { path });
                Assert.Fail("File should be overwritten");
            }

            var fileExists = File.Exists(path);

            DeleteFilesIfExist(new[] { path });

            Assert.IsTrue(fileExists);
        }
Beispiel #7
0
 public void ExtractFromZipFile()
 {
     File.Delete("LogoNLMW.xml");
     ZipFileUtils.Extract(@"..\..\..\..\Data\ZipFile\metadata.zip", ".");
     Assert.IsTrue(File.Exists("LogoNLMW.xml"));
 }
Beispiel #8
0
 public void ExtractFromZipFile()
 {
     File.Delete("LogoNLMW.xml");
     ZipFileUtils.Extract(@"..\..\..\..\..\test-data\Common\DelftTools.Tests\zipfile\MetaData.zip", ".");
     Assert.IsTrue(File.Exists("LogoNLMW.xml"));
 }