public async Task SingleRequest_Execute_Specific_Operation(
            string operationName)
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetAsync(new ClientQueryRequest
            {
                Query         = @"
                    query a {
                        a: hero {
                            name
                        }
                    }

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

            // assert
            result.MatchSnapshot(new SnapshotNameExtension(operationName));
        }
        public async Task SingleRequest_CreateReviewForEpisode_Omit_NonNull_Variable()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetAsync(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!" },
                        }
                    }
                }
            });

            // assert
            result.MatchSnapshot();
        }
        public async Task SingleRequest_CreateReviewForEpisode_Variables_Unused()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetAsync(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!" }
                }
            });

            // assert
            result.MatchSnapshot();
        }
        public async Task Upload_File_In_InputObject()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            var query = @"
                query ($input: InputWithFileInput!) {
                    objectUpload(input: $input)
                }";

            var request = JsonConvert.SerializeObject(
                new ClientQueryRequest
            {
                Query     = query,
                Variables = new Dictionary <string, object>
                {
                    { "input", new Dictionary <string, object> {
                          { "file", null }
                      } }
                }
            });

            // act
            var form = new MultipartFormDataContent
            {
                { new StringContent(request), "operations" },
                { new StringContent("{ \"1\": [\"variables.input.file\"] }"), "map" },
                { new StringContent("abc"), "1", "foo.bar" },
            };

            ClientQueryResult result = await server.PostMultipartAsync(form, path : "/upload");

            // assert
            result.MatchSnapshot();
        }
예제 #5
0
        public async Task SingleRequest_Decimal_Min_Variable()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.PostAsync(new ClientQueryRequest
            {
                Query     = @"
                        query ($d: Decimal) {
                             decimal_arg(d: $d)
                        }",
                Variables = new Dictionary <string, object> {
                    { "d", decimal.MinValue }
                }
            },
                                       "/arguments");

            // assert
            new
            {
                decimal.MinValue,
                result
            }.MatchSnapshot();
        }
        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.Snapshot();
        }
예제 #7
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_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.Snapshot();
        }
        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);

            // 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 Get_ActivePersistedQuery_AddQuery_Unformatted()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            var query = "{__typename}";

            var hashProvider = new MD5DocumentHashProvider();
            var hash         = hashProvider.ComputeHash(Encoding.UTF8.GetBytes(query));

            // act
            ClientQueryResult resultA =
                await server.GetStoreActivePersistedQueryAsync(
                    query,
                    "md5Hash",
                    hash);

            ClientQueryResult resultB =
                await server.GetActivePersistedQueryAsync("md5Hash", hash);

            // assert
            new[] {
                resultA,
                resultB
            }.MatchSnapshot();
        }
        public async Task Get_ActivePersistedQuery_AddQuery()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            DocumentNode document = Utf8GraphQLParser.Parse("{ __typename }");

            var hashProvider = new MD5DocumentHashProvider();
            var hash         = hashProvider.ComputeHash(
                Encoding.UTF8.GetBytes(document.ToString(false)));

            // act
            ClientQueryResult resultA =
                await server.GetStoreActivePersistedQueryAsync(
                    document.ToString(false),
                    "md5Hash",
                    hash);

            ClientQueryResult resultB =
                await server.GetActivePersistedQueryAsync("md5Hash", hash);

            // assert
            new[] {
                resultA,
                resultB
            }.MatchSnapshot();
        }
        public async Task Get_Middleware_Is_Disabled()
        {
            // arrange
            TestServer server = CreateStarWarsServer(
                configureConventions: e => e.WithOptions(
                    new GraphQLServerOptions
            {
                EnableGetRequests = false
            }));

            // act
            ClientQueryResult result =
                await server.GetAsync(new ClientQueryRequest
            {
                Query = @"
                    {
                        hero {
                            name
                        }
                    }"
            });

            // assert
            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_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 SingleRequest_Double_Max_Variable()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetAsync(new ClientQueryRequest
            {
                Query     = @"
                        query ($d: Float) {
                             double_arg(d: $d)
                        }",
                Variables = new Dictionary <string, object> {
                    { "d", double.MaxValue }
                }
            },
                                      "/arguments");

            // assert
            new
            {
                double.MaxValue,
                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_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_")));
            }
        }
        public async Task HttpPost_Query_Syntax_Exception()
        {
            // 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));
        }
        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_OnSubPath()
        {
            // arrange
            TestServer server  = CreateStarWarsServer("/foo");
            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 Ensure_Middleware_Mapping()
        {
            // arrange
            TestServer server = CreateStarWarsServer("/foo");

            // act
            ClientQueryResult result = await server.PostAsync(string.Empty);

            // assert
            result.MatchSnapshot();
        }
        public async Task EmptyRequest()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result = await server.PostAsync(string.Empty);

            // assert
            result.MatchSnapshot();
        }
        public async Task BatchRequest_Empty(string request, int id)
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result = await server.PostAsync(request);

            // assert
            result.MatchSnapshot(new SnapshotNameExtension(id.ToString()));
        }
        public async Task SingleRequest_Incomplete()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result = await server.PostAsync("{ \"query\":    ");

            // assert
            result.MatchSnapshot();
        }
        public async Task Simple_IsAlive_Test()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result = await server.PostAsync(
                new ClientQueryRequest { Query = "{ __typename }" });

            // assert
            result.MatchSnapshot();
        }
예제 #27
0
        public async Task Get_ActivePersistedQuery_NotFound()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetActivePersistedQueryAsync("md5Hash", "abc");

            // assert
            result.MatchSnapshot();
        }
예제 #28
0
        public async Task Get_ActivePersistedQuery()
        {
            // arrange
            TestServer server = CreateStarWarsServer();

            // act
            ClientQueryResult result =
                await server.GetActivePersistedQueryAsync("md5Hash", "60ddx/GGk4FDObSa6eK0sg==");

            // assert
            result.MatchSnapshot();
        }
        public async Task MapGraphQLHttp_Simple_IsAlive_Test()
        {
            // arrange
            TestServer server = CreateServer(endpoint => endpoint.MapGraphQLHttp());

            // act
            ClientQueryResult result = await server.GetAsync(
                new ClientQueryRequest { Query = "{ __typename }" });

            // assert
            result.MatchSnapshot();
        }
예제 #30
0
        public async Task Simple_IsAlive_Test_On_Non_GraphQL_Path()
        {
            // arrange
            TestServer server = CreateStarWarsServer("/foo");

            // act
            ClientQueryResult result = await server.GetAsync(
                new ClientQueryRequest { Query = "{ __typename }" },
                "/foo");

            // assert
            result.MatchSnapshot();
        }