public void ThenItShouldReturnGraphRequestForJsonMimeType(GraphRequest request) { var value = JsonConvert.SerializeObject(request); var actual = GraphRequest.Parse(value, JsonMimeType); Assert.IsNotNull(actual); }
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]}"); } }
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); }
public void ThenItShouldThrowExceptionIfMimeTypeNotSupported() { Assert.Throws <ArgumentOutOfRangeException>(() => GraphRequest.Parse("some-value", "text/plain")); }
public void ThenItShouldAssignValueToGraphRequestsQuery(string value) { var actual = GraphRequest.Parse(value, GraphQLMimeType); Assert.AreEqual(value, actual.Query); }
public void ThenItShouldReturnGraphRequestForJGraphQLMimeType(string value) { var actual = GraphRequest.Parse(value, GraphQLMimeType); Assert.IsNotNull(actual); }