|
| 1 | +using System.Diagnostics.CodeAnalysis; |
| 2 | +using FluentAssertions; |
| 3 | +using GraphQL.Client.Abstractions; |
| 4 | +using GraphQL.Client.Http; |
| 5 | +using GraphQL.Client.Tests.Common.StarWars.TestData; |
| 6 | +using GraphQL.Integration.Tests.Helpers; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace GraphQL.Integration.Tests.APQ; |
| 10 | + |
| 11 | +[SuppressMessage("ReSharper", "UseConfigureAwaitFalse")] |
| 12 | +public class APQViaHttpRequests : IAsyncLifetime, IClassFixture<SystemTextJsonAutoNegotiateServerTestFixture> |
| 13 | +{ |
| 14 | + public SystemTextJsonAutoNegotiateServerTestFixture Fixture { get; } |
| 15 | + protected GraphQLHttpClient StarWarsClient; |
| 16 | + |
| 17 | + public APQViaHttpRequests(SystemTextJsonAutoNegotiateServerTestFixture fixture) |
| 18 | + { |
| 19 | + Fixture = fixture; |
| 20 | + } |
| 21 | + |
| 22 | + public async Task InitializeAsync() |
| 23 | + { |
| 24 | + await Fixture.CreateServer(); |
| 25 | + StarWarsClient = Fixture.GetStarWarsClient(options => options.EnableAutomaticPersistedQueries = _ => true); |
| 26 | + } |
| 27 | + |
| 28 | + public Task DisposeAsync() |
| 29 | + { |
| 30 | + StarWarsClient?.Dispose(); |
| 31 | + return Task.CompletedTask; |
| 32 | + } |
| 33 | + |
| 34 | + [Theory] |
| 35 | + [ClassData(typeof(StarWarsHumans))] |
| 36 | + public async void After_querying_all_starwars_humans_the_APQDisabledForSession_is_still_false_Async(int id, string name) |
| 37 | + { |
| 38 | + var query = new GraphQLQuery(""" |
| 39 | + query Human($id: String!){ |
| 40 | + human(id: $id) { |
| 41 | + name |
| 42 | + } |
| 43 | + } |
| 44 | + """); |
| 45 | + |
| 46 | + var graphQLRequest = new GraphQLRequest(query, new { id = id.ToString() }); |
| 47 | + |
| 48 | + var response = await StarWarsClient.SendQueryAsync(graphQLRequest, () => new { Human = new { Name = string.Empty } }); |
| 49 | + |
| 50 | + Assert.Null(response.Errors); |
| 51 | + Assert.Equal(name, response.Data.Human.Name); |
| 52 | + StarWarsClient.APQDisabledForSession.Should().BeFalse("if APQ has worked it won't get disabled"); |
| 53 | + } |
| 54 | +} |
0 commit comments