Skip to content

Commit 4e53c02

Browse files
author
Raul Hidalgo Caballero
committed
Dispose
1 parent c01e71d commit 4e53c02

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

src/GraphQL.Client/GraphQLClient.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace GraphQL.Client {
1010

11-
public partial class GraphQLClient {
11+
public partial class GraphQLClient:IDisposable {
1212

1313
public Uri EndPoint {
1414
get => this.Options.EndPoint;
@@ -82,6 +82,9 @@ private async Task<GraphQLResponse> ReadHttpResponseMessageAsync(HttpResponseMes
8282
return JsonConvert.DeserializeObject<GraphQLResponse>(resultString, this.Options.JsonSerializerSettings);
8383
}
8484

85+
public void Dispose() =>
86+
this.httpClient.Dispose();
87+
8588
}
8689

8790
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
3+
namespace GraphQL.Client.Tests {
4+
5+
public abstract class BaseGraphQLClientTest : IDisposable{
6+
7+
public GraphQLClient GraphQLClient { get; set; } = new GraphQLClient("https://swapi.apis.guru/");
8+
9+
public void Dispose() =>
10+
this.GraphQLClient.Dispose();
11+
12+
}
13+
14+
}

tests/GraphQL.Client.Tests/GraphQLClientTest.cs

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using GraphQL.Common.Request;
2+
using Xunit;
3+
4+
namespace GraphQL.Client.Tests {
5+
6+
public class GraphQLClientTests : BaseGraphQLClientTest {
7+
8+
[Fact]
9+
public async void GetAsyncFact() {
10+
var graphQLRequest = new GraphQLRequest { Query = @"
11+
{
12+
person(personID: ""1"") {
13+
name
14+
}
15+
}"
16+
};
17+
var response=await this.GraphQLClient.GetAsync(graphQLRequest).ConfigureAwait(false);
18+
19+
Assert.Equal("Luke Skywalker", response.Data.person.name.Value);
20+
}
21+
22+
}
23+
24+
}

0 commit comments

Comments
 (0)