public void Update() { var zipFilePath = IOSamples.GetTestPath("output/result.zip"); WorkflowTester.CompileAndRun(new Zip { ToCompress = new InArgument <string>(IOSamples.GetTestPath("output/A")), CompressionLevel = CompressionLevel.NoCompression }, GetArgs(zipFilePath)); WorkflowTester.CompileAndRun(new Zip { ToCompress = new InArgument <string>(IOSamples.GetTestPath("output/1.txt")), CompressionLevel = CompressionLevel.Fastest }, GetArgs(zipFilePath)); WorkflowTester.CompileAndRun(new Zip { ToCompress = new InArgument <string>(IOSamples.GetTestPath("output/B/1.txt")), CompressionLevel = CompressionLevel.Optimal }, GetArgs(zipFilePath));; using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Read)) { Assert.AreEqual(1, zip.Entries.Count); } }
public void DifferentRoot(bool shortNames) { var zipFilePath = IOSamples.GetTestPath("output/result.zip"); var a = IOSamples.CreateFile("C:\\Temp\\T1\\a.txt"); var b = Path.GetFullPath(IOSamples.CreateFile("output/temp/T1/b.txt")).Replace("\\", "/"); // D: var c = Path.GetFullPath(IOSamples.CreateFile("output/temp/T2/c.txt")).Replace("\\", "/"); // D: var sources = new[] { a, b, c }; WorkflowTester.CompileAndRun(new Zip { ToCompress = new InArgument <string[]>(_ => sources), ShortEntryNames = shortNames }, GetArgs(zipFilePath)); File.Delete(a); using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Read)) { if (shortNames) { Assert.AreEqual("C\\a.txt", zip.Entries[0].FullName); Assert.AreEqual("D\\T1\\b.txt", zip.Entries[1].FullName); Assert.AreEqual("D\\T2\\c.txt", zip.Entries[2].FullName); } else { Assert.AreEqual(Path.GetFullPath(a).Replace(":", ""), zip.Entries[0].FullName); Assert.AreEqual(Path.GetFullPath(b).Replace(":", ""), zip.Entries[1].FullName); Assert.AreEqual(Path.GetFullPath(c).Replace(":", ""), zip.Entries[2].FullName); } } }
public void Default(bool deleteEmptyFolders, object searchPattern, int filesDeleted, int foldersDeleted) { InArgument pattern = null; if (searchPattern != null) { var value = searchPattern.ToString(); if (value.Contains(',')) { var values = value.Split(','); pattern = new InArgument <string[]>(_ => values); } else { pattern = new InArgument <string>(value); } } var folder = IOSamples.GetTestPath(); var output = WorkflowTester.CompileAndRun(new CleanUpFolder { DeleteEmptyFolders = deleteEmptyFolders, SearchPattern = pattern }, GetArgs(folder, null)); var result = (CleanUpFolderResult)output.Get(p => p.Result); Assert.AreEqual(filesDeleted, result.FilesDeleted); Assert.AreEqual(foldersDeleted, result.FoldersDeleted); Assert.AreEqual(filesDeleted + foldersDeleted, result.TotalDeleted); }
public void Timeout() { Assert.ThrowsException <TimeoutException>(() => WorkflowTester.Run(new WaitDynamicFile() { Timeout = 2000 }, GetArgs(IOSamples.GetTestPath("output"), "*.txt"))); }
public void InvalidSearchPattern() { Assert.ThrowsException <InvalidWorkflowException>(() => WorkflowTester.CompileAndRun(new CleanUpFolder { SearchPattern = new InArgument <int>(100) }, GetArgs(IOSamples.GetTestPath(), null))); }
public static void ChangeLastWriteTime() { File.SetLastWriteTime(IOSamples.GetTestPath("T1.txt"), DateTime.Now.AddMinutes(-1)); File.SetLastWriteTime(IOSamples.GetTestPath("Y1.yml"), DateTime.Now.AddMinutes(-3)); File.SetLastWriteTime(IOSamples.GetTestPath("J1.json"), DateTime.Now.AddMinutes(-3)); File.SetLastWriteTime(IOSamples.GetTestPath("inner1/T2.txt"), DateTime.Now.AddMinutes(-10)); File.SetLastWriteTime(IOSamples.GetTestPath("inner3/deeper/J2.json"), DateTime.Now.AddMinutes(-2)); File.SetLastWriteTime(IOSamples.GetTestPath("inner3/deeper/T3.txt"), DateTime.Now.AddMinutes(-2)); }
public async Task Default() { var createFile = CreateFileAfter(1); var result = WorkflowTester.Run(new WaitDynamicFile(), GetArgs(IOSamples.GetTestPath("output"), null)); var expectedFileName = await createFile.ConfigureAwait(false); var info = result.Get(p => p.Result) as FileInfo; Assert.AreEqual(Path.GetFullPath(expectedFileName), info.FullName); }
public void Default(string sampleFile, int expectedFilesCount, int expectedFoldersCount) { var extractTo = IOSamples.GetTestPath("unzip"); WorkflowTester.Run(new Unzip(), GetArgs(IOSamples.GetTestPath(sampleFile), extractTo)); var files = Directory.GetFiles(extractTo, "*", SearchOption.AllDirectories); var folders = Directory.GetDirectories(extractTo, "*", SearchOption.AllDirectories); Assert.AreEqual(expectedFilesCount, files.Length); Assert.AreEqual(expectedFoldersCount, folders.Length); }
public async Task SearchPattern() { _ = CreateFileAfter(1, ".json"); _ = CreateFileAfter(2, ".yml"); var createFile = CreateFileAfter(3, ".txt"); var result = WorkflowTester.Run(new WaitDynamicFile(), GetArgs(IOSamples.GetTestPath("output"), "*.txt")); var expectedFileName = await createFile.ConfigureAwait(false); var info = result.Get(p => p.Result) as FileInfo; Assert.AreEqual(Path.GetFullPath(expectedFileName), info.FullName); }
public void OLE2(string file) { var path = IOSamples.GetTestPath(file); var args = new Dictionary <string, object> { { nameof(GetSheetNames.WorkbookPath), path } }; var result = WorkflowTester.Invoke(new GetSheetNames(), args); CollectionAssert.AreEqual(new[] { "Sheet1", "Sheet2", "Sheet3", "Sheet4" }, result); }
[DataRow(1, 30000)] // clamps 20000 public async Task Intervals(int secondsToCreateFile, int interval) { var createFile = CreateFileAfter(secondsToCreateFile, ".txt"); var result = WorkflowTester.Run(new WaitDynamicFile { Interval = interval }, GetArgs(IOSamples.GetTestPath("output"), "*.txt")); var expectedFileName = await createFile.ConfigureAwait(false); var info = result.Get(p => p.Result) as FileInfo; Assert.AreEqual(Path.GetFullPath(expectedFileName), info.FullName); }
public async Task WaitForExistAndInterval(int interval) { var createFile = CreateFileAfter(3, ".json"); var result = WorkflowTester.Run(new WaitFile { WaitForExist = true, Interval = interval, }, GetArgs(IOSamples.GetTestPath("output/sample.json"))); var expectedFileName = await createFile.ConfigureAwait(false); var info = result.Get(p => p.Result) as FileInfo; Assert.AreEqual("sample.json", info.Name); }
public void Default(string searchPattern, SearchOption option) { var path = IOSamples.GetTestPath("output"); var enumFiles = Directory.EnumerateFiles(path, searchPattern ?? "*", option); var result = WorkflowTester.CompileAndInvoke(new EnumerateFiles() { Path = new InArgument <string>(path), SearchPattern = new InArgument <string>(searchPattern), SearchOption = option }); CollectionAssert.AreEqual(enumFiles.ToList(), result.ToList()); }
public void LastWriteTime(bool deleteEmptyFolders, int minutesToAdd, int filesDeleted, int foldersDeleted) { ChangeLastWriteTime(); var folder = IOSamples.GetTestPath(); var output = WorkflowTester.CompileAndRun(new CleanUpFolder { DeleteEmptyFolders = deleteEmptyFolders }, GetArgs(folder, DateTime.Now.AddMinutes(minutesToAdd))); var result = (CleanUpFolderResult)output.Get(p => p.Result); Assert.AreEqual(filesDeleted, result.FilesDeleted); Assert.AreEqual(foldersDeleted, result.FoldersDeleted); Assert.AreEqual(filesDeleted + foldersDeleted, result.TotalDeleted); }
public void MultiplePathsAndPatterns() { var path1 = IOSamples.GetTestPath("output"); var path2 = IOSamples.GetTestPath("output/inner3/deeper"); var result = WorkflowTester.CompileAndInvoke(new EnumerateFiles() { Path = new InArgument <string[]>(_ => new[] { path1, path2 }), SearchPattern = new InArgument <string[]>(_ => new[] { "*.json", "*.txt" }), SearchOption = SearchOption.TopDirectoryOnly }); var path1Res = Directory.EnumerateFiles(path1, "*.*", SearchOption.TopDirectoryOnly).Where(path => Path.GetExtension(path) != ".yml"); var path2Res = Directory.EnumerateFiles(path2, "*.json", SearchOption.TopDirectoryOnly); CollectionAssert.AreEqual(path1Res.Concat(path2Res).ToArray(), result.ToArray()); }
public void Override() { var files1 = IOSamples.GetTestPath("files1.zip"); var files2 = IOSamples.GetTestPath("files2.zip"); var extractTo = IOSamples.GetTestPath("unzip"); WorkflowTester.Run(new Unzip(), GetArgs(files1, extractTo)); Assert.ThrowsException <IOException>(() => WorkflowTester.Run(new Unzip { Overwrite = false }, GetArgs(files2, extractTo))); // no error WorkflowTester.Run(new Unzip { Overwrite = true }, GetArgs(files2, extractTo)); }
public void OLE2(string file, int sheetIndex, string expectedSheetName) { var path = IOSamples.GetTestPath(file); var args = new Dictionary <string, object> { { nameof(GetSheetName.WorkbookPath), path }, { nameof(GetSheetName.SheetIndex), sheetIndex }, }; var workflow = new GetSheetName { UseScope = false }; var result = WorkflowTester.Invoke(workflow, args); Assert.AreEqual(expectedSheetName, result); }
public void Timeout(bool waitForExist) { IOSamples.CreateFolder("output"); object exec() => WorkflowTester.Run(new WaitFile() { Timeout = 2000, WaitForExist = waitForExist, }, GetArgs(IOSamples.GetTestPath("output/missing.txt"))); if (waitForExist) { Assert.ThrowsException <TimeoutException>(exec); } else { Assert.ThrowsException <FileNotFoundException>(exec); } }
public void SameRoot() { var zipFilePath = IOSamples.GetTestPath("output/result.zip"); var sources = new[] { IOSamples.GetTestPath("output/A"), IOSamples.GetTestPath("output/B"), IOSamples.GetTestPath("output/C") }; WorkflowTester.CompileAndRun(new Zip { ToCompress = new InArgument <string[]>(_ => sources), }, GetArgs(zipFilePath)); using (var zip = ZipFile.Open(zipFilePath, ZipArchiveMode.Read)) { Assert.AreEqual(5, zip.Entries.Count); Assert.AreEqual(4, zip.Entries.Count(entry => !string.IsNullOrEmpty(entry.Name))); } }
public void Attributes(FileAttributes attrToSet, FileAttributes attrToExclude, int filesToAffect, int expectedCount) { var path = IOSamples.GetTestPath("output"); var filesToChange = Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories) .OrderBy(_ => Guid.NewGuid()) .Take(filesToAffect) .Select(p => new FileInfo(p)).ToArray(); foreach (var f in filesToChange) { f.Attributes = attrToSet; } var result = WorkflowTester.CompileAndInvoke(new EnumerateFiles() { Path = new InArgument <string>(IOSamples.GetTestPath("output")), SearchOption = SearchOption.AllDirectories, Exclusions = attrToExclude }); Assert.AreEqual(expectedCount, result.Count()); }