|
| 1 | +using GraphQL.Common.Request; |
| 2 | +using GraphQL.Common.Tests.Model; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +namespace GraphQL.Client.Tests { |
| 6 | + |
| 7 | + public class IGraphQLClientTest : BaseGraphQLClientTest { |
| 8 | + |
| 9 | + [Fact] |
| 10 | + public async void QueryGetAsyncFact() { |
| 11 | + var graphQLRequest = new GraphQLRequest { |
| 12 | + Query = @" |
| 13 | + { |
| 14 | + person(personID: ""1"") { |
| 15 | + name |
| 16 | + } |
| 17 | + }" |
| 18 | + }; |
| 19 | + var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); |
| 20 | + |
| 21 | + Assert.Equal("Luke Skywalker", response.Data.person.name.Value); |
| 22 | + Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public async void OperationNameGetAsyncFact() { |
| 27 | + var graphQLRequest = new GraphQLRequest { |
| 28 | + Query = @" |
| 29 | + query Person{ |
| 30 | + person(personID: ""1"") { |
| 31 | + name |
| 32 | + } |
| 33 | + } |
| 34 | +
|
| 35 | + query Planet { |
| 36 | + planet(planetID: ""1"") { |
| 37 | + name |
| 38 | + } |
| 39 | + }", |
| 40 | + OperationName = "Person" |
| 41 | + }; |
| 42 | + var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); |
| 43 | + |
| 44 | + Assert.Equal("Luke Skywalker", response.Data.person.name.Value); |
| 45 | + Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name); |
| 46 | + } |
| 47 | + |
| 48 | + [Fact] |
| 49 | + public async void VariablesGetAsyncFact() { |
| 50 | + var graphQLRequest = new GraphQLRequest { |
| 51 | + Query = @" |
| 52 | + query Person($personId: ID!){ |
| 53 | + person(personID: $personId) { |
| 54 | + name |
| 55 | + } |
| 56 | + }", |
| 57 | + Variables = new { |
| 58 | + personId = "1" |
| 59 | + } |
| 60 | + }; |
| 61 | + var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); |
| 62 | + |
| 63 | + Assert.Equal("Luke Skywalker", response.Data.person.name.Value); |
| 64 | + Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + public async void OperationNameVariableGetAsyncFact() { |
| 69 | + var graphQLRequest = new GraphQLRequest { |
| 70 | + Query = @" |
| 71 | + query Person($personId: ID!){ |
| 72 | + person(personID: $personId) { |
| 73 | + name |
| 74 | + } |
| 75 | + } |
| 76 | +
|
| 77 | + query Planet { |
| 78 | + planet(planetID: ""1"") { |
| 79 | + name |
| 80 | + } |
| 81 | + }", |
| 82 | + OperationName = "Person", |
| 83 | + Variables = new { |
| 84 | + personId = "1" |
| 85 | + } |
| 86 | + }; |
| 87 | + var response = await this.GraphQLClientSwapi.SendQueryAsync(graphQLRequest).ConfigureAwait(false); |
| 88 | + |
| 89 | + Assert.Equal("Luke Skywalker", response.Data.person.name.Value); |
| 90 | + Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name); |
| 91 | + } |
| 92 | + |
| 93 | + } |
| 94 | + |
| 95 | +} |
0 commit comments