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) { var node = TEST.CreateNode("Request - " + method + " - " + requestService); 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(); } node.Log(Status.Info, "<pre>" + "<b>URL: </b>" + url + "</pre>"); node.Log(Status.Info, "<pre>" + "<b>REQUEST: </b>" + requestService + "</pre>"); node.Log(Status.Info, "<pre>" + "<b>METHOD: </b>" + method + "</pre>"); if (allParameters != null) { node.Log(Status.Info, "<pre>" + "<b>PARAMETERS: </b>" + allParameters + "</pre>"); } if (jsonBody != null) { node.Log(Status.Info, "<pre>" + "<b>JSON BODY: </b>" + "\n" + jsonBody + "</pre>"); } if (allHeaders != null) { node.Log(Status.Info, "<pre>" + "<b>HEADERS: </b>" + allHeaders + "</pre>"); } if (allCookies != null) { node.Log(Status.Info, "<pre>" + "<b>COOKIES: </b>" + allCookies + "</pre>"); } if (httpBasicAuthenticator || ntlmAuthenticator) { node.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; node.Log(Status.Info, "<pre>" + "<b>STATUS CODE: </b>" + numericStatusCode + " - " + response.StatusCode.ToString() + "</pre>"); node.Log(Status.Info, "<pre>" + "<b>RESPONSE HEADERS: </b>" + allResponseHeaders + "</pre>"); node.Log(Status.Info, "<pre>" + "<b>PAYLOAD: </b>" + "\n" + GeneralHelpers.FormatJson(response.Content) + "</pre>"); }
public static async Task <IRestResponse> ExecuteRequest(string url, string requestService, Method method, IDictionary <string, string> headers, IDictionary <string, string> cookies, IDictionary <string, string> parameters, bool parameterTypeIsUrlSegment, object 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) { JsonSerializer jsonSerializer = new JsonSerializer(); string jsonsSerializer = jsonSerializer.Serialize(jsonBody); if (GeneralHelpers.IsAJsonArray(jsonsSerializer)) { request.AddJsonBody(new JArray(jsonSerializer)); } else { request.AddJsonBody(JsonConvert.DeserializeObject <JObject>(jsonsSerializer)); } } RestClient client = new RestClient(url); //client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; //utilizar url interna do gateway //client.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate); //limpar cache if (httpBasicAuthenticator) { //client.PreAuthenticate = true; //caso seja necessária pré atenticação 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(await client.ExecuteAsync(request)); }
public static void AddTestInfo(int methodLevel, string text) { TEST.Log(Status.Pass, GeneralHelpers.GetMethodNameByLevel(methodLevel) + " || " + text); }