public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraTargetHost = testAction.GetParameterAsInputValue("Host", false).Value; if (string.IsNullOrEmpty(paraTargetHost)) { throw new ArgumentException(string.Format("Es muss ein Ziel (Host) angegeben sein.")); } string paraMessage = testAction.GetParameterAsInputValue("Message", false).Value; if (string.IsNullOrEmpty(paraMessage)) { throw new ArgumentException(string.Format("Es muss eine Message angegeben sein.")); } string paraApi = testAction.GetParameterAsInputValue("API", false).Value; if (string.IsNullOrEmpty(paraApi)) { throw new ArgumentException(string.Format("Es muss eine API angegeben sein.")); } Uri checkRequest = new Uri(string.Format("http://{0}/checkMessage/?api={1}", paraTargetHost, paraApi)); GetResponse(checkRequest); return(new PassedActionResult("Check result for request " + checkRequest)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String endPoint = testAction.GetParameterAsInputValue("EndPoint", false).Value; String repositoryName = testAction.GetParameterAsInputValue("Repository", false).Value; if (string.IsNullOrEmpty(endPoint)) { throw new ArgumentException("End Point is a mandatory parameter."); } else { if (!endPoint.EndsWith("/")) { endPoint += "/"; } } if (string.IsNullOrEmpty(repositoryName)) { throw new ArgumentException("Repository Name is a mandatory parameter."); } var client = new RestClient(new Uri(endPoint + "configuration/repositories/" + repositoryName)); var request = new RestRequest(Method.DELETE); IRestResponse response = client.Execute(request); HttpStatusCode statusMessage = response.StatusCode; int statusCode = (int)statusMessage; return(new PassedActionResult("Got response: " + statusCode + " " + statusMessage)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { IInputValue setfailed = testAction.GetParameterAsInputValue(c_SetFailed, false); IInputValue failuretyp = testAction.GetParameterAsInputValue(c_FailureTyp, false); IInputValue message = testAction.GetParameterAsInputValue(c_Message, false); if (string.IsNullOrEmpty(setfailed.Value)) { t_setfailed = "Failed"; } else { t_setfailed = setfailed.Value; } if (!string.IsNullOrEmpty(failuretyp.Value)) { t_failuretyp = failuretyp.Value; } if (!string.IsNullOrEmpty(message.Value)) { t_message = message.Value; } string message_all = "Failuretyp: " + t_failuretyp + "; Message: " + t_message; if (t_setfailed == "Failed") { try { if (t_failuretyp == "Warn" || t_failuretyp == "Absence" || t_failuretyp == "Missing") { return(new PassedActionResult("Test " + t_setfailed + " > " + message_all + " <")); } if (t_failuretyp == "Other Failure") { return(new PassedActionResult("Test " + t_setfailed + " > " + message_all + " <")); } else { throw (new TestFailedException("Test " + t_setfailed + " > " + message_all + " <")); } } catch (TestFailedException e) { throw (new TestFailedException("Test " + t_setfailed + " > " + message_all + " <\r\n", e)); } finally { } // return new PassedActionResult("Test failed: " + message_all); } return(new PassedActionResult("Passed successfully: " + message_all)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { bool completed = false; string returnMsg = ""; IInputValue paramURL = testAction.GetParameterAsInputValue(URL, false); IInputValue paramIsNewTab = testAction.GetParameterAsInputValue(isNewTab, false); if (paramURL == null || string.IsNullOrEmpty(paramURL.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", URL)); } if (paramIsNewTab == null || string.IsNullOrEmpty(paramIsNewTab.Value)) { throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", isNewTab)); } try { if (paramIsNewTab.Value == "True") { ShellWindows shellWindows = new ShellWindows(); //Uses SHDocVw to get the Internet Explorer Instances foreach (SHDocVw.InternetExplorer internetExplorerInstance in shellWindows) { string url = internetExplorerInstance.LocationURL; if (!url.Contains("file:///")) { internetExplorerInstance.Navigate(paramURL.Value, 0x800); completed = true; returnMsg = "URL opened in new tab"; break; } } } if (!completed) // To open url in new window { Process procInNewWndow = new Process(); procInNewWndow.StartInfo.FileName = "C:\\Program Files\\Internet Explorer\\iexplore.exe"; procInNewWndow.StartInfo.Arguments = paramURL.Value; procInNewWndow.StartInfo.UseShellExecute = true; procInNewWndow.StartInfo.CreateNoWindow = false; procInNewWndow.Start(); returnMsg = "URL opened in new window"; } } catch (Exception) { return(new UnknownFailedActionResult("Could not start program", string.Format( "Failed while trying to start:\nURL: {0}\r\nIsNewTab: {1}", paramURL.Value, paramIsNewTab.Value), "")); } return(new PassedActionResult(returnMsg)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String relay = testAction.GetParameterAsInputValue("relay", false).Value; if (string.IsNullOrEmpty(relay)) { throw new ArgumentException(string.Format("Es muss ein SMTP Relay angegeben sein.")); } String sendTo = testAction.GetParameterAsInputValue("to", false).Value; if (string.IsNullOrEmpty(sendTo)) { throw new ArgumentException(string.Format("Es muss ein Empfänger angegeben werden.")); } String sendFrom = testAction.GetParameterAsInputValue("from", false).Value; if (string.IsNullOrEmpty(sendFrom)) { throw new ArgumentException(string.Format("Es muss ein Absender angegeben werden.")); } String msgSubject = testAction.GetParameterAsInputValue("subject", false).Value; if (string.IsNullOrEmpty(msgSubject)) { throw new ArgumentException(string.Format("Es muss ein Betreff angegeben sein.")); } String msgBody = testAction.GetParameterAsInputValue("body", false).Value; if (string.IsNullOrEmpty(msgBody)) { throw new ArgumentException(string.Format("Es muss ein Text (Body) angegeben sein.")); } MailMessage message = new MailMessage(sendFrom, sendTo); message.Subject = msgSubject; message.Body = @msgBody; using (SmtpClient client = new SmtpClient(relay)) { // client.UseDefaultCredentials = true; try { client.Send(message); return(new PassedActionResult("Message successfully sent.")); } catch (Exception ex) { return(new NotFoundFailedActionResult("Exception caught in CreateTestMessage2(): {0}", ex.ToString())); } finally { } } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraBuffer = testAction.GetParameterAsInputValue("Directory", false).Value; if (string.IsNullOrEmpty(paraBuffer)) { throw new ArgumentException(string.Format("Es muss ein Verzeichnis angegeben sein.")); } int countFiles = 0; if (Directory.Exists(paraBuffer)) { string [] fileEntries = Directory.GetFiles(paraBuffer); foreach (string fileName in fileEntries) { File.Delete(fileName); countFiles++; } } else { throw new ArgumentException(string.Format("Es wurde kein Verzeichnis angegeben.")); } return(new PassedActionResult(string.Format("Removed files: {0}", countFiles))); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraSettingsFile = testAction.GetParameterAsInputValue("File", false).Value; if (string.IsNullOrEmpty(paraSettingsFile)) { throw new ArgumentException(string.Format("Es muss eine Settingsdatei (File) angegeben sein.")); } if (!Collections.Instance.CollectionExists(BufferCollectionPath)) { throw new InvalidOperationException("Es existiert keine Buffer-Collection in den Einstellungen!"); } XmlDocument doc = new XmlDocument(); doc.Load(paraSettingsFile); XmlNode SettingsListNode = doc.SelectSingleNode("/root"); XmlNodeList SettingsNodeList = SettingsListNode.SelectNodes("CollectionEntry"); foreach (XmlNode node in SettingsNodeList) { string key = node.Attributes.GetNamedItem("name").Value; string value = node.InnerText; Buffers.Instance.SetBuffer(key, value, false); } return(new PassedActionResult("settings loaded from : " + paraSettingsFile)); }
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 ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String base64ImageRepresentation = testAction.GetParameterAsInputValue("Payload", false).Value; String targetFile = testAction.GetParameterAsInputValue("TargetFile", false).Value; if (targetFile != null && base64ImageRepresentation != null) { System.IO.File.WriteAllBytes(targetFile, Convert.FromBase64String(base64ImageRepresentation)); } else { throw new ArgumentException(); } return(new PassedActionResult("Decoding File successfully completed")); }
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 ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String sourceFile = testAction.GetParameterAsInputValue("InputFile", false).Value; String bufferParameterName = testAction.GetParameterAsInputValue("BufferParamName", false).Value; if (sourceFile != null && bufferParameterName != null) { string base64ImageRepresentation = Convert.ToBase64String(System.IO.File.ReadAllBytes(sourceFile)); Buffers.Instance.SetBuffer(bufferParameterName, base64ImageRepresentation, false); } else { throw new ArgumentException(); } return(new PassedActionResult("Encoding File successfully completed")); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { IInputValue FilePath = testAction.GetParameterAsInputValue("FilePath", false); //isOptional=true Process.Start(FilePath.Value); return(new PassedActionResult("File Opened Successfully")); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String filePath = testAction.GetParameterAsInputValue("FilePath", false).Value; String rowNumber = testAction.GetParameterAsInputValue("RowNumber", false).Value; if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException(string.Format("Text file path is required.")); } if (string.IsNullOrEmpty(rowNumber)) { throw new ArgumentException(string.Format("Row number with column names is required.")); } int i = 0; int row = Int32.Parse(rowNumber); int[] columnSize = { 14, 3, 4, 7, 7, 3, 3, 3, 10, 3, 6, 2, 5, 8, 6, 10, 13, 9, 8, 3, 16, 25, 8 }; string resultString = "Column Names: "; string[] lines = File.ReadAllLines(filePath); foreach (string line in lines) { if (line.Equals(lines[row - 1]) && i == 0) { string columnNames = line.Substring(1); int columnLength = 0; for (int x = 0; x < columnSize.Length; x++) { columnLength = columnSize[x]; resultString += columnNames.Substring(i, columnLength + 1).Trim() + ", "; i = i + columnLength + 1; } } } return(new PassedActionResult(resultString)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraBuffer = testAction.GetParameterAsInputValue("Value", false).Value; if (string.IsNullOrEmpty(paraBuffer)) { throw new ArgumentException(string.Format("Es muss ein Buffer angegeben sein.")); } return(new PassedActionResult(paraBuffer)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { IInputValue showinfo = testAction.GetParameterAsInputValue(c_ShowInfo, false); /* * if (showinfo == null || string.IsNullOrEmpty(showinfo.Value)) * throw new ArgumentException(string.Format("Mandatory parameter '{0}' not set.", c_ShowInfo)); */ return(new PassedActionResult("Info: " + showinfo.Value)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { try { IInputValue buffer = testAction.GetParameterAsInputValue("Buffer Name", false, new[] { ActionMode.Input }); IInputValue folder = testAction.GetParameterAsInputValue("Folder Path", false, new[] { ActionMode.Input }); IInputValue fileName = testAction.GetParameterAsInputValue("File Name", false, new[] { ActionMode.Input }); string fileContent = Buffers.Instance.GetBuffer(buffer.Value); if (fileContent.StartsWith("\"") && fileContent.EndsWith("\"")) { fileContent = fileContent.TrimStart('"').TrimEnd('"').Replace("\"\"", "\""); } File.WriteAllText(Path.Combine(folder.Value, fileName.Value), fileContent); return(new PassedActionResult("File created as '" + Path.Combine(folder.Value, fileName.Value) + "'.")); } catch (Exception e) { return(new UnknownFailedActionResult(e.Message)); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String inputStr = testAction.GetParameterAsInputValue("InputString", false).Value; if (string.IsNullOrEmpty(inputStr)) { throw new ArgumentException(string.Format("Please provide input string to be converted to uppercase!")); } string resultString = inputStr.ToUpper(); return(new PassedActionResult(resultString)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String filePath = testAction.GetParameterAsInputValue("Path", false).Value; String fileNamePattern = testAction.GetParameterAsInputValue("Pattern", false).Value; String bufferName = testAction.GetParameterAsInputValue("Buffer", false).Value; if (string.IsNullOrEmpty(filePath)) { throw new ArgumentException(string.Format("File Path is required.")); } if (string.IsNullOrEmpty(fileNamePattern)) { throw new ArgumentException(string.Format("File Name Pattern is required.")); } if (string.IsNullOrEmpty(bufferName)) { throw new ArgumentException(string.Format("Buffer Name is required.")); } string[] matches = Directory.GetFiles(filePath, fileNamePattern); int arrLength = matches.Length; if (arrLength == 0) { return(new NotFoundFailedActionResult("No matching file name was found for the given pattern.")); } else if (arrLength > 1) { return(new NotFoundFailedActionResult("More than 1 file found for the given pattern.")); } else { Buffers.Instance.SetBuffer(bufferName, matches[0], false); return(new PassedActionResult("File name saved successfully.")); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { IInputValue name = testAction.GetParameterAsInputValue(Name, false); string browserProcessName = string.Empty; string result = string.Empty; try { // Setting Browser process Name as per browserName switch (name.Value) { case "Internet Explorer": browserProcessName = "iexplore"; break; case "Google Chrome": browserProcessName = "chrome"; break; case "Mozilla Firefox": browserProcessName = "firefox"; break; default: return(new UnknownFailedActionResult("Could not kill program", string.Format("Failed while trying to kill {0}", name.Value), "")); } Process[] procs = Process.GetProcessesByName(browserProcessName); if (procs.Length > 0) { foreach (Process proc in procs) { proc.Kill(); result = name.Value + " Browser closed Successfully"; } } else { result = name.Value + ERROR_BROWSER_NOTAVAILABLE; } } catch (Exception) { return(new UnknownFailedActionResult("Could not kill program", string.Format( "Failed while trying to kill {0}", name.Value), "")); } return(new PassedActionResult(result)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String bankIdent = testAction.GetParameterAsInputValue("bankIdent", false).Value; if (string.IsNullOrEmpty(bankIdent)) { throw new ArgumentException(string.Format("Es muss eine Bank identifikation angegeben sein.")); } String accountNumber = testAction.GetParameterAsInputValue("accountNumber", false).Value; if (string.IsNullOrEmpty(accountNumber)) { throw new ArgumentException(string.Format("Es muss eine Kontonummer angegeben sein.")); } String buffer = testAction.GetParameterAsInputValue("buffer", false).Value; if (string.IsNullOrEmpty(buffer)) { throw new ArgumentException(string.Format("Es muss ein Puffer angegeben werden in welche die IBAN gespeichert werden soll.")); } // onyl support DE so far ECountry countryCode = ECountry.DE; // DE46 | 5054 0028 | 0420 0861 00 _manager = ContainerBootstrapper.Resolve <IIbanManager>(countryCode.ToString()); iban = _manager.GenerateIban(countryCode, bankIdent, accountNumber); Buffers.Instance.SetBuffer(buffer, iban.IBAN.IBAN, false); testAction.SetResult(SpecialExecutionTaskResultState.Ok, "IBAN generated and saved to buffer."); throw new NotImplementedException(); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String endPoint = testAction.GetParameterAsInputValue("EndPoint", false).Value; String repoDescription = testAction.GetParameterAsInputValue("Description", false).Value; String repositoryName = testAction.GetParameterAsInputValue("Repository", false).Value; const String repoType = "InMemory"; if (string.IsNullOrEmpty(endPoint)) { throw new ArgumentException("End Point is a mandatory parameter."); } else { if (!endPoint.EndsWith("/")) { endPoint += "/"; } } if (string.IsNullOrEmpty(repositoryName)) { throw new ArgumentException("Repository Name is a mandatory parameter."); } var client = new RestClient(new Uri(endPoint + "configuration/repositories")); var request = new RestRequest(Method.POST); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); request.AddBody(new { description = repoDescription, location = repositoryName, name = repositoryName, type = repoType }); IRestResponse response = client.Execute(request); HttpStatusCode statusMessage = response.StatusCode; int statusCode = (int)statusMessage; return(new PassedActionResult("Got response: " + statusCode + " " + statusMessage)); }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraTargetHost = testAction.GetParameterAsInputValue("Host", false).Value; if (string.IsNullOrEmpty(paraTargetHost)) { throw new ArgumentException(string.Format("Es muss ein Ziel (Host) angegeben sein.")); } Uri resetRequest = new Uri("http://" + paraTargetHost + "/resetSession"); GetResponse(resetRequest); return(new PassedActionResult("Session reset on: " + paraTargetHost)); }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { //The 2nd parameter of GetParameterAsInputValue Method defines if the argument is optional or not //and if we don't provide the second parameter by default it is false(Means argument is mandetory) IInputValue browserName = testAction.GetParameterAsInputValue("BrowserName", false); bool result = EraseTemporaryFiles(browserName.Value); if (result) { testAction.SetResult(SpecialExecutionTaskResultState.Ok, string.Format("Cache for {0} is cleared.", browserName.Value)); } else { testAction.SetResult(SpecialExecutionTaskResultState.Failed, string.Format("Unable to clear cache for {0}.", browserName.Value)); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String paraExchangeFile = testAction.GetParameterAsInputValue("File", false).Value; if (string.IsNullOrEmpty(paraExchangeFile)) { throw new ArgumentException(string.Format("Es muss eine Exchangedatei (File) angegeben sein.")); } if (!Collections.Instance.CollectionExists(BufferCollectionPath)) { throw new InvalidOperationException("Es existiert keine Buffer-Collection in den Einstellungen!"); } XmlDocument doc = new XmlDocument(); XmlDeclaration xmlDeclaration = doc.CreateXmlDeclaration("1.0", "UTF-8", null); XmlElement root = doc.DocumentElement; doc.InsertBefore(xmlDeclaration, root); XmlElement bodyElement = doc.CreateElement(string.Empty, "exchange", string.Empty); doc.AppendChild(bodyElement); XmlElement varElement = doc.CreateElement(string.Empty, "variables", string.Empty); bodyElement.AppendChild(varElement); foreach ( KeyValuePair<string, string> buffer in Collections.Instance.GetCollectionEntries(BufferCollectionPath)) { if (!string.IsNullOrEmpty(buffer.Value) && !buffer.Key.StartsWith("#")) { XmlElement varKey = doc.CreateElement(string.Empty, buffer.Key, string.Empty); XmlText varValue; if (buffer.Key == "QAPass") { varValue = doc.CreateTextNode("****"); varKey.AppendChild(varValue); } else { varValue = doc.CreateTextNode(buffer.Value); varKey.AppendChild(varValue); } varElement.AppendChild(varKey); } } doc.Save(paraExchangeFile); return new PassedActionResult("Exchange generated to: " + paraExchangeFile); }
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 paraCommand = testAction.GetParameterAsInputValue("Command", false).Value; if (string.IsNullOrEmpty(paraCommand)) { throw new ArgumentException(string.Format("Es muss ein Command angegeben sein.")); } String paraTarget = testAction.GetParameterAsInputValue("Target", false).Value; if (string.IsNullOrEmpty(paraTarget)) { paraTarget = ""; } String paraValue = testAction.GetParameterAsInputValue("Value", false).Value; if (string.IsNullOrEmpty(paraValue)) { paraValue = ""; } // rest server address + port can be configured via buffer settings. // key should be: LOCAL_VEBTAL_PORT String outServer; bool adrServer = Buffers.Instance.TryGetBuffer("LOCAL_VEBTAL_SERVER", out outServer); if (string.IsNullOrEmpty(outServer)) { outServer = "http://127.0.0.1"; // fallback to default } // key should be: LOCAL_VEBTAL_PORT String outPort; bool port = Buffers.Instance.TryGetBuffer("LOCAL_VEBTAL_PORT", out outPort); if (string.IsNullOrEmpty(outPort)) { outPort = "84"; // fallback to default } var client = new RestClient(outServer + ":" + outPort); var request = new RestRequest("td/execute", Method.POST); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); request.AddBody(new { command = paraCommand, target = paraTarget, value = paraValue }); IRestResponse response = client.Execute(request); var content = response.Content; // Deserialisieren RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var JSONObj = deserial.Deserialize <Dictionary <string, string> >(response); string rowCode = JSONObj["code"]; string rowMsg = ""; if (JSONObj.ContainsKey("message")) { rowMsg = JSONObj["message"]; } // storedKey und storedValue beruecksichtigen if (JSONObj.ContainsKey("storedValue")) { string storedValue = JSONObj["storedValue"]; string storedKey = JSONObj["storedKey"]; Buffers.Instance.SetBuffer(storedKey, storedValue, false); } if (rowCode == "0") { return(new PassedActionResult("Got response: " + content)); } else { return(new NotFoundFailedActionResult("Command failed: " + content + " for request: [command=" + paraCommand + "; target=" + paraTarget + "; value=" + paraValue + "]")); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { int i, paraExpectedDays, paraExpectedMaxDays; double calcBusinessDays; DateTime paraStartDate, paraEndDate, chosenBatchDate; String[] noBatchDays = { "2019-01-01", "2019-04-19", "2019-04-22", "2019-05-01", "2019-05-30", "2019-06-10", "2019-10-03", "2019-12-24", "2019-12-25", "2019-12-26", "2019-12-31" }; String sepaCreationDate = testAction.GetParameterAsInputValue("StartDate", false).Value; String sepaRequestCollectionDate = testAction.GetParameterAsInputValue("EndDate", false).Value; String expectedDays = testAction.GetParameterAsInputValue("ExpectedDays", false).Value; String expectedMaxDays = testAction.GetParameterAsInputValue("ExpectedMaxDays", false).Value; if (string.IsNullOrEmpty(sepaCreationDate)) { throw new ArgumentException(string.Format("Start Date is required.")); } if (string.IsNullOrEmpty(sepaRequestCollectionDate)) { throw new ArgumentException(string.Format("End Date is required.")); } if (string.IsNullOrEmpty(expectedDays) && (string.IsNullOrEmpty(expectedMaxDays))) { throw new ArgumentException(string.Format("Either Expected Days or Expected Max. days is required.")); } paraStartDate = DateTime.ParseExact(sepaCreationDate.Substring(0, 10), "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); paraEndDate = DateTime.ParseExact(sepaRequestCollectionDate, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); if (string.IsNullOrEmpty(expectedDays)) { paraExpectedDays = -1; } else { paraExpectedDays = Int32.Parse(expectedDays); } if (string.IsNullOrEmpty(expectedMaxDays)) { paraExpectedMaxDays = -1; } else { paraExpectedMaxDays = Int32.Parse(expectedMaxDays); } if (paraEndDate <= paraStartDate) { throw new ArgumentException(string.Format("The Start Date should be before End Date.")); } calcBusinessDays = 1 + ((paraEndDate - paraStartDate).TotalDays * 5 - (paraStartDate.DayOfWeek - paraEndDate.DayOfWeek) * 2) / 7; if (paraEndDate.DayOfWeek == DayOfWeek.Saturday) { calcBusinessDays--; } if (paraStartDate.DayOfWeek == DayOfWeek.Sunday) { calcBusinessDays--; } for (i = 0; i < 10; i++) { chosenBatchDate = DateTime.ParseExact(noBatchDays[i], "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); if (chosenBatchDate >= paraStartDate && chosenBatchDate <= paraEndDate) { calcBusinessDays--; } } if (paraExpectedDays > 0) { if (paraExpectedDays == calcBusinessDays) { return(new PassedActionResult("Expected working days matches with the calculated value.")); } else { return(new NotFoundFailedActionResult("Expected Days (" + expectedDays + ") did not match with the actual no. of working days: " + calcBusinessDays)); } } if (paraExpectedMaxDays > 0) { if (paraExpectedMaxDays >= calcBusinessDays) { return(new PassedActionResult("Expected maximum working days matches with the calculated value.")); } else { return(new NotFoundFailedActionResult("Expected maximum Days (" + expectedMaxDays + ") is smaller than the actual no. of working days: " + calcBusinessDays)); } } return(new NotFoundFailedActionResult("No expectation set. Please review teststep!")); }
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))); } }
public override ActionResult Execute(ISpecialExecutionTaskTestAction testAction) { String file = testAction.GetParameterAsInputValue("File", false).Value; if (string.IsNullOrEmpty(file)) { throw new ArgumentException(string.Format("Es muss eine Datei angegeben sein.")); } String paraTimeOut = testAction.GetParameterAsInputValue("TimeOut", false).Value; if (string.IsNullOrEmpty(paraTimeOut)) { throw new ArgumentException(string.Format("TimeOut muss gesetzt sein.")); } int timeOut; bool isNumeric = int.TryParse(paraTimeOut, out timeOut); if (!isNumeric) { throw new ArgumentException(string.Format("TimeOut muss numerisch sein.")); } String paraInterval = testAction.GetParameterAsInputValue("Interval", false).Value; if (string.IsNullOrEmpty(paraInterval)) { throw new ArgumentException(string.Format("Es muss ein Interval gesetzt sein.")); } int interval; isNumeric = int.TryParse(paraInterval, out interval); if (!isNumeric) { throw new ArgumentException(string.Format("Das Inervall muss numerisch sein.")); } bool isFinished = false; bool isFound = false; long foundAfter = 666; var stopwatch = new Stopwatch(); stopwatch.Start(); while (!isFinished) { if (File.Exists(file)) { foundAfter = stopwatch.ElapsedMilliseconds; stopwatch.Stop(); isFound = true; isFinished = true; } if (stopwatch.Elapsed > TimeSpan.FromMilliseconds(timeOut)) { isFinished = true; } if (!isFinished) { Thread.Sleep(interval); } } // Abschlusswartezeit? Thread.Sleep(2000); if (isFound) { return(new PassedActionResult("File " + file + " found after: " + foundAfter + " ms.")); } else { return(new NotFoundFailedActionResult("File " + file + " not found.")); } }
public override void ExecuteTask(ISpecialExecutionTaskTestAction testAction) { String paraCommand = testAction.GetParameterAsInputValue("Command", false).Value; if (string.IsNullOrEmpty(paraCommand)) { throw new ArgumentException(string.Format("Es muss ein Command angegeben sein.")); } String paraTarget = testAction.GetParameterAsInputValue("Target", false).Value; // Wenn Target null, dann leer uebergeben. if (string.IsNullOrEmpty(paraTarget)) { paraTarget = ""; } String paraValue = testAction.GetParameterAsInputValue("Value", false).Value; // Wenn Value null, dann leer uebergeben. if (string.IsNullOrEmpty(paraValue)) { paraValue = ""; } // Rest Service konfigurierbar machen? var client = new RestClient("http://127.0.0.1:84"); var request = new RestRequest("tn5250/execute", Method.POST); request.RequestFormat = DataFormat.Json; request.AddHeader("Content-Type", "application/json"); request.AddHeader("Accept", "application/json"); request.AddBody(new { command = paraCommand, target = paraTarget, value = paraValue }); IRestResponse response = client.Execute(request); var content = response.Content; // Deserialisieren RestSharp.Deserializers.JsonDeserializer deserial = new JsonDeserializer(); var JSONObj = deserial.Deserialize <Dictionary <string, string> >(response); string rowCode = JSONObj["code"]; string rowMsg = ""; if (JSONObj.ContainsKey("message")) { rowMsg = JSONObj["message"]; } // storedKey und storedValue beruecksichtigen if (JSONObj.ContainsKey("storedValue")) { string storedValue = JSONObj["storedValue"]; string storedKey = JSONObj["storedKey"]; Buffers.Instance.SetBuffer(storedKey, storedValue, false); } if (rowCode == "0") { // return new PassedActionResult("Got response: " + content); testAction.SetResult(SpecialExecutionTaskResultState.Ok, "The execution of the command was successfully processed."); } else { // Im Falle eines Fehlers und damit eines Abbruchs muessen wir die Telnet Session aufraeumen? // var requestClean = new RestRequest("selenese/close", Method.POST); // requestClean.RequestFormat = DataFormat.Json; // requestClean.AddHeader("Content-Type", "application/json"); // requestClean.AddHeader("Accept", "application/json"); // requestClean.AddBody(new { // command = "close", // target = "this", // value = "null" // }); // IRestResponse responseClean = client.Execute(requestClean); // return new VerifyFailedActionResult("expected", "real"); testAction.SetResult( SpecialExecutionTaskResultState.Failed, rowMsg); } }