public async Task HttpPost_EnumArgument()
        {
            // arrange
            TestServer server  = CreateTestServer();
            var        request = new ClientQueryRequest
            {
                Query     = "query a($a: TestEnum) { withEnum(test: $a) }",
                Variables = JObject.FromObject(new Dictionary <string, object>
                {
                    { "a", "A" }
                })
            };

            // act
            HttpResponseMessage message = await server
                                          .SendRequestAsync(request)
                                          .ConfigureAwait(false);

            // assert
            Assert.Equal(HttpStatusCode.OK, message.StatusCode);

            string json = await message.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
        public async Task HttpPost_Casing()
        {
            // arrange
            TestServer server  = CreateTestServer();
            var        request = new ClientQueryRequest {
                Query = "{ A:basic { B:a } }"
            };

            // act
            HttpResponseMessage message = await server
                                          .SendRequestAsync(request)
                                          .ConfigureAwait(false);

            // assert
            Assert.Equal(HttpStatusCode.OK, message.StatusCode);

            string json = await message.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
        public async Task HttpPost_GraphQLRequest()
        {
            // arrange
            TestServer server      = CreateTestServer();
            var        request     = @"
                {
                    customProperty
                }";
            var        contentType = "application/graphql";

            // act
            HttpResponseMessage message = await server
                                          .SendPostRequestAsync(request, contentType, null)
                                          .ConfigureAwait(false);

            // assert
            Assert.Equal(HttpStatusCode.OK, message.StatusCode);

            string json = await message.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
        public async Task HttpGet_QueryOnly()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = "{ hero { name } }";

            // act
            HttpResponseMessage message =
                await server.SendGetRequestAsync(request);

            // assert
            ClientQueryResult result = await DeserializeAsync(message);

            result.MatchSnapshot();
        }
        public async Task UseGraphQLHttpGet_BuilderServices()
        {
            // arrange
            TestServer server = ServerFactory.Create(
                services => services.AddStarWars(),
                (app, sp) => app.UseGraphQLHttpGet(sp));

            // act
            HttpResponseMessage message =
                await server.SendGetRequestAsync("{ hero { name } }");

            // assert
            ClientQueryResult result = await DeserializeAsync(message);

            result.MatchSnapshot();
        }
Esempio n. 6
0
        public async Task HttpPost_WithObjectVariables()
        {
            // arrange
            TestServer server  = CreateTestServer();
            var        request = new ClientQueryRequest
            {
                Query     = @"
                query test($a: FooInput!) {
                    withObjectArgument(b: $a) {
                        a
                        b
                        c
                    }
                }",
                Variables = JObject.FromObject(new Dictionary <string, object>
                {
                    { "a", new Dictionary <string, object> {
                          { "a", "44" },
                          { "b", "55" },
                          { "c", 66 }
                      } }
                })
            };

            // act
            HttpResponseMessage message = await server
                                          .SendRequestAsync(request)
                                          .ConfigureAwait(false);

            // assert
            Assert.Equal(HttpStatusCode.OK, message.StatusCode);

            string json = await message.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
Esempio n. 7
0
        public async Task HttpPost_Json_Unused_Variable()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    mutation CreateReviewForEpisode(
                        $ep: Episode!
                        $stars: Int!
                        $commentary: String!
                        $foo: Float) {
                        createReview(episode: $ep, review: {
                            stars: $stars
                            commentary: $commentary
                        } ) {
                            stars
                            commentary
                        }
                    }
                ",
                Variables = new Dictionary <string, object>
                {
                    { "ep", "EMPIRE" },
                    { "stars", 5 },
                    { "commentary", "This is a great movie!" }
                }
            };

            // act
            HttpResponseMessage message =
                await server.SendPostRequestAsync(request);

            // assert
            ClientQueryResult result = await DeserializeAsync(message);

            result.MatchSnapshot();
        }
Esempio n. 8
0
        public async Task HttpPost_Plain_GraphQL()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request =
                @"
                    {
                        hero {
                            name
                        }
                    }
                ";
            var contentType = "application/graphql";

            // act
            HttpResponseMessage message =
                await server.SendPostRequestAsync(request, contentType, null);

            // assert
            ClientQueryResult result = await DeserializeAsync(message);

            result.MatchSnapshot();
        }
        public async Task HttpGet_BasicTest()
        {
            // arrange
            TestServer server = CreateTestServer();
            var        query  = "{ basic { a } }";

            // act
            HttpResponseMessage message = await server
                                          .SendGetRequestAsync(query)
                                          .ConfigureAwait(false);

            // assert
            Assert.Equal(HttpStatusCode.OK, message.StatusCode);

            string json = await message.Content.ReadAsStringAsync()
                          .ConfigureAwait(false);

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

            Assert.Null(result.Errors);
            result.Snapshot();
        }
Esempio n. 10
0
        public async Task HttpPost_Json_Variable_NonNull_Violation()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    mutation CreateReviewForEpisode(
                        $ep: Episode!
                        $review: ReviewInput!) {
                        createReview(episode: $ep, review: $review) {
                            stars
                            commentary
                        }
                    }
                ",
                Variables = new Dictionary <string, object>
                {
                    { "review",
                      new Dictionary <string, object>
                      {
                          { "stars", 5 },
                          { "commentary", "This is a great movie!" },
                      } }
                }
            };

            // act
            HttpResponseMessage message =
                await server.SendPostRequestAsync(request);

            // assert
            ClientQueryResult result = await DeserializeAsync(message);

            result.MatchSnapshot();
        }