Beispiel #1
0
        public void ThenItShouldReturnGraphRequestForJsonMimeType(GraphRequest request)
        {
            var value = JsonConvert.SerializeObject(request);

            var actual = GraphRequest.Parse(value, JsonMimeType);

            Assert.IsNotNull(actual);
        }
Beispiel #2
0
        public void ThenItShouldDeserializeValueForJsonMimeType(GraphRequest request, Dictionary <string, string> variables)
        {
            request.Variables = JObject.Parse(JsonConvert.SerializeObject(variables));
            var value = JsonConvert.SerializeObject(request);

            var actual = GraphRequest.Parse(value, JsonMimeType);

            Assert.AreEqual(request.Query, actual.Query);
            Assert.AreEqual(request.OperationName, actual.OperationName);
            Assert.AreEqual(request.Variables.Count, actual.Variables.Count);
            foreach (var key in variables.Keys)
            {
                Assert.IsTrue(actual.Variables.ContainsKey(key),
                              $"Expected Variables to contain key {key}, but was not found");
                Assert.AreEqual(request.Variables[key], actual.Variables[key],
                                $"Expected Variable[{key}] to be {request.Variables[key]}, but was {actual.Variables[key]}");
            }
        }
Beispiel #3
0
        private async Task <GraphRequest> ExtractGraphRequestAsync(HttpRequest req)
        {
            if (req.Method.Equals("GET", StringComparison.InvariantCultureIgnoreCase))
            {
                return(GraphRequest.Parse(req.Query["query"], "application/graphql"));
            }
            else if (req.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase))
            {
                var contentType = req.ContentType.Contains(";")
                    ? req.ContentType.Substring(0, req.ContentType.IndexOf(";"))
                    : req.ContentType;
                using (var reader = new StreamReader(req.Body))
                {
                    var body = await reader.ReadToEndAsync();

                    return(GraphRequest.Parse(body, contentType));
                }
            }

            return(null);
        }
Beispiel #4
0
 public void ThenItShouldThrowExceptionIfMimeTypeNotSupported()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
                                                 GraphRequest.Parse("some-value", "text/plain"));
 }
Beispiel #5
0
        public void ThenItShouldAssignValueToGraphRequestsQuery(string value)
        {
            var actual = GraphRequest.Parse(value, GraphQLMimeType);

            Assert.AreEqual(value, actual.Query);
        }
Beispiel #6
0
        public void ThenItShouldReturnGraphRequestForJGraphQLMimeType(string value)
        {
            var actual = GraphRequest.Parse(value, GraphQLMimeType);

            Assert.IsNotNull(actual);
        }