Skip to content

Commit 825881a

Browse files
author
Raul Hidalgo Caballero
committed
Working
1 parent bdf14db commit 825881a

File tree

2 files changed

+142
-4
lines changed

2 files changed

+142
-4
lines changed

tests/GraphQL.Client.Tests/GraphQLClientGetTests.cs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,83 @@ public class GraphQLClientGetTests : BaseGraphQLClientTest {
88

99
[Fact]
1010
public async void QueryGetAsyncFact() {
11-
var graphQLRequest = new GraphQLRequest { Query = @"
11+
var graphQLRequest = new GraphQLRequest {
12+
Query = @"
1213
{
1314
person(personID: ""1"") {
1415
name
1516
}
1617
}"
1718
};
18-
var response=await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false);
19+
var response = await this.GraphQLClient.GetAsync(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.GraphQLClient.GetAsync(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.GraphQLClient.GetAsync(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.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false);
1988

2089
Assert.Equal("Luke Skywalker", response.Data.person.name.Value);
2190
Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name);

tests/GraphQL.Client.Tests/GraphQLClientPostTests.cs

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,83 @@ public class GraphQLClientPostTests : BaseGraphQLClientTest {
88

99
[Fact]
1010
public async void QueryPostAsyncFact() {
11-
var graphQLRequest = new GraphQLRequest { Query = @"
11+
var graphQLRequest = new GraphQLRequest {
12+
Query = @"
1213
{
1314
person(personID: ""1"") {
1415
name
1516
}
1617
}"
1718
};
18-
var response=await this.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false);
19+
var response = await this.GraphQLClient.PostAsync(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 OperationNamePostAsyncFact() {
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.GraphQLClient.PostAsync(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 VariablesPostAsyncFact() {
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.GraphQLClient.PostAsync(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 OperationNameVariablePostAsyncFact() {
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.GraphQLClient.PostAsync(graphQLRequest).ConfigureAwait(false);
1988

2089
Assert.Equal("Luke Skywalker", response.Data.person.name.Value);
2190
Assert.Equal("Luke Skywalker", response.GetDataFieldAs<Person>("person").Name);

0 commit comments

Comments
 (0)