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 Parentparam = testAction.GetParameter("BufferCredentials",false); // IEnumerable<IParameter> Childparam = Parentparam.GetChildParameters("BufferCredentials"); foreach (IParameter Param in testAction.Parameters) { if (Param.ActionMode == ActionMode.Input) { IInputValue inputValue = Param.GetAsInputValue(); Buffers.Instance.SetBuffer(Param.Name, Param.GetAsInputValue().Value, false); testAction.SetResultForParameter(Param, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set for value {1}", Param.Name, inputValue.Value)); } else { testAction.SetResultForParameter(Param, SpecialExecutionTaskResultState.Failed, string.Format("Fail")); } } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { foreach (IParameter parameter in testAction.Parameters) { //ActionMode input means set the buffer if (parameter.ActionMode == ActionMode.Input) { IInputValue inputValue = parameter.GetAsInputValue(); //Buffers.Instance.SetBuffer(parameter.Name, inputValue.Value); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", parameter.Name, inputValue.Value)); } //Otherwise we let TBox handle the verification. Other ActionModes like WaitOn will lead to an exception. else { //Don't need the return value of HandleActualValue in this case. //HandleActualValue(testAction, parameter, Buffers.Instance.GetBuffer(parameter.Name)); } } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { //Iterate over each TestStepValue foreach (IParameter parameter in testAction.Parameters) { //ActionMode input means set the buffer if (parameter.ActionMode == ActionMode.Input) { IInputValue inputValue = parameter.GetAsInputValue(); Buffers.Instance.SetBuffer(parameter.Name, inputValue.Value, false); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", parameter.Name, inputValue.Value)); } //Otherwise we let TBox handle the verification. Other ActionModes like WaitOn will lead to an exception. else { //Don't need the return value of HandleActualValue in this case. HandleActualValue(testAction, parameter, Buffers.Instance.GetBuffer(parameter.Name)); } } }
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); } }
private static void StartProgramWithoutWaitingForExit( ISpecialExecutionTaskTestAction testAction, ProcessStartInfo processStartInfo, string expandedPath, string processArguments, IParameter pathParameter) { try { Process.Start(processStartInfo); testAction.SetResult( SpecialExecutionTaskResultState.Ok, "Started: " + expandedPath + " with arguments: " + processArguments); } catch (Win32Exception e) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, CreateMessageForStartError(expandedPath, processArguments, e), e.StackTrace, ""); } }
private void StartProgramWithWaitForExit( ISpecialExecutionTaskTestAction testAction, IParameter exitParameter, ProcessStartInfo processStartInfo, IParameter pathParameter, string expandedPath, string processArguments) { if (exitParameter.GetAsInputValue().Verify("True", exitParameter.Operator) is FailedActionResult) { throw new InvalidOperationException( "Please use 'True' as value for " + exitParameter.Name + ". If you don't want to wait for exit of the application, please delete the node. The items below won't work without waiting for exit."); } IParameter stdoutParameter = exitParameter.GetChildParameter(StandardOutputFile, true); IParameter exitCodeParameter = exitParameter.GetChildParameter( ProcessExitCode, true, new[] { ActionMode.Buffer, ActionMode.Verify }); IInputValue timeoutForExitValue = exitParameter.GetChildParameterAsInputValue(TimeoutForExit, true); int timeoutForExit; if (timeoutForExitValue != null) { if (!int.TryParse(timeoutForExitValue.Value, out timeoutForExit)) { throw new InvalidOperationException( "Please use a valid integer value for the Parameter 'TimeoutForExit'"); } timeoutForExit = timeoutForExit * 1000; } else { timeoutForExit = int.MaxValue; } string output; try { int exitCode; bool wasTimeout; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); output = StartProcessWithWaitForExit( processStartInfo, stdoutParameter != null, timeoutForExit, out exitCode, out wasTimeout); stopwatch.Stop(); testAction.SetResult( SpecialExecutionTaskResultState.Ok, string.Format("Started '{0}' with arguments '{1}'", expandedPath, processArguments)); if (wasTimeout) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, string.Format( "Timeout occured, process didn't stop within the timeout of {0} seconds!", timeoutForExit / 1000)); } else { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Ok, string.Format( "Process stopped after '{0}' minutes.", Math.Round(stopwatch.Elapsed.TotalMinutes))); if (exitCodeParameter != null) { HandleActualValue(testAction, exitCodeParameter, exitCode); } } } catch (Win32Exception e) { testAction.SetResultForParameter( pathParameter, SpecialExecutionTaskResultState.Failed, CreateMessageForStartError(expandedPath, processArguments, e), e.StackTrace, ""); return; } if (stdoutParameter != null && output != null) { String filePath = Environment.ExpandEnvironmentVariables(stdoutParameter.GetAsInputValue().Value); File.WriteAllText(filePath, output); testAction.SetResultForParameter( stdoutParameter, new PassedActionResult( "The Standard-Output was saved inside the given file. See 'Details'-column for the path.", filePath, String.Empty)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { const string BEGINWHERE = " where 1=1 "; const string BEGINSELECT = " select "; const string BEGINORDER = " order by "; const string ORDERDIRECTION = " desc "; var connStringParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault( xParam => xParam.Name == "ConnectionString"); string connString = connStringParam.UnparsedValue; var tableNameParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "TableName"); string tableName = tableNameParam.UnparsedValue; var orderAttribParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "OrderAttribute"); string orderAttrib = orderAttribParam.UnparsedValue; string queryWhere = BEGINWHERE; string queryBegin = BEGINSELECT; string query = string.Empty; string queryOrder = string.Format("{0} {1} {2}", BEGINORDER, orderAttrib, ORDERDIRECTION); int count = 0; var constraints = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Constraint); if (constraints.Count > 0) { foreach (var parameter in constraints) { IInputValue value = parameter.Value as IInputValue; queryWhere += string.Format(" and {0} = '{1}' ", parameter.Name, value.Value); } } var buffersVerifies = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Verify || p.ActionMode == ActionMode.Buffer); if (buffersVerifies.Count == 0 ) { // No use in continuing if there is nothing to verify or buffer return; } queryBegin += String.Join(",", buffersVerifies.Select(p => p.Name).ToArray()); // Generate db query query = string.Format("{0} FROM {1} {2} {3}", queryBegin, tableName, queryWhere, queryOrder); // Connect to the database Datalink dl = new Datalink(); dl.ConnectionString = connString; if (!dl.IsValidSqlConnectionString()) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Cannot connect to the SQL database with the following connection string: {0}", connString)); return; } DataRow dr = dl.GetRowFromDb(query); // If there is not a result from the database, set the testresult to failed if (dr == null) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "No records found in with selected searchcriteria" ); return; } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Verify)) { IInputValue value = parameter.Value as IInputValue; if (value.Value == dr[parameter.Name].ToString()) { testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("{0}: Expected value {1} matches actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } else { count++; testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Failed, string.Format("Error {0}: Expected value {1} does not match actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Buffer)) { IInputValue buffer = parameter.Value as IInputValue; Buffers.Instance.SetBuffer(buffer.Value, dr[parameter.Name].ToString()); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", buffer.Value, dr[parameter.Name].ToString())); } if (count == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "All values match."); } else { int numberOfVerifies = buffersVerifies.Count(p => p.ActionMode == ActionMode.Verify); testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("{0} out of {1} values match.", numberOfVerifies - count, numberOfVerifies)); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { const string BEGINWHERE = " where 1=1 "; const string BEGINSELECT = " select "; const string BEGINORDER = " order by "; const string ORDERDIRECTION = " desc "; var connStringParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "ConnectionString"); string connString = connStringParam.UnparsedValue; var tableNameParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "TableName"); string tableName = tableNameParam.UnparsedValue; var orderAttribParam = testAction.SearchQuery.XParameters.ConfigurationParameters.FirstOrDefault(xParam => xParam.Name == "OrderAttribute"); string orderAttrib = orderAttribParam.UnparsedValue; string queryWhere = BEGINWHERE; string queryBegin = BEGINSELECT; string query = string.Empty; string queryOrder = string.Format("{0} {1} {2}", BEGINORDER, orderAttrib, ORDERDIRECTION); int count = 0; var constraints = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Constraint); if (constraints.Count > 0) { foreach (var parameter in constraints) { IInputValue value = parameter.Value as IInputValue; queryWhere += string.Format(" and {0} = '{1}' ", parameter.Name, value.Value); } } var buffersVerifies = testAction.Parameters.FindAll(p => p.ActionMode == ActionMode.Verify || p.ActionMode == ActionMode.Buffer); if (buffersVerifies.Count == 0) { // No use in continuing if there is nothing to verify or buffer return; } queryBegin += String.Join(",", buffersVerifies.Select(p => p.Name).ToArray()); // Generate db query query = string.Format("{0} FROM {1} {2} {3}", queryBegin, tableName, queryWhere, queryOrder); // Connect to the database Datalink dl = new Datalink(); dl.ConnectionString = connString; if (!dl.IsValidSqlConnectionString()) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Cannot connect to the SQL database with the following connection string: {0}", connString)); return; } DataRow dr = dl.GetRowFromDb(query); // If there is not a result from the database, set the testresult to failed if (dr == null) { testAction.SetResult(SpecialExecutionTaskResultState.Failed, "No records found in with selected searchcriteria"); return; } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Verify)) { IInputValue value = parameter.Value as IInputValue; if (value.Value == dr[parameter.Name].ToString()) { testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("{0}: Expected value {1} matches actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } else { count++; testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Failed, string.Format("Error {0}: Expected value {1} does not match actual value {2}.", parameter.Name, value.Value, dr[parameter.Name].ToString())); } } foreach (IParameter parameter in buffersVerifies.Where(p => p.ActionMode == ActionMode.Buffer)) { IInputValue buffer = parameter.Value as IInputValue; Buffers.Instance.SetBuffer(buffer.Value, dr[parameter.Name].ToString()); testAction.SetResultForParameter(parameter, SpecialExecutionTaskResultState.Ok, string.Format("Buffer {0} set to value {1}.", buffer.Value, dr[parameter.Name].ToString())); } if (count == 0) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, "All values match."); } else { int numberOfVerifies = buffersVerifies.Count(p => p.ActionMode == ActionMode.Verify); testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("{0} out of {1} values match.", numberOfVerifies - count, numberOfVerifies)); } }
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))); } }