Example #1
0
        public void AddNoFileToArchiveFails()
        {
            string zipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".zip");

            Assert.IsFalse(ZipUtilities.AddFileToArchive(zipPath, null));
            Assert.IsFalse(ZipUtilities.AddFileToArchive(zipPath, string.Empty));
        }
Example #2
0
        public void FailsOnMissingOutputDirTest()
        {
            string ticks         = $"{DateTime.Now.Ticks}";
            string directoryName = $"dir{ticks}";
            string directoryPath = Path.Combine(Path.GetTempPath(), directoryName);
            string zipPath       = Path.Combine(directoryPath, $"source{ticks}.zip");
            string outputDir     = Path.Combine(directoryPath, "output");

            // Create empty directory
            Directory.CreateDirectory(directoryPath);
            Assert.IsTrue(Directory.Exists(directoryPath));

            // Create file with some data
            string fileName = $"file{ticks}.txt";
            string filePath = Path.Combine(directoryPath, fileName);

            File.WriteAllText(filePath, $"{this.GetType()}");
            Assert.IsTrue(File.Exists(filePath));

            ZipUtilities.AddFileToArchive(zipPath, filePath);
            Assert.IsTrue(File.Exists(zipPath));

            // With instance arguments
            IAction action = new UnzipArchiveAction()
            {
                SourceZipPath = zipPath,
            };

            var actionResult = action.Execute(ArgumentCollection.New());

            Assert.IsNotNull(actionResult);
            Assert.IsFalse(actionResult.Result);
            Assert.IsNotNull(actionResult.AttachedException);

            // With output dir defined in execution arguments
            ((UnzipArchiveAction)action).SourceZipPath = null;
            action.Execute(ArgumentCollection.New()
                           .WithArgument(UnzipArchiveActionExecutionArgs.SourceZipPath, zipPath)
                           );

            Assert.IsNotNull(actionResult);
            Assert.IsFalse(actionResult.Result);
            Assert.IsNotNull(actionResult.AttachedException);



            // Cleanup
            if (Directory.Exists(outputDir))
            {
                Directory.Delete(outputDir, true);
            }

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

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

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