public void CanUnzip_ExplicitDirectoryEntries() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientTestFolder emptyDir = source.CreateDirectory("emptyDir"); TransientTestFolder subDir = source.CreateDirectory("subDir"); subDir.CreateFile("F83E9633685494E53BEF3794EDEEE6A6.txt", "file3"); subDir.CreateFile("21D6D4596067723B3AC5DF9A8B3CBFE7.txt", "file4"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "F83E9633685494E53BEF3794EDEEE6A6.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "subdir", "21D6D4596067723B3AC5DF9A8B3CBFE7.txt"), () => _mockEngine.Log); Directory.Exists(Path.Combine(destination.Path, "emptyDir")); } }
public void LogsErrorIfExcludeContainsPropertyReferences() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Exclude = "$(Include)" }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3938", () => _mockEngine.Log); } }
public void CanUnzip() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); testEnvironment.CreateFile(source, "BE78A17D30144B549D21F71D5C633F7D.txt", "file1"); testEnvironment.CreateFile(source, "A04FF4B88DF14860B7C73A8E75A4FB76.txt", "file2"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "BE78A17D30144B549D21F71D5C633F7D.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "A04FF4B88DF14860B7C73A8E75A4FB76.txt"), () => _mockEngine.Log); } }
public void CanOverwriteReadOnlyFile() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "638AF4AE88A146E09CB69FE1CA7083DC.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("638AF4AE88A146E09CB69FE1CA7083DC", () => _mockEngine.Log); } }
public void CanUnzip_WithIncludeAndExcludeFilter() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFolder sub = source.CreateDirectory("sub"); testEnvironment.CreateFile(source, "file1.js", "file1"); testEnvironment.CreateFile(source, "file1.js.map", "file2"); testEnvironment.CreateFile(source, "file2.js", "file3"); testEnvironment.CreateFile(source, "readme.txt", "file4"); testEnvironment.CreateFile(sub, "subfile.js", "File5"); TransientZipArchive zipArchive = TransientZipArchive.Create(source, testEnvironment.CreateFolder(createFolder: true)); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(destination.Path), OverwriteReadOnlyFiles = true, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) }, Include = "*.js", Exclude = "*.js.map;sub\\*.js" }; unzip.Execute().ShouldBeTrue(() => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file1.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "file1.js.map"), () => _mockEngine.Log); _mockEngine.Log.ShouldContain(Path.Combine(destination.Path, "file2.js"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "readme.txt"), () => _mockEngine.Log); _mockEngine.Log.ShouldNotContain(Path.Combine(destination.Path, "sub", "subfile.js"), () => _mockEngine.Log); } }
public void LogsErrorIfReadOnlyFileCannotBeOverwitten() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder source = testEnvironment.CreateFolder(createFolder: true); TransientTestFolder destination = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file1 = testEnvironment.CreateFile(source, "D6DFD219DACE48F8B86EFCDF98433333.txt", "file1"); new FileInfo(file1.Path).IsReadOnly = true; TransientZipArchive zipArchive = TransientZipArchive.Create(source, destination); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(source.Path), OverwriteReadOnlyFiles = false, SkipUnchangedFiles = false, SourceFiles = new ITaskItem[] { new TaskItem(zipArchive.Path) } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain($"D6DFD219DACE48F8B86EFCDF98433333.txt{ (NativeMethodsShared.IsMono ? "\"" : "'") } is denied", () => _mockEngine.Log); } }
public void LogsErrorIfDirectoryCannotBeCreated() { Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(String.Empty) }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3931", () => _mockEngine.Log); }
public void LogsErrorIfSourceFileDoesNotExist() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(Path.Combine(testEnvironment.DefaultTestDirectory.Path, "foo.zip")), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3932", () => _mockEngine.Log); } }
public void LogsErrorIfSourceFileCannotBeOpened() { using (TestEnvironment testEnvironment = TestEnvironment.Create()) { TransientTestFolder folder = testEnvironment.CreateFolder(createFolder: false); TransientTestFile file = testEnvironment.CreateFile("foo.txt", "foo"); Unzip unzip = new Unzip { BuildEngine = _mockEngine, DestinationFolder = new TaskItem(folder.Path), SourceFiles = new ITaskItem[] { new TaskItem(file.Path), } }; unzip.Execute().ShouldBeFalse(() => _mockEngine.Log); _mockEngine.Log.ShouldContain("MSB3933", () => _mockEngine.Log); } }
public void UnzipExecute() { string testDir = TaskUtility.TestDirectory; string zipFileName = Path.Combine(testDir, ZipTest.ZIP_FILE_NAME); if (!File.Exists(zipFileName)) { Assert.Ignore("Zip file \"{0}\" not found; first run test that creates it", zipFileName); } ZipTest zip = new ZipTest(); zip.ZipExecute(); Unzip task = new Unzip(); task.BuildEngine = new MockBuild(); task.ZipFileName = zipFileName; task.TargetDirectory = Path.Combine(testDir, @"Backup"); Assert.IsTrue(task.Execute(), "Execute Failed"); }
public void ZipWithParallelCompression() { var task = new Zip(); task.BuildEngine = new MockBuild(); string testDir = TaskUtility.TestDirectory; string testFile = Path.Combine(testDir, "zip-128kb-test-1.dat"); const int numberOfBytes = 1024 * 128 * 9; if (File.Exists(testFile)) { File.Delete(testFile); } CreateTestFile(numberOfBytes, testFile); task.Files = new[] { new TaskItem(testFile) }; task.WorkingDirectory = testDir; task.ParallelCompression = true; task.ZipFileName = Path.Combine(testDir, ZIP_128KB_FILE_NAME); if (File.Exists(task.ZipFileName)) { File.Delete(task.ZipFileName); } // First zip up the file Assert.IsTrue(task.Execute(), "Execute Failed"); Assert.IsTrue(File.Exists(task.ZipFileName), "Zip file not found"); // Then delete the original, and try to unzip the file File.Delete(testFile); Unzip unzipTask = new Unzip(); unzipTask.BuildEngine = new MockBuild(); unzipTask.ZipFileName = task.ZipFileName; unzipTask.TargetDirectory = testDir; Assert.IsTrue(unzipTask.Execute()); }