Пример #1
0
 public static void CheckBooleanResponseForFalse(BooleanResponse resp)
 {
     Assert.IsNull(resp.ErrorMessage, "Error message not null: " + resp.ErrorMessage);
     Assert.IsFalse(resp.Response, "Boolean Result not false as expected: " + resp.Response);
 }
Пример #2
0
 public static void CheckBooleanResponse(BooleanResponse resp)
 {
     Assert.IsTrue(resp.IsSuccessfull,
         "Boolean Result failed with response: " + resp.Response + " and Error Message: " + resp.ErrorMessage);
 }
Пример #3
0
        private async Task<BooleanResponse> PostForBoolean(Uri url, string content)
        {
            BooleanResponse resp = null;
            try
            {
                using (var client = new HttpClient(
                    new HttpClientHandler
                    {
                        AutomaticDecompression = DecompressionMethods.GZip
                                                 | DecompressionMethods.Deflate
                    }))
                {
                    client.DefaultRequestHeaders.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate");

                    var credentials = new FormUrlEncodedContent(new[]
                    {
                        new KeyValuePair<string, string>("json", content)
                    });

                    var res = await client.PostAsync(url, credentials);
                    var respo = await res.Content.ReadAsStringAsync();
                    if (respo == "true")
                        resp = new BooleanResponse() { Response = true };
                    else
                    {
                        if (respo == "false")
                            resp = new BooleanResponse() { Response = false };
                        else
                        {
                            resp = new BooleanResponse() { ErrorMessage = respo };
                            LogHelper.Instance.Log(LogLevel.FatalError,
                                "Post failed for url " + url + " with json " + content + " Reponse recieved: " + respo, this);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.Instance.Log(LogLevel.Error, "Post failed for url " + url, this, ex);
                resp = new BooleanResponse() { ErrorMessage = "Post failed for url " + url };
            }
            return resp;
        }