public void Timeout() { Assert.ThrowsException <TimeoutException>(() => WorkflowTester.Run(new WaitDynamicFile() { Timeout = 2000 }, GetArgs(IOSamples.GetTestPath("output"), "*.txt"))); }
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 Initialize() { Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; var content = File.ReadAllText(IOSamples.GetSamplePath("primary.yml")); _config = new ConfigSection(new YamlSectionResolver(content)); }
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 InvalidSearchPattern() { Assert.ThrowsException <InvalidWorkflowException>(() => WorkflowTester.CompileAndRun(new CleanUpFolder { SearchPattern = new InArgument <int>(100) }, GetArgs(IOSamples.GetTestPath(), null))); }
public void Default() { var path = IOSamples.CreateFile("output/sample.txt"); var result = WorkflowTester.Run(new WaitFile(), GetArgs(path)); var info = result.Get(p => p.Result) as FileInfo; Assert.AreEqual("sample.txt", info.Name); }
public void Initialize() { IOSamples.ClearFolder(); IOSamples.CreateFolderAndFiles("output", "1.txt", "2.yml", "3.json"); IOSamples.CreateFolderAndFiles("output/A", "1.txt"); IOSamples.CreateFolderAndFiles("output/B", "1.txt", "2.yml"); IOSamples.CreateFolderAndFiles("output/C/D", "3.json"); IOSamples.CreateFolder("output/C/E"); }
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 void Initialize() { IOSamples.ClearFolder(); IOSamples.CreateFolderAndFiles("output", "T1.txt", "Y1.yml", "J1.json"); IOSamples.CreateFolderAndFiles("output/inner1", "T2.txt"); IOSamples.CreateFolderAndFiles("output/inner2", "Y2.yml"); IOSamples.CreateFolderAndFiles("output/inner3/deeper", "J2.json"); IOSamples.CreateFolderAndFiles("output/inner3/deeper", "T3.yml"); }
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 void Merge() { var content = File.ReadAllText(IOSamples.GetSamplePath("secondary.json")); var other = new ConfigSection(new JsonSectionResolver(content)); _config.Merge(other, true); Assert.AreEqual(1000, _config.AsInt("int")); Assert.IsFalse(_config.AsBoolean("boolean")); Assert.AreEqual(2, _config.AsInt("sub-section/level")); Assert.AreEqual("json", _config.AsString("sub-section/name")); }
public void Initialize() { Cleanup(); // excel.svg, hello.txt, link.png IOSamples.ExportSample("files1.zip"); // hello.txt // folder1/(excel.svg, hello.txt, link.png) // folder1/folder2/link.png IOSamples.ExportSample("files2.zip"); }
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); }
public void Initialize() { IOSamples.ClearFolder(); IOSamples.CreateFiles("T1.txt", "Y1.yml", "J1.json"); IOSamples.CreateFolderAndFiles("inner1", "T2.txt"); // empty folder IOSamples.CreateFolder("inner2"); IOSamples.CreateFolderAndFiles("inner3", "Y2.yml"); IOSamples.CreateFolderAndFiles("inner3/deeper", "J2.json", "T3.txt"); }
public void Default(string fileName, int files, int folders) { int filesCount = 0; var result = WorkflowTester.Run(new ZipEntriesCount { FilesCount = new System.Activities.OutArgument <int>(_ => filesCount) }, GetArgs(IOSamples.GetSamplePath(fileName))); Assert.AreEqual(files, filesCount); Assert.AreEqual(files, result.Get(p => p.FilesCount)); Assert.AreEqual(folders, result.Get(p => p.FoldersCount)); Assert.AreEqual(files + folders, result.Get(p => p.EntriesCount)); }
public void Advanced() { var sample = File.ReadAllText(IOSamples.GetSamplePath("advanced.yml")); var config = new ConfigSection(new YamlSectionResolver(sample)); Assert.IsTrue(config.HasSection("level-1")); Assert.IsTrue(config.HasSection("level-1/level-2")); Assert.IsTrue(config.HasKey("level-1/level-2/level-3")); Assert.IsTrue(config.HasSection("sub-1")); Assert.IsTrue(config.HasSection("sub-1/sub-2")); Assert.IsTrue(config.HasKey("sub-1/sub-2/sub-3")); }
[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()); }
public void LockedFile(int unlockAfterMs) { var path = IOSamples.CreateFile("output/sample.txt"); var fs = File.Open(path, FileMode.Append, FileAccess.Write); if (!IsLocked(path)) { Assert.Fail("File is not locked"); } Task.Delay(unlockAfterMs).ContinueWith(_ => { fs.Dispose(); if (IsLocked(path)) { Assert.Fail("File is not unlocked"); } }); WorkflowTester.Run(new WaitFile(), GetArgs(path)); Assert.IsFalse(IsLocked(path)); }