Skip to content

Commit 94c2d91

Browse files
committed
restructure test classes
1 parent a47cae1 commit 94c2d91

File tree

8 files changed

+81
-80
lines changed

8 files changed

+81
-80
lines changed

tests/GraphQL.Integration.Tests/ExtensionsTest.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/GraphQL.Integration.Tests/NewtonsoftWebsocketTest.cs

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/GraphQL.Integration.Tests/QueryAndMutationTests.cs renamed to tests/GraphQL.Integration.Tests/QueryAndMutationTests/Base.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
using System.Net.Http;
2-
using System.Text.Json;
32
using GraphQL.Client.Abstractions;
3+
using GraphQL.Client.Abstractions.Websocket;
44
using GraphQL.Client.Http;
55
using GraphQL.Client.Tests.Common.Helpers;
66
using GraphQL.Client.Tests.Common.StarWars;
77
using GraphQL.Integration.Tests.Helpers;
88
using IntegrationTestServer;
9-
using Newtonsoft.Json.Linq;
109
using Xunit;
1110

12-
namespace GraphQL.Integration.Tests {
13-
public class QueryAndMutationTests {
11+
namespace GraphQL.Integration.Tests.QueryAndMutationTests {
12+
13+
public abstract class Base {
14+
15+
protected IGraphQLWebsocketJsonSerializer serializer;
16+
17+
private TestServerSetup SetupTest(bool requestsViaWebsocket = false) => WebHostHelpers.SetupTest<StartupStarWars>(requestsViaWebsocket, serializer);
18+
19+
protected Base(IGraphQLWebsocketJsonSerializer serializer) {
20+
this.serializer = serializer;
21+
}
1422

15-
private static TestServerSetup SetupTest(bool requestsViaWebsocket = false) => WebHostHelpers.SetupTest<StartupStarWars>(requestsViaWebsocket);
16-
1723
[Theory]
1824
[ClassData(typeof(StarWarsHumans))]
1925
public async void QueryTheory(int id, string name) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using GraphQL.Client.Serializer.Newtonsoft;
2+
3+
namespace GraphQL.Integration.Tests.QueryAndMutationTests {
4+
public class Newtonsoft: Base {
5+
public Newtonsoft() : base(new NewtonsoftJsonSerializer())
6+
{
7+
}
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using GraphQL.Client.Serializer.SystemTextJson;
2+
3+
namespace GraphQL.Integration.Tests.QueryAndMutationTests {
4+
public class SystemTextJson: Base {
5+
public SystemTextJson() : base(new SystemTextJsonSerializer())
6+
{
7+
}
8+
}
9+
}

tests/GraphQL.Integration.Tests/WebsocketTest.cs renamed to tests/GraphQL.Integration.Tests/WebsocketTests/Base.cs

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,34 @@
33
using System.Net.WebSockets;
44
using System.Threading;
55
using System.Threading.Tasks;
6+
using FluentAssertions;
67
using GraphQL.Client.Abstractions;
8+
using GraphQL.Client.Abstractions.Websocket;
79
using GraphQL.Client.Tests.Common.Chat;
810
using GraphQL.Client.Tests.Common.Helpers;
911
using GraphQL.Integration.Tests.Helpers;
1012
using IntegrationTestServer;
1113
using Microsoft.AspNetCore.Hosting;
1214
using Xunit;
1315
using Xunit.Abstractions;
14-
using FluentAssertions;
15-
using GraphQL.Client.Abstractions.Websocket;
1616

17-
namespace GraphQL.Integration.Tests {
18-
public class WebsocketTest {
19-
private readonly ITestOutputHelper output;
20-
private static IWebHost CreateServer(int port) => WebHostHelpers.CreateServer<StartupChat>(port);
17+
namespace GraphQL.Integration.Tests.WebsocketTests {
18+
public abstract class Base {
19+
protected readonly ITestOutputHelper output;
20+
protected readonly IGraphQLWebsocketJsonSerializer serializer;
21+
protected IWebHost CreateServer(int port) => WebHostHelpers.CreateServer<StartupChat>(port);
2122

22-
public WebsocketTest(ITestOutputHelper output) {
23+
public Base(ITestOutputHelper output, IGraphQLWebsocketJsonSerializer serializer) {
24+
this.output = output;
25+
this.serializer = serializer;
26+
}
27+
28+
public Base(ITestOutputHelper output) {
2329
this.output = output;
2430
}
2531

26-
[Theory]
27-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
28-
public async void AssertTestingHarness(IGraphQLWebsocketJsonSerializer serializer) {
32+
[Fact]
33+
public async void AssertTestingHarness() {
2934
var port = NetworkHelpers.GetFreeTcpPortNumber();
3035
using (CreateServer(port)) {
3136
var client = WebHostHelpers.GetGraphQLClient(port, serializer: serializer);
@@ -38,9 +43,8 @@ public async void AssertTestingHarness(IGraphQLWebsocketJsonSerializer serialize
3843
}
3944

4045

41-
[Theory]
42-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
43-
public async void CanSendRequestViaWebsocket(IGraphQLWebsocketJsonSerializer serializer) {
46+
[Fact]
47+
public async void CanSendRequestViaWebsocket() {
4448
var port = NetworkHelpers.GetFreeTcpPortNumber();
4549
using (CreateServer(port)) {
4650
var client = WebHostHelpers.GetGraphQLClient(port, true, serializer);
@@ -51,10 +55,8 @@ public async void CanSendRequestViaWebsocket(IGraphQLWebsocketJsonSerializer ser
5155
}
5256
}
5357

54-
55-
[Theory]
56-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
57-
public async void CanHandleRequestErrorViaWebsocket(IGraphQLWebsocketJsonSerializer serializer) {
58+
[Fact]
59+
public async void CanHandleRequestErrorViaWebsocket() {
5860
var port = NetworkHelpers.GetFreeTcpPortNumber();
5961
using (CreateServer(port)) {
6062
var client = WebHostHelpers.GetGraphQLClient(port, true, serializer);
@@ -74,9 +76,8 @@ public async void CanHandleRequestErrorViaWebsocket(IGraphQLWebsocketJsonSeriali
7476
private readonly GraphQLRequest SubscriptionRequest = new GraphQLRequest(SubscriptionQuery);
7577

7678

77-
[Theory]
78-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
79-
public async void CanCreateObservableSubscription(IGraphQLWebsocketJsonSerializer serializer) {
79+
[Fact]
80+
public async void CanCreateObservableSubscription() {
8081
var port = NetworkHelpers.GetFreeTcpPortNumber();
8182
using (CreateServer(port)) {
8283
var client = WebHostHelpers.GetGraphQLClient(port, serializer: serializer);
@@ -116,9 +117,8 @@ public class MessageAddedContent {
116117
}
117118

118119

119-
[Theory]
120-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
121-
public async void CanReconnectWithSameObservable(IGraphQLWebsocketJsonSerializer serializer) {
120+
[Fact]
121+
public async void CanReconnectWithSameObservable() {
122122
var port = NetworkHelpers.GetFreeTcpPortNumber();
123123
using (CreateServer(port)) {
124124
var client = WebHostHelpers.GetGraphQLClient(port, serializer: serializer);
@@ -185,9 +185,8 @@ public class UserJoinedContent {
185185
private readonly GraphQLRequest SubscriptionRequest2 = new GraphQLRequest(SubscriptionQuery2);
186186

187187

188-
[Theory]
189-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
190-
public async void CanConnectTwoSubscriptionsSimultaneously(IGraphQLWebsocketJsonSerializer serializer) {
188+
[Fact]
189+
public async void CanConnectTwoSubscriptionsSimultaneously() {
191190
var port = NetworkHelpers.GetFreeTcpPortNumber();
192191
var callbackTester = new CallbackTester<Exception>();
193192
var callbackTester2 = new CallbackTester<Exception>();
@@ -234,9 +233,8 @@ public async void CanConnectTwoSubscriptionsSimultaneously(IGraphQLWebsocketJson
234233
}
235234

236235

237-
[Theory]
238-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
239-
public async void CanHandleConnectionTimeout(IGraphQLWebsocketJsonSerializer serializer) {
236+
[Fact]
237+
public async void CanHandleConnectionTimeout() {
240238
var port = NetworkHelpers.GetFreeTcpPortNumber();
241239
var server = CreateServer(port);
242240
var callbackTester = new CallbackTester<Exception>();
@@ -277,9 +275,8 @@ public async void CanHandleConnectionTimeout(IGraphQLWebsocketJsonSerializer ser
277275
}
278276

279277

280-
[Theory]
281-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
282-
public async void CanHandleSubscriptionError(IGraphQLWebsocketJsonSerializer serializer) {
278+
[Fact]
279+
public async void CanHandleSubscriptionError() {
283280
var port = NetworkHelpers.GetFreeTcpPortNumber();
284281
using (CreateServer(port)) {
285282
var client = WebHostHelpers.GetGraphQLClient(port, serializer: serializer);
@@ -305,9 +302,8 @@ public async void CanHandleSubscriptionError(IGraphQLWebsocketJsonSerializer ser
305302
}
306303

307304

308-
[Theory]
309-
[ClassData(typeof(AvailableJsonSerializers<IGraphQLWebsocketJsonSerializer>))]
310-
public async void CanHandleQueryErrorInSubscription(IGraphQLWebsocketJsonSerializer serializer) {
305+
[Fact]
306+
public async void CanHandleQueryErrorInSubscription() {
311307
var port = NetworkHelpers.GetFreeTcpPortNumber();
312308
using (CreateServer(port)) {
313309

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using GraphQL.Client.Serializer.Newtonsoft;
2+
using Xunit.Abstractions;
3+
4+
namespace GraphQL.Integration.Tests.WebsocketTests {
5+
public class Newtonsoft: Base {
6+
public Newtonsoft(ITestOutputHelper output) : base(output, new NewtonsoftJsonSerializer())
7+
{
8+
}
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using GraphQL.Client.Serializer.SystemTextJson;
2+
using Xunit.Abstractions;
3+
4+
namespace GraphQL.Integration.Tests.WebsocketTests {
5+
public class SystemTextJson: Base {
6+
public SystemTextJson(ITestOutputHelper output) : base(output, new SystemTextJsonSerializer())
7+
{
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)