public void SetsEngineDelay() { _engine = new AutomationEngineInstance(null); _setEngineDelay = new SetEngineDelayCommand(); string newDelay = "1000"; VariableMethods.CreateTestVariable(newDelay, _engine, "newDelay", typeof(string)); VariableMethods.CreateTestVariable(null, _engine, "var1", typeof(string)); VariableMethods.CreateTestVariable(null, _engine, "var2", typeof(string)); _setEngineDelay.v_EngineDelay = "{newDelay}"; _setEngineDelay.RunCommand(_engine); _setVariableCommand1 = new Variable.SetVariableCommand(); _setVariableCommand1.v_Input = "val1"; _setVariableCommand1.v_OutputUserVariableName = "{var1}"; _setVariableCommand2 = new Variable.SetVariableCommand(); _setVariableCommand2.v_Input = "val2"; _setVariableCommand2.v_OutputUserVariableName = "{var2}"; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); ScriptAction action1 = new ScriptAction(); action1.ScriptCommand = _setVariableCommand1; _engine.ExecuteCommand(action1); output.WriteLine(stopwatch.ElapsedMilliseconds.ToString()); Assert.True(stopwatch.ElapsedMilliseconds > 1000); ScriptAction action2 = new ScriptAction(); action2.ScriptCommand = _setVariableCommand2; _engine.ExecuteCommand(action2); output.WriteLine(stopwatch.ElapsedMilliseconds.ToString()); Assert.True(stopwatch.ElapsedMilliseconds > 2000); stopwatch.Stop(); Assert.Equal(int.Parse(newDelay), _engine.EngineSettings.DelayBetweenCommands); }
public async void ProcessesSwitch(string caseString) { _engine = new AutomationEngineInstance(null); _beginSwitch = new BeginSwitchCommand(); _case1 = new CaseCommand(); _defaultCase = new CaseCommand(); _endSwitch = new EndSwitchCommand(); _parentAction = new ScriptAction(); _setVariableCase1 = new Variable.SetVariableCommand(); _setVariableDefaultCase = new Variable.SetVariableCommand(); VariableMethods.CreateTestVariable(caseString, _engine, "caseInput", typeof(string)); VariableMethods.CreateTestVariable(null, _engine, "switchOutput", typeof(string)); _beginSwitch.v_SwitchValue = "{caseInput}"; _case1.v_CaseValue = "case1"; _defaultCase.v_CaseValue = "Default"; _setVariableCase1.v_Input = "case1Set"; _setVariableCase1.v_OutputUserVariableName = "{switchOutput}"; _setVariableDefaultCase.v_Input = "defaultCaseSet"; _setVariableDefaultCase.v_OutputUserVariableName = "{switchOutput}"; _parentAction.ScriptCommand = _beginSwitch; _parentAction.AddAdditionalAction(_case1); _parentAction.AddAdditionalAction(_setVariableCase1); _parentAction.AddAdditionalAction(_defaultCase); _parentAction.AddAdditionalAction(_setVariableDefaultCase); _parentAction.AddAdditionalAction(_endSwitch); _engine.ExecuteCommand(_parentAction); if (caseString.Equals("case1")) { Assert.Equal("case1Set", (string)await "{switchOutput}".EvaluateCode(_engine)); } else if (caseString.Equals("noCase")) { Assert.Equal("defaultCaseSet", (string)await "{switchOutput}".EvaluateCode(_engine)); } }
public void SetsEnginePreference() { _engine = new AutomationEngineInstance(null); _setEnginePreference = new SetEnginePreferenceCommand(); _setEnginePreference.v_CalculationOption = "Disable Automatic Calculations"; _setEnginePreference.RunCommand(_engine); Assert.False(_engine.AutoCalculateVariables); VariableMethods.CreateTestVariable(null, _engine, "output", typeof(string)); _setVariable = new Variable.SetVariableCommand(); _setVariable.v_Input = "1+1"; _setVariable.v_OutputUserVariableName = "{output}"; ScriptAction action = new ScriptAction(); action.ScriptCommand = _setVariable; _engine.ExecuteCommand(action); Assert.Equal("1+1", "{output}".ConvertUserVariableToString(_engine)); }
public void RunsTask() { _engine = new AutomationEngineInstance(null); _runTask = new RunTaskCommand(); _textFile = new TextFile.WriteCreateTextFileCommand(); _setVariable = new Variable.SetVariableCommand(); _taskScript = new Script(); List <ScriptVariable> variables = new List <ScriptVariable>(); ScriptVariable var1 = new ScriptVariable(); var1.VariableName = "output"; var1.VariableValue = "outputValue"; var1.VariableType = typeof(string); variables.Add(var1); _taskScript.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); // set script variables _taskScript.Variables = variables; List <ScriptArgument> arguments = new List <ScriptArgument>(); ScriptArgument arg1 = new ScriptArgument(); arg1.ArgumentName = "inputArg"; arg1.Direction = ScriptArgumentDirection.In; arg1.ArgumentValue = "default"; arg1.ArgumentType = typeof(string); arguments.Add(arg1); ScriptArgument arg2 = new ScriptArgument(); arg2.ArgumentName = "outputArg"; arg2.Direction = ScriptArgumentDirection.Out; arg2.ArgumentValue = "default"; arg2.AssignedVariable = "{outputVar}"; arg2.ArgumentType = typeof(string); arguments.Add(arg2); // set script arguments _taskScript.Arguments = arguments; string projectDirectory = Directory.GetParent(Environment.CurrentDirectory).Parent.FullName; string filePath = Path.Combine(projectDirectory, @"Resources"); _textFile.v_FilePath = Path.Combine(filePath, @"test.txt"); _textFile.v_TextToWrite = "{inputArg}"; _textFile.v_Overwrite = "Overwrite"; _engine.AutomationEngineContext.FilePath = Path.Combine(filePath, "task.obscript"); _engine.AutomationEngineContext.IsTest = true; List <ScriptAction> commands = new List <ScriptAction>(); ScriptAction com1 = new ScriptAction(); com1.ScriptCommand = _textFile; commands.Add(com1); _setVariable.v_Input = "outputValue"; _setVariable.v_OutputUserVariableName = "{outputArg}"; ScriptAction com2 = new ScriptAction(); com2.ScriptCommand = _setVariable; commands.Add(com2); _taskScript.Commands = commands; //write to file var serializerSettings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Objects, }; JsonSerializer serializer = JsonSerializer.Create(serializerSettings); using (StreamWriter sw = new StreamWriter(_engine.AutomationEngineContext.FilePath)) using (JsonWriter writer = new JsonTextWriter(sw) { Formatting = Formatting.Indented }) { serializer.Serialize(writer, _taskScript, typeof(Script)); } DataTable argumentTable = new DataTable(); argumentTable.Columns.Add("ArgumentName"); argumentTable.Columns.Add("ArgumentType"); argumentTable.Columns.Add("ArgumentValue"); argumentTable.Columns.Add("ArgumentDirection"); argumentTable.Columns[1].DataType = typeof(Type); DataRow arg1row = argumentTable.NewRow(); arg1row["ArgumentName"] = "inputArg"; arg1row["ArgumentType"] = typeof(string); arg1row["ArgumentValue"] = "{taskInput}"; arg1row["ArgumentDirection"] = "In"; DataRow arg2row = argumentTable.NewRow(); arg2row["ArgumentName"] = "outputArg"; arg2row["ArgumentType"] = typeof(string); arg2row["ArgumentValue"] = "{outputVar}"; arg2row["ArgumentDirection"] = "Out"; argumentTable.Rows.Add(arg1row); argumentTable.Rows.Add(arg2row); _runTask.v_TaskPath = _engine.AutomationEngineContext.FilePath; _runTask.v_AssignArguments = true; _runTask.v_ArgumentAssignments = argumentTable; List <ScriptAction> mainCommands = new List <ScriptAction>(); ScriptAction runTaskAction = new ScriptAction(); runTaskAction.ScriptCommand = _runTask; VariableMethods.CreateTestVariable("inputValue", _engine, "taskInput", typeof(string)); VariableMethods.CreateTestVariable("default", _engine, "taskOutput", typeof(string)); VariableMethods.CreateTestVariable(null, _engine, "outputVar", typeof(string)); _engine.ExecuteCommand(runTaskAction); Assert.Equal("outputValue", "{outputVar}".ConvertUserVariableToString(_engine)); Assert.True(OBIO.File.Exists(Path.Combine(filePath, @"test.txt"))); Assert.Equal("inputValue", OBIO.File.ReadAllText(Path.Combine(filePath, @"test.txt"))); OBIO.File.Delete(Path.Combine(filePath, @"test.txt")); OBIO.File.Delete(Path.Combine(filePath, @"task.obscript")); }