Skip to content

Commit 1f785cb

Browse files
Enhance GamesClientTests with CancellationToken support
Updated the GamesClientTests class to accept an optional ITestOutputHelper for improved logging. Asynchronous method calls to gamesClient now include a CancellationToken parameter, allowing for better cancellation handling. Methods such as GetGamesAsync, SetMoveAsync, GetGameAsync, and CancelGameAsync have been modified accordingly. Removed unused global using directive for Xunit.Abstractions.
1 parent 1b867f5 commit 1f785cb

2 files changed

Lines changed: 9 additions & 16 deletions

File tree

src/clients/Codebreaker.GameAPIs.Client.Tests/GamesClientTests.cs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,8 @@
44

55
namespace Codebreaker.GameAPIs.Client.Tests;
66

7-
public class GamesClientTests
7+
public class GamesClientTests(ITestOutputHelper? testOutputHelper = null)
88
{
9-
private readonly ITestOutputHelper? _testOutputHelper;
10-
11-
public GamesClientTests(ITestOutputHelper? testOutputHelper = null)
12-
{
13-
_testOutputHelper = testOutputHelper;
14-
}
15-
169
[Fact]
1710
public async Task StartGameAsync_Should_ReturnResults()
1811
{
@@ -22,7 +15,7 @@ public async Task StartGameAsync_Should_ReturnResults()
2215
GamesClient gamesClient = new(httpClient, NullLogger<GamesClient>.Instance);
2316

2417
// Act
25-
var (GameId, NumberCodes, MaxMoves, FieldValues) = await gamesClient.StartGameAsync(GameType.Game6x4, "test");
18+
var (GameId, NumberCodes, MaxMoves, FieldValues) = await gamesClient.StartGameAsync(GameType.Game6x4, "test", TestContext.Current.CancellationToken);
2619

2720
// Assert
2821
Assert.Equal(4, NumberCodes);
@@ -80,7 +73,7 @@ public async Task StartGameAsync_Should_StartGameAndTriggerGameCreatedEvent()
8073
GamesClient gamesClient = new(httpClient, NullLogger<GamesClient>.Instance);
8174

8275
// Act
83-
var (GameId, NumberCodes, MaxMoves, FieldValues) = await gamesClient.StartGameAsync(GameType.Game6x4, "test");
76+
var (GameId, NumberCodes, MaxMoves, FieldValues) = await gamesClient.StartGameAsync(GameType.Game6x4, "test", TestContext.Current.CancellationToken);
8477

8578
Assert.True(startActivityReceived);
8679
Assert.True(stopActivityReceived);
@@ -96,7 +89,7 @@ public async Task GetGamesAsync_Should_ReturnResults()
9689

9790
// Act
9891
GamesQuery query = new(GameType.Game6x4, "test", new DateOnly(2024, 2, 14), Ended: false);
99-
var games = await gamesClient.GetGamesAsync(query);
92+
var games = await gamesClient.GetGamesAsync(query, TestContext.Current.CancellationToken);
10093

10194
// Assert
10295
Assert.Equal(2, games.Count());
@@ -117,7 +110,8 @@ public async Task SetMoveAsync_Should_ReturnResults()
117110
"test",
118111
GameType.Game6x4,
119112
1,
120-
new[] { "Red", "Green", "Blue", "Yellow" });
113+
["Red", "Green", "Blue", "Yellow"],
114+
TestContext.Current.CancellationToken);
121115

122116
// Assert
123117
Assert.Equal(2, Results.Length);
@@ -143,7 +137,7 @@ public async Task GetGameAsync_Should_ReturnResults()
143137

144138
// Act
145139
var gameId = Guid.Parse("91f3c729-5e6e-459a-b656-2d77f3f45dd9");
146-
var game = await gamesClient.GetGameAsync(gameId);
140+
var game = await gamesClient.GetGameAsync(gameId, TestContext.Current.CancellationToken);
147141

148142
// Assert
149143
Assert.NotNull(game);
@@ -172,7 +166,7 @@ public async Task CancelGameAsync_Should_CallApi()
172166

173167
// Act
174168
var gameId = Guid.Parse("91f3c729-5e6e-459a-b656-2d77f3f45dd9");
175-
await gamesClient.CancelGameAsync(gameId, "test", GameType.Game6x4);
169+
await gamesClient.CancelGameAsync(gameId, "test", GameType.Game6x4, TestContext.Current.CancellationToken);
176170

177171
// Assert
178172
handlerMock.Protected().Verify(
@@ -235,7 +229,7 @@ public async Task CancelGameAsync_Should_TrackActivity()
235229

236230
// Act
237231
var gameId = Guid.Parse("91f3c729-5e6e-459a-b656-2d77f3f45dd9");
238-
await gamesClient.CancelGameAsync(gameId, "test", GameType.Game6x4);
232+
await gamesClient.CancelGameAsync(gameId, "test", GameType.Game6x4, TestContext.Current.CancellationToken);
239233

240234
// Assert
241235
Assert.True(startActivityReceived);

src/clients/Codebreaker.GameAPIs.Client.Tests/GlobalUsings.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,3 @@
88
global using System.Text.Json;
99

1010
global using Xunit;
11-
global using Xunit.Abstractions;

0 commit comments

Comments
 (0)