Example #1
0
        public static async Task <ClientQueryResult> PostAsync(
            this TestServer testServer,
            ClientQueryRequest request,
            string path = "/graphql")
        {
            HttpResponseMessage response =
                await SendPostRequestAsync(
                    testServer,
                    JsonConvert.SerializeObject(request),
                    path);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(new ClientQueryResult {
                    StatusCode = HttpStatusCode.NotFound
                });
            }

            var json = await response.Content.ReadAsStringAsync();

            ClientQueryResult result = JsonConvert.DeserializeObject <ClientQueryResult>(json);

            result.StatusCode  = response.StatusCode;
            result.ContentType = response.Content.Headers.ContentType.ToString();
            return(result);
        }
Example #2
0
        public static async Task <IReadOnlyList <ClientQueryResult> > PostOperationAsync(
            this TestServer testServer,
            ClientQueryRequest request,
            string operationNames,
            string path = "/graphql",
            Func <string, string> createOperationParameter = null)
        {
            createOperationParameter ??= s => "batchOperations=[" + s + "]";
            HttpResponseMessage response =
                await SendPostRequestAsync(
                    testServer,
                    JsonConvert.SerializeObject(request),
                    path + "?" + createOperationParameter(operationNames));

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                return(new[] { new ClientQueryResult {
                                   StatusCode = HttpStatusCode.NotFound
                               } });
            }

            var json = await response.Content.ReadAsStringAsync();

            try
            {
                List <ClientQueryResult> result =
                    JsonConvert.DeserializeObject <List <ClientQueryResult> >(json);

                foreach (ClientQueryResult item in result)
                {
                    item.StatusCode  = response.StatusCode;
                    item.ContentType = response.Content.Headers.ContentType.ToString();
                }

                return(result);
            }
            catch
            {
                ClientQueryResult result = JsonConvert.DeserializeObject <ClientQueryResult>(json);
                result.StatusCode  = response.StatusCode;
                result.ContentType = response.Content.Headers.ContentType.ToString();
                return(new[] { result });
            }
        }