public async Task HttpPost_Ensure_Response_Casing_Alignes_With_Request()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    {
                        Hero: hero {
                            name
                        }
                    }
                "
            };

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

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Json_QueryAndStringVariable()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    query h($id: String!) {
                        human(id: $id) {
                            name
                        }
                    }
                ",
                Variables = new Dictionary <string, object>
                {
                    { "id", "1000" }
                }
            };

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

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Path(
            string path,
            string requestPath,
            HttpStatusCode httpStatus)
        {
            // arrange
            TestServer server  = CreateStarWarsServer(path);
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    query a {
                        hero {
                            name
                        }
                    }
                "
            };

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

            // assert
            Assert.Equal(httpStatus, message.StatusCode);

            if (message.StatusCode == HttpStatusCode.OK)
            {
                ClientQueryResult result = await DeserializeAsync(message);

                result.MatchSnapshot(new SnapshotNameExtension(
                                         path?.Replace("/", "_Slash_"),
                                         requestPath?.Replace("/", "_Slash_")));
            }
        }
Beispiel #4
0
        public async Task UseGraphQLHttpPost_BuilderOptions()
        {
            // arrange
            TestServer server = ServerFactory.Create(
                services => services.AddStarWars(),
                app => app.UseGraphQLHttpPost(
                    new HttpPostMiddlewareOptions
            {
                Path = "/foo"
            }));

            HttpClient client = server.CreateClient();

            var request = new ClientQueryRequest
            {
                Query =
                    @"
                    {
                        hero {
                            name
                        }
                    }
                "
            };

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

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Json_CachedQuery_NotFound()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    query a {
                        hero {
                            name
                        }
                    }
                ".Replace("\n", string.Empty).Replace("\r", string.Empty),
                NamedQuery = "abc"
            };

            HttpResponseMessage message =
                await server.SendPostRequestAsync(request);

            // act
            request = new ClientQueryRequest
            {
                NamedQuery = "abc"
            };

            message = await server.SendPostRequestAsync(request);

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Json_QueryAndEnumVariable()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    query h($episode: Episode) {
                        hero(episode: $episode) {
                            name
                        }
                    }
                ",
                Variables = new Dictionary <string, object>
                {
                    { "episode", "EMPIRE" }
                }
            };

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

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Json_QueryOnly()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    {
                        hero {
                            name
                        }
                    }
                "
            };

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

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

            result.MatchSnapshot();
        }
        public async Task HttpPost_Json_QueryAndOperationName(
            string operationName)
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    query a {
                        a: hero {
                            name
                        }
                    }

                    query b {
                        b: hero {
                            name
                        }
                    }
                ",
                OperationName = operationName
            };

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

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

            result.MatchSnapshot(new SnapshotNameExtension(operationName));
        }
Beispiel #9
0
        public async Task HttpPost_Check_Response_ContentType()
        {
            // arrange
            TestServer server  = CreateStarWarsServer();
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    {
                        hero {
                            name
                        }
                    }
                "
            };

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

            // assert
            Assert.Collection(
                message.Content.Headers.GetValues("Content-Type"),
                t => Assert.Equal("application/json", t));
        }
Beispiel #10
0
        public async Task HttpPost_WithScalarVariables()
        {
            // arrange
            TestServer server  = CreateTestServer();
            var        request = new ClientQueryRequest
            {
                Query     = @"
                query test($a: String!) {
                    withScalarArgument(a: $a) {
                        a
                        b
                        c
                    }
                }",
                Variables = JObject.FromObject(new Dictionary <string, object>
                {
                    { "a", "1234567890" }
                })
            };

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

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

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

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

            Assert.Null(result.Errors);
            result.Snapshot();
        }
Beispiel #11
0
        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);

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

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

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
Beispiel #12
0
        public async Task HttpPost_Path(
            string path,
            string requestPath,
            HttpStatusCode httpStatus)
        {
            // arrange
            TestServer server  = CreateTestServer(path);
            var        request = new ClientQueryRequest
            {
                Query = @"
                {
                    customProperty
                }"
            };

            // act
            HttpResponseMessage message =
                await server.SendRequestAsync(request, requestPath);

            // assert
            Assert.Equal(httpStatus, message.StatusCode);

            if (message.StatusCode == HttpStatusCode.OK)
            {
                string result = await message.Content.ReadAsStringAsync();

                result.MatchSnapshot(new SnapshotNameExtension(
                                         path?.Replace("/", "_Slash_"),
                                         requestPath?.Replace("/", "_Slash_")));
            }
        }
Beispiel #13
0
        public async Task HttpPost_CustomProperties()
        {
            // arrange
            TestServer server  = CreateTestServer();
            var        request = new ClientQueryRequest
            {
                Query = @"
                {
                    customProperty
                }"
            };

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

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

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

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

            Assert.Null(result.Errors);
            result.MatchSnapshot();
        }
        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();
        }
        public async Task HttpPost_Json_OnSubPath_PostOnInvalidPath()
        {
            // arrange
            TestServer server  = CreateStarWarsServer("/foo");
            var        request = new ClientQueryRequest
            {
                Query =
                    @"
                    {
                        hero {
                            name
                        }
                    }
                "
            };

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

            // assert
            Assert.Equal(HttpStatusCode.NotFound, message.StatusCode);
        }
Beispiel #16
0
        public async Task HttpPost_BasicTest()
        {
            // arrange
            TestServer server  = CreateTestServer("/foo");
            var        request = new ClientQueryRequest {
                Query = "{ basic { a } }"
            };

            // act
            HttpResponseMessage message =
                await server.SendRequestAsync(request, "foo");

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

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

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

            Assert.Null(result.Errors);
            result.Snapshot();
        }
        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();
        }