public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter expectedFilePathParameter = testAction.GetParameter("ExpectedFile", false, new[] { ActionMode.Input }); IParameter actualFilePathParameter = testAction.GetParameter("ActualFile", false, new[] { ActionMode.Input }); string expectedFilePath = Environment.ExpandEnvironmentVariables(expectedFilePathParameter.GetAsInputValue().Value); string actualFilePath = Environment.ExpandEnvironmentVariables(actualFilePathParameter.GetAsInputValue().Value); string result = String.Empty; try { result = FileComparer.Compare(expectedFilePath, actualFilePath); } catch (FileNotFoundException exc) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, exc.Message); return; } if (result == String.Empty) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "The contents of the files are identical."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, result); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPfile = testAction.GetParameter("File", false, new[] { ActionMode.Input }); IParameter IPinverse = testAction.GetParameter("Exists", false, new[] { ActionMode.Input }); string file = IPfile.GetAsInputValue().Value; string inverseString = IPinverse.GetAsInputValue().Value; bool fileExists; // if this is true, the file should exists. Default value should be true bool result; bool success = Boolean.TryParse(inverseString, out fileExists); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "Inverse has to be an boolean"); return; } if (FileOrDirectoryExists(file)) { result = fileExists; //if the file is found, the value of fileExists will be returned. } else { result = !fileExists; //if the file is not found, the inverse of fileExists will be returned. } if (result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Correct"); return; } testAction.SetResult(SpecialExecutionTaskResultState.Failed, "Incorrect"); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPconnString = testAction.GetParameter("ConnectionString", false, new[] { ActionMode.Input }); IParameter IPquery = testAction.GetParameter("Query", false, new[] { ActionMode.Input }); IParameter IPresult = testAction.GetParameter("Result", true, new[] { ActionMode.Verify, ActionMode.Buffer }); string connString = IPconnString.GetAsInputValue().Value; string query = IPquery.GetAsInputValue().Value; if (File.Exists(query)) { query = File.ReadAllText(query); } Datalink dl = new Datalink(connString); if (!dl.IsValidSqlConnectionString()) { throw new InvalidOperationException("Connectionstring is not valid or the database cannot be reached"); } string result = dl.Execute(query); if (IPresult != null) { IInputValue expectedResult = IPresult.Value as IInputValue; if (IPresult.ActionMode == ActionMode.Buffer) { Buffers.Instance.SetBuffer(expectedResult.Value, result); testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", expectedResult.Value, result)); return; } if (expectedResult.Value == result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Actual rows match expected number of rows."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Expected result: {0}. Actual result {1}. Incorrect", expectedResult.Value, result.ToString())); } } else { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Query executed"); } }
protected static ProcessStartInfo CreateProcessStartInfo( ISpecialExecutionTaskTestAction testAction, IParameter pathParameter, out string processArguments, out string expandedPath) { IInputValue path = pathParameter.GetAsInputValue(); IInputValue directoryValue = testAction.GetParameterAsInputValue(Directory, true); IParameter argumentsParameter = testAction.GetParameter(Arguments, true); processArguments = string.Empty; if (string.IsNullOrEmpty(path.Value)) { throw new ArgumentException("Mandatory parameter '{Path}' not set."); } string directory = GetDirectory(directoryValue); if (argumentsParameter != null) { processArguments = ParseArguments(argumentsParameter); } expandedPath = Environment.ExpandEnvironmentVariables(path.Value); ProcessStartInfo processStartInfo = new ProcessStartInfo(expandedPath, processArguments); if (!string.IsNullOrEmpty(directory)) { processStartInfo.WorkingDirectory = directory; } return(processStartInfo); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IInputValue path = testAction.GetParameterAsInputValue("Path"); //IParameter result = testAction.GetParameter("Result"); IParameter buffers = testAction.GetParameter("Buffers", true); IEnumerable <IParameter> arguments = buffers.GetChildParameters("Buffer"); string returnValue = ExtractString(path.Value); string[] words = returnValue.Split(','); if (words.Length == arguments.Count()) { int index = 0; string resultText = "Buffers Created:"; foreach (IParameter argument in arguments) { IInputValue arg = argument.Value as IInputValue; Buffers.Instance.SetBuffer(arg.Value, words[index], false); resultText = resultText + Environment.NewLine + "Name: " + arg.Value + Environment.NewLine + "Value: " + words[index]; index = index + 1; } testAction.SetResultForParameter(buffers, SpecialExecutionTaskResultState.Ok, string.Format(resultText)); } else { testAction.SetResultForParameter(buffers, SpecialExecutionTaskResultState.Failed, string.Format("File does not have all the buffers!")); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPconnString = testAction.GetParameter("ConnectionString", false, new[] { ActionMode.Input }); IParameter IPquery = testAction.GetParameter("Query", false, new[] { ActionMode.Input }); IParameter IPresult = testAction.GetParameter("Result", true, new[] { ActionMode.Verify, ActionMode.Buffer }); string connString = IPconnString.GetAsInputValue().Value; string query = IPquery.GetAsInputValue().Value; if (File.Exists(query)) { query = File.ReadAllText(query); } Datalink dl = new Datalink(connString); if (!dl.IsValidSqlConnectionString()) { throw new InvalidOperationException("Connectionstring is not valid or the database cannot be reached"); } string result = dl.Execute(query); if (IPresult != null ) { IInputValue expectedResult = IPresult.Value as IInputValue; if (IPresult.ActionMode == ActionMode.Buffer) { Buffers.Instance.SetBuffer(expectedResult.Value, result); testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.",expectedResult.Value, result)); return; } if (expectedResult.Value == result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Actual rows match expected number of rows."); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Expected result: {0}. Actual result {1}. Incorrect", expectedResult.Value, result.ToString())); } } else { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "Query executed"); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPprocess = testAction.GetParameter("Process", false, new[] { ActionMode.Input }); IParameter IPwaittimesecs = testAction.GetParameter("WaitTimeSecs", false, new[] { ActionMode.Input }); string process = IPprocess.GetAsInputValue().Value; string waittimesecsString = IPwaittimesecs.GetAsInputValue().Value; short waittimesecs = 0; bool success = Int16.TryParse(waittimesecsString, out waittimesecs); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "WaitTimeSecs has to be an integer"); return; } if (waittimesecs == 0) { waittimesecs = DEFAULTWAITTIME; } Process[] pname = Process.GetProcessesByName(process); if (pname.Length == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} already ended or not started", process)); return; } short counter = 0; while (counter < waittimesecs) { counter++; Thread.Sleep(1000); pname = Process.GetProcessesByName(process); if (pname.Length == 0) { break; } } testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} has ended after {1} seconds", process, counter)); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter pathParameter = testAction.GetParameter(Path); string processArguments = null, expandedPath = null; ProcessStartInfo processStartInfo = null; try { processStartInfo = CreateProcessStartInfo( testAction, pathParameter, out processArguments, out expandedPath); } catch (FileNotFoundException e) { testAction.SetResultForParameter(pathParameter, new UnknownFailedActionResult("Cannot find the given file'.", e.ToString(), expandedPath ?? string.Empty)); return; } IParameter exitParameter = testAction.GetParameter(WaitForExit, true, new[] { ActionMode.Select }); if (exitParameter != null) { StartProgramWithWaitForExit( testAction, exitParameter, processStartInfo, pathParameter, expandedPath, processArguments); } else { StartProgramWithoutWaitingForExit( testAction, processStartInfo, expandedPath, processArguments, pathParameter); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { IParameter IPprocess = testAction.GetParameter("Process", false, new[] { ActionMode.Input }); IParameter IPwaittimesecs = testAction.GetParameter("WaitTimeSecs", false, new[] { ActionMode.Input }); string process = IPprocess.GetAsInputValue().Value; string waittimesecsString = IPwaittimesecs.GetAsInputValue().Value; short waittimesecs = 0; bool success = Int16.TryParse(waittimesecsString, out waittimesecs); if (!success) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "WaitTimeSecs has to be an integer"); return; } if (waittimesecs == 0) waittimesecs = DEFAULTWAITTIME; Process[] pname = Process.GetProcessesByName(process); if (pname.Length == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} already ended or not started", process)); return; } short counter = 0; while (counter < waittimesecs) { counter++; Thread.Sleep(1000); pname = Process.GetProcessesByName(process); if (pname.Length == 0) break; } testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Proces {0} has ended after {1} seconds", process, counter)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { IInputValue path = testAction.GetParameterAsInputValue(Path, false); IParameter parameter = testAction.GetParameter(Arguments, true); string processArguments = string.Empty; if (path == null || string.IsNullOrEmpty(path.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", Path)); } if (parameter != null) { IEnumerable <IParameter> arguments = parameter.GetChildParameters(Argument); //Get Input value of each argument foreach (IParameter argument in arguments) { IInputValue processArgument = argument.Value as IInputValue; processArguments += processArgument.Value + " "; } } try { Process.Start(path.Value, processArguments); } catch (Win32Exception) { return(new UnknownFailedActionResult("Could not start program", string.Format( "Failed while trying to start:\nPath: {0}\r\nArguments: {1}", path.Value, processArguments), "")); } return(new PassedActionResult("Started successfully")); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String time = String.Empty; string hmacSignatureString = String.Empty; //TestStep Parameters IInputValue key = testAction.GetParameterAsInputValue(Key, false); IInputValue secret = testAction.GetParameterAsInputValue(Secret, false); IInputValue method = testAction.GetParameterAsInputValue(Method, false); IInputValue payload = testAction.GetParameterAsInputValue(Payload, false); IInputValue timeStamp = testAction.GetParameterAsInputValue(TimeStamp, true); IParameter hmacSignature = testAction.GetParameter("HMAC Signature", false, new[] { ActionMode.Buffer, ActionMode.Verify }); if (key == null || string.IsNullOrEmpty(key.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", key)); } if (secret == null || string.IsNullOrEmpty(secret.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", secret)); } if (method == null || string.IsNullOrEmpty(method.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", method)); } if (payload == null || string.IsNullOrEmpty(payload.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", payload)); } //Use timestamp from TestStep parameter otherwise generate one autmatically time = (timeStamp == null) ? GetTime().ToString() : timeStamp.Value.ToString(); //Get HMAC Signature from the provided parameters hmacSignatureString = GetHmacSignature(key, secret, method, payload, time); if (string.IsNullOrEmpty(hmacSignatureString)) { testAction.SetResultForParameter(hmacSignature, SpecialExecutionTaskResultState.Failed, "The HMAC Signature was empty or null."); return(new UnknownFailedActionResult("Could not create HMAC Signature", string.Format("Failed while trying to start:\nKey:\r\n {0}\r\nSecret: {1}\r\nMethod: {2}\r\nPayload: {3}\r\nTimeStamp: {4}", key.Value, secret.Value, method.Value, payload.Value, time), "")); } else { HandleActualValue(testAction, hmacSignature, hmacSignatureString); return(new PassedActionResult(String.Format("HMAC: {0}\r\n\r\nValues:\r\nKey: {1}\r\nSecret: {2}\r\nMethod: {3}\r\nPayload:\r\n{4}\r\nTimeStamp: {5} ", hmacSignatureString, key.Value, secret.Value, method.Value, payload.Value, time))); } }