Skip to content

Commit 53489f6

Browse files
author
Raul Hidalgo Caballero
committed
IGraphQLClientTest
1 parent 251aebd commit 53489f6

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

tests/GraphQL.Client.Tests/BaseGraphQLClientTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ namespace GraphQL.Client.Tests {
66
public abstract class BaseGraphQLClientTest : IDisposable {
77

88
protected GraphQLClient GraphQLClient { get; } = new GraphQLClient("https://swapi.apis.guru/");
9+
protected IGraphQLClient GraphQLClientSwapi { get; } = new GraphQLHttpClient("https://swapi.apis.guru/");
910
protected GraphQLHttpClient GitHuntClient { get; } = new GraphQLHttpClient("http://api.githunt.com/graphql");
1011

1112
public void Dispose() {
1213
this.GraphQLClient.Dispose();
14+
this.GraphQLClientSwapi.Dispose();
1315
this.GitHuntClient.Dispose();
1416
}
1517

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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

Comments
 (0)