Exemple #1
0
        protected static TResultModel SendRequestWithRetry <TResultModel>(CustomRestClient client, IRestRequest request, bool lookForItems = false, int maxRetry = 3, bool validateResponse = true)
        {
            var response = client.SendRequest(request);

            var result = response.DeserializeJsonResponseContent <TResultModel>();

            var retry = 0;

            if (lookForItems)
            {
                while (((dynamic)result).Items.Count == 0 && retry < maxRetry)
                {
                    Thread.Sleep(3000);
                    response = client.SendRequest(request);
                    result   = response.DeserializeJsonResponseContent <TResultModel>();
                    retry++;
                }
            }
            else
            {
                while (result == null && retry < maxRetry)
                {
                    Thread.Sleep(3000);
                    response = client.SendRequest(request);
                    result   = response.DeserializeJsonResponseContent <TResultModel>();
                    retry++;
                }
            }

            if (validateResponse)
            {
                ValidateResponse(response, request.Method);
            }
            else if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
            {
                Console.WriteLine($"Log: Expected OK or NoContent but found {response.StatusCode}");
            }

            return(result);
        }
Exemple #2
0
        protected static IRestResponse SendRequest(CustomRestClient client, IRestRequest request, bool validateResponse = true)
        {
            var response = client.SendRequest(request);

            if (validateResponse)
            {
                ValidateResponse(response, request.Method);
            }
            else if (response.StatusCode != HttpStatusCode.OK && response.StatusCode != HttpStatusCode.NoContent)
            {
                Console.WriteLine($"Log: Expected OK or NoContent but found {response.StatusCode}");
            }

            return(response);
        }
Exemple #3
0
 public void WhenISendGETRequest(Method method, string endPoint)
 {
     _request  = Client.PrepareRequest(endPoint, method);
     _response = Client.SendRequest(_request);
 }