示例#1
0
        public void ZipFiles_NoFiles_NoZip()
        {
            FileZipper zipper    = new FileZipper();
            ZipResult  zipResult = zipper.ZipFiles(Enumerable.Empty <string>());

            Assert.IsNull(zipResult);
        }
示例#2
0
 public void ZipFilesThrowsIfCollectionIsEmpty(IEnumerable <FileInfo> files)
 {
     Assert.Throws <ArgumentException>(() =>
     {
         var _ = FileZipper.ZipFiles(files);
     });
 }
示例#3
0
 public void UnzipFilesThrowsOnNullArgument()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = FileZipper.UnzipFiles(null).ToList();
     });
 }
示例#4
0
 public void ZipFilesBoolThrowsIfArgumentIsNull()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         var _ = FileZipper.ZipFiles(null, true);
     });
 }
        public void Test_GetZipInternalPath()
        {
            string fileName = "/SourceDir/File.txt";

            string destination = "/DestDir/";

            string pattern = fileName + "|" + destination;

            string zipFileName = "MyZipFile";

            // TODO: Remove if not ne
            //var script = new DummyScript("TestScript");

            var zipper = new FileZipper();

            string internalPath = zipper.GetZipInternalPath(
                WorkingDirectory,
                zipFileName,
                fileName,
                pattern
                );

            var expected = zipFileName
                           + "/"
                           + destination.Trim('/')
                           + "/"
                           + Path.GetFileName(fileName);

            Assert.AreEqual(expected, internalPath, "Wrong path returned.");
        }
示例#6
0
 private void ZipFiles()
 {
     if (FilesRadioButton.IsChecked == true)
     {
         if (string.IsNullOrEmpty(ZipArchivePassword.Password))
         {
             binaryEmbedStruct.ZipFileLocation = new FileInfo(FileZipper.ArchiveFiles(binaryEmbedStruct.Files, null));
         }
         else
         {
             binaryEmbedStruct.ZipFileLocation = new FileInfo(FileZipper.ArchiveFiles(binaryEmbedStruct.Files, ZipArchivePassword.Password));
         }
     }
     else if (DirectoryRadioButton.IsChecked == true)
     {
         if (string.IsNullOrEmpty(ZipArchivePassword.Password))
         {
             binaryEmbedStruct.ZipFileLocation = new FileInfo(FileZipper.ArchiveDirectory(binaryEmbedStruct.Directory, null));
         }
         else
         {
             binaryEmbedStruct.ZipFileLocation = new FileInfo(FileZipper.ArchiveDirectory(binaryEmbedStruct.Directory, ZipArchivePassword.Password));
         }
     }
 }
示例#7
0
 private void compressFile()
 {
     if (IsZipFile)
     {
         LogWriter.LogInfo("ExportCommand: Compressing the file");
         FileZipper.Compress(new FileInfo(FileName));
     }
 }
示例#8
0
        public void ZipFiles_OneFile_ZipResult()
        {
            FileZipper zipper    = new FileZipper();
            var        readme    = Path.Combine(GetTestLogDirectoryPath(), "readme.txt");
            ZipResult  zipResult = zipper.ZipFiles(new[] { readme });

            Assert.IsNotNull(zipResult);
        }
示例#9
0
        public void ZipArchiveIsCreatedFromValidFiles()
        {
            using (var stream = FileZipper.ZipFiles(this.EnumerateFileOfTempCollection()))
            {
                File.WriteAllBytes(this.singleZipFile.FullName, stream.ToArray());

                Assert.IsTrue(this.singleZipFile.Exists);
            }
        }
示例#10
0
        public void ZipFiles_OneFile_ZipResultContainsFileLog()
        {
            FileZipper zipper    = new FileZipper();
            var        readmeTxt = "readme.txt";
            var        fullPath  = Path.Combine(GetTestLogDirectoryPath(), readmeTxt);
            ZipResult  zipResult = zipper.ZipFiles(new[] { fullPath });

            Assert.AreEqual(readmeTxt, zipResult.Entries[0]);
        }
示例#11
0
 public LibraryGetter(
     IFileNodeState nodeState
     )
 {
     NodeState       = nodeState;
     Zipper          = new FileZipper();
     OnlineZipGetter = new LibraryOnlineZipGetter(nodeState);
     LocalZipGetter  = new LibraryLocalZipGetter(nodeState);
     NugetGetter     = new LibraryNugetGetter(nodeState);
 }
示例#12
0
 public void UnizipFilesThrowsIfStreamIsEmpty()
 {
     Assert.Throws <ArgumentException>(() =>
     {
         using (var stream = new MemoryStream())
         {
             var _ = FileZipper.UnzipFiles(stream).ToList();
         }
     });
 }
示例#13
0
        public void SetUp()
        {
            sourceDirectoryName = Guid.NewGuid().ToString();
            sourceDirectoryPath = Path.Combine(Path.GetTempPath(), sourceDirectoryName);
            cancellationToken   = CancellationToken.None;

            Directory.CreateDirectory(sourceDirectoryPath);

            fileZipper = new FileZipper();
        }
示例#14
0
        public void ZipFiles_OneFile_ZipResultContainsFile()
        {
            FileZipper zipper    = new FileZipper();
            var        readmeTxt = "readme.txt";
            var        fullPath  = Path.Combine(GetTestLogDirectoryPath(), readmeTxt);
            ZipResult  zipResult = zipper.ZipFiles(new[] { fullPath });
            var        entry     = this.GetEntry(zipResult.ZipStream, readmeTxt);

            Assert.IsNotNull(entry);
        }
示例#15
0
        public void ZipFiles_OneFile_ZipResultContainsFileWithCorrectContent()
        {
            FileZipper   zipper    = new FileZipper();
            var          readmeTxt = "readme.txt";
            var          fullPath  = Path.Combine(GetTestLogDirectoryPath(), readmeTxt);
            ZipResult    zipResult = zipper.ZipFiles(new[] { fullPath });
            var          entry     = this.GetEntry(zipResult.ZipStream, readmeTxt);
            StreamReader reader    = new StreamReader(entry.GetStream());
            string       text      = reader.ReadToEnd();

            Assert.AreEqual("TEST_SUCCESS", text);
        }
示例#16
0
        public void ZipFiles_ManyFiles_ZipResultContainsMultipleFileEntries()
        {
            var files = Directory.GetFiles(GetTestLogDirectoryPath(), "*.txt");

            Assert.Greater(files.Length, 5, "Missing Files for testing");

            FileZipper zipper = new FileZipper();

            using (ZipResult zipResult = zipper.ZipFiles(files))
            {
                Assert.AreEqual(files.Length, zipResult.Entries.Count());
            }
        }
示例#17
0
        public FileResult DownloadTestScript()
        {
            string     zipsolutionPath = Server.MapPath("~/SeleniumTestScript");
            FileZipper fz;

            fz = new FileZipper();
            fz.CopyZip(zipsolutionPath, "TestScript.rar");
            string solutionPath = zipsolutionPath;

            solutionPath = zipsolutionPath + "\\TestScript.rar";
            if (System.IO.File.Exists(solutionPath))
            {
                byte[] fileBytes = System.IO.File.ReadAllBytes(solutionPath);
                string fileName  = "TestScript.rar";
                return(File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName));
            }
            return(null);
        }
示例#18
0
        public void FilesOfArchiveAreWrittenIntoMemory()
        {
            var unzippedFiles = new List <FileInfo>();

            using (var archive = this.CreateArchiveFromTemporaryFiles())
            {
                foreach (var singleFileStream in FileZipper.UnzipFiles(archive))
                {
                    using (singleFileStream)
                    {
                        var path = Path.GetTempFileName();
                        this.tempTestFiles.AddFile(path, false);
                        File.WriteAllBytes(path, singleFileStream.ToArray());
                        unzippedFiles.Add(new FileInfo(path));
                    }
                }
            }

            Assert.IsTrue(unzippedFiles.All(f => f.Exists));
        }
示例#19
0
 /// <summary>
 ///     Creates a new zip archive in memory from the temporary
 ///     files held by this instance
 /// </summary>
 /// <returns>
 ///    A <see cref="MemoryStream"/> containing the created zip archive
 /// </returns>
 private MemoryStream CreateArchiveFromTemporaryFiles()
 {
     return(FileZipper.ZipFiles(this.EnumerateFileOfTempCollection()));
 }
示例#20
0
 void decompress()
 {
     FileName = FileZipper.Decompress(FileName);
 }