public static async Task Test_DownloadFile() { string downloadUrl = "http://www.quickzip.org/logo2.png"; string tempDirectory = "C:\\Temp"; string destFile = System.IO.Path.Combine(tempDirectory, "output.png"); IScriptCommand downloadCommand = CoreScriptCommands.Download("Url", "Stream", CoreScriptCommands.DiskParseOrCreateFile("{Profile}", "{DestinationFile}", "{Destination}", CoreScriptCommands.DiskOpenStream("{Destination}", "{DestinationStream}", FileExplorer.Defines.FileAccess.Write, CoreScriptCommands.CopyStream("{Stream}", "{DestinationStream}")))); //downloadCommand = ScriptCommands.DownloadFile("Url", "DestinationFile"); downloadCommand = serializeAndDeserializeCommand(downloadCommand); await ScriptRunner.RunScriptAsync(new ParameterDic() { { "Profile", new FileSystemInfoExProfile(null, null) }, { "Url", downloadUrl }, { "DestinationFile", destFile }, }, downloadCommand); }
public static async Task Test_CopyFile() { string tempDirectory = "C:\\Temp"; string srcFile = System.IO.Path.Combine(tempDirectory, "File1.txt"); string destFile = System.IO.Path.Combine(tempDirectory, "File2.txt"); string signature = "Created by testCopyFile at " + DateTime.Now.ToString(); Directory.CreateDirectory(tempDirectory); using (var sw = File.CreateText(srcFile)) sw.WriteLine(signature); //File.Delete(destFile); IProfile fsiProfile = new FileSystemInfoExProfile(null, null); IScriptCommand copyCommand = CoreScriptCommands.ParsePath("{Profile}", "{SourceFile}", "{Source}", CoreScriptCommands.DiskParseOrCreateFile("{Profile}", "{DestinationFile}", "{Destination}", CoreScriptCommands.DiskOpenStream("{Source}", "{SourceStream}", FileExplorer.Defines.FileAccess.Read, CoreScriptCommands.DiskOpenStream("{Destination}", "{DestinationStream}", FileExplorer.Defines.FileAccess.Write, CoreScriptCommands.CopyStream("{SourceStream}", "{DestinationStream}")))) , ResultCommand.Error(new FileNotFoundException(srcFile)) ); //copyCommand = ScriptCommands.CopyFile("SourceFile", "DestinationFile"); copyCommand = serializeAndDeserializeCommand(copyCommand); await ScriptRunner.RunScriptAsync(new ParameterDic() { { "Profile", fsiProfile }, { "SourceFile", srcFile }, { "DestinationFile", destFile } }, copyCommand); string actual = null; using (var sr = File.OpenText(destFile)) { actual = sr.ReadLine(); } Assert.AreEqual(signature, actual); }