private static MySqlConnection GetDBConnection() { string connectionString = "" + "Database=" + JsonBuilder.ReturnParameterAppSettings("DB_NAME").ToString() + ";" + "Data Source=" + JsonBuilder.ReturnParameterAppSettings("DB_URL").ToString() + ";" + "User Id=" + JsonBuilder.ReturnParameterAppSettings("DB_USER").ToString() + "; " + "Password="******"DB_PASSWORD").ToString() + ""; //string connectionString = "Data Source=" + JsonBuilder.ReturnParameterAppSettings("DB_URL").ToString() + // "," + JsonBuilder.ReturnParameterAppSettings("DB_PORT").ToString() + ";" + // "Initial Catalog=" + JsonBuilder.ReturnParameterAppSettings("DB_NAME").ToString() + ";" + // "User ID=" + JsonBuilder.ReturnParameterAppSettings("DB_USER").ToString() + "; " + // "Password="******"DB_PASSWORD").ToString() + ";"; MySqlConnection connection = new MySqlConnection(connectionString); return(connection); }
public static IRestResponse <dynamic> ExecuteSoapRequest(string url, IDictionary <string, string> headers, IDictionary <string, string> cookies, string bodyXml, bool httpBasicAuthenticator, bool ntlmAuthenticator) { RestRequest request = new RestRequest(url, Method.POST); request.RequestFormat = RestSharp.DataFormat.Xml; foreach (var header in headers) { request.AddParameter(header.Key, header.Value, ParameterType.HttpHeader); } foreach (var cookie in cookies) { request.AddParameter(cookie.Key, cookie.Value, ParameterType.Cookie); } if (bodyXml != null) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(bodyXml); request.AddParameter("text/xml", xmlDoc.OuterXml, ParameterType.RequestBody); } RestClient client = new RestClient(url); if (httpBasicAuthenticator) { client.Authenticator = new HttpBasicAuthenticator(JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_USER"), JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_PASSWORD")); } if (ntlmAuthenticator) { client.Authenticator = new NtlmAuthenticator(JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_USER"), JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_PASSWORD")); } return(client.Execute <dynamic>(request)); }
public static List <string> RetornaDadosQuery(string query) { DataSet ds = new DataSet(); List <string> lista = new List <string>(); using (MySqlCommand cmd = new MySqlCommand(query, GetDBConnection())) { cmd.CommandTimeout = Int32.Parse(JsonBuilder.ReturnParameterAppSettings("DB_CONNECTION_TIMEOUT").ToString()); cmd.Connection.Open(); DataTable table = new DataTable(); table.Load(cmd.ExecuteReader()); ds.Tables.Add(table); cmd.Connection.Close(); } if (ds.Tables[0].Columns.Count == 0) { return(null); } try { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { for (int j = 0; j < ds.Tables[0].Columns.Count; j++) { lista.Add(ds.Tables[0].Rows[i][j].ToString()); } } } catch (Exception) { return(null); } return(lista); }
public static IRestResponse <dynamic> ExecuteRequest(string url, string requestService, Method method, IDictionary <string, string> headers, IDictionary <string, string> cookies, IDictionary <string, string> parameters, bool parameterTypeIsUrlSegment, string jsonBody, bool httpBasicAuthenticator, bool ntlmAuthenticator) { RestRequest request = new RestRequest(requestService, method); foreach (var header in headers) { request.AddParameter(header.Key, header.Value, ParameterType.HttpHeader); } foreach (var cookie in cookies) { request.AddParameter(cookie.Key, cookie.Value, ParameterType.Cookie); } foreach (var parameter in parameters) { if (parameterTypeIsUrlSegment) { request.AddParameter(parameter.Key, parameter.Value, ParameterType.UrlSegment); } else { request.AddParameter(parameter.Key, parameter.Value); } } request.JsonSerializer = new JsonSerializer(); if (jsonBody != null) { if (GeneralHelpers.IsAJsonArray(jsonBody)) { request.AddJsonBody(new JArray(jsonBody)); } else { request.AddJsonBody(JsonConvert.DeserializeObject <JObject>(jsonBody)); } } RestClient client = new RestClient(url); if (httpBasicAuthenticator) { client.Authenticator = new HttpBasicAuthenticator(JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_USER"), JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_PASSWORD")); } if (ntlmAuthenticator) { client.Authenticator = new NtlmAuthenticator(JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_USER"), JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_PASSWORD")); } client.AddHandler("application/json", new JsonDeserializer()); return(client.Execute <dynamic>(request)); }
public static void AddTestInfo(string url, string requestService, string method, IDictionary <string, string> headers, IDictionary <string, string> cookies, IDictionary <string, string> parameters, string jsonBody, bool httpBasicAuthenticator, bool ntlmAuthenticator, IRestResponse <dynamic> response) { string allHeaders = null; string allCookies = null; string allParameters = null; string allResponseHeaders = null; foreach (var parameter in parameters) { allParameters = allParameters + "\n" + "<i>" + parameter.Key + "</i>" + " = " + parameter.Value; } foreach (var header in headers) { allHeaders = allHeaders + "\n" + "<i>" + header.Key + "</i>" + " = " + header.Value; } foreach (var cookie in cookies) { allCookies = allCookies + "\n" + "<i>" + cookie.Key + "</i>" + " = " + cookie.Value; } foreach (var responseHeader in response.Headers) { allResponseHeaders = allResponseHeaders + "\n" + responseHeader.ToString(); } TEST.Log(Status.Info, "<pre>" + "<b>URL: </b>" + url + "</pre>"); TEST.Log(Status.Info, "<pre>" + "<b>REQUEST: </b>" + requestService + "</pre>"); TEST.Log(Status.Info, "<pre>" + "<b>METHOD: </b>" + method + "</pre>"); if (allParameters != null) { TEST.Log(Status.Info, "<pre>" + "<b>PARAMETERS: </b>" + allParameters + "</pre>"); } if (jsonBody != null) { TEST.Log(Status.Info, "<pre>" + "<b>JSON BODY: </b>" + "\n" + jsonBody + "</pre>"); } if (allHeaders != null) { TEST.Log(Status.Info, "<pre>" + "<b>HEADERS: </b>" + allHeaders + "</pre>"); } if (allCookies != null) { TEST.Log(Status.Info, "<pre>" + "<b>COOKIES: </b>" + allCookies + "</pre>"); } if (httpBasicAuthenticator || ntlmAuthenticator) { TEST.Log(Status.Info, "<pre>" + "<b>AUTHENTICATOR: </b>" + "\n" + "<b>USER: </b>" + JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_USER") + "\n" + "<b>PASSWORD: </b>" + JsonBuilder.ReturnParameterAppSettings("AUTHENTICATOR_PASSWORD") + " </pre>"); } HttpStatusCode statusCode = response.StatusCode; int numericStatusCode = (int)statusCode; TEST.Log(Status.Info, "<pre>" + "<b>STATUS CODE: </b>" + numericStatusCode + " - " + response.StatusCode.ToString() + "</pre>"); TEST.Log(Status.Info, "<pre>" + "<b>RESPONSE HEADERS: </b>" + allResponseHeaders + "</pre>"); TEST.Log(Status.Info, "<pre>" + "<b>PAYLOAD: </b>" + "\n" + GeneralHelpers.FormatJson(response.Content) + "</pre>"); }
public static void AddTest() { string testName = TestContext.CurrentContext.Test.MethodName; string testCategory = TestContext.CurrentContext.Test.ClassName.Substring(Int32.Parse(JsonBuilder.ReturnParameterAppSettings("REPORT_SUBSTRING_LENGTH"))); TEST = EXTENT_REPORT.CreateTest(testName).AssignCategory(testCategory); }