Skip to content

Commit 759ef62

Browse files
committed
Defined data for a simulated game and adpated the GamesClient mock the simulated game.
1 parent 49ec3c2 commit 759ef62

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/Codebreaker.ViewModels.Tests/GamePageViewModelTests.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,39 @@ namespace CodeBreaker.ViewModels.Tests;
66

77
public class GamePageViewModelTests
88
{
9+
private static readonly string[] s_code = ["Green", "Blue", "Yellow", "Orange"];
10+
private static readonly (string[] GuessPegs, string[] KeyPegs, bool HasEnded, bool IsVictory)[] s_moves = [
11+
(["Red", "Red", "Red", "Red"], [], false, false),
12+
(["Green", "Green", "Green", "Green"], ["Black"], false, false),
13+
(["Blue", "Green", "Green", "Green"], ["White", "White"], false, false),
14+
(["Green", "Blue", "Blue", "Blue"], ["Black", "Black"], false, false),
15+
(["Green", "Blue", "Yellow", "Yellow"], ["Black", "Black", "Black"], false, false),
16+
(["Green", "Blue", "Yellow", "Purple"], ["Black", "Black", "Black"], false, false),
17+
(["Green", "Blue", "Yellow", "Orange"], ["Black", "Black", "Black", "Black"], true, true),
18+
];
19+
920
private readonly Mock<IGamesClient> _gamesClientMock;
1021
private readonly Mock<IInfoBarService> _infoBarServiceMock;
1122

1223
public GamePageViewModelTests()
1324
{
14-
(Guid GameType, int NumberCodes, int MaxMoves, IDictionary<string, string[]> FieldValues) returnValue =
25+
(Guid Id, int NumberCodes, int MaxMoves, IDictionary<string, string[]> FieldValues) gameReturnValue =
1526
(Guid.NewGuid(), 4, 12, new Dictionary<string, string[]>()
1627
{
1728
{ "colors", ["Black", "White", "Red", "Green", "Blue", "Yellow"] }
1829
});
1930

2031
_gamesClientMock = new();
21-
_gamesClientMock.Setup(client => client.StartGameAsync(GameType.Game6x4, "Test", CancellationToken.None)).ReturnsAsync(returnValue);
32+
// Setup the StartGameAsync method of the GamesClient.
33+
_gamesClientMock.Setup(client => client.StartGameAsync(GameType.Game6x4, "Test", CancellationToken.None)).ReturnsAsync(gameReturnValue);
34+
35+
// Setup the SetMoveAsync method of the GamesClient.
36+
for (int i = 0; i < s_moves.Length; i++)
37+
{
38+
var move = s_moves[i];
39+
_gamesClientMock.Setup(client => client.SetMoveAsync(gameReturnValue.Id, "Test", GameType.Game6x4, i + 1, move.GuessPegs, CancellationToken.None))
40+
.ReturnsAsync((move.KeyPegs, move.HasEnded, move.IsVictory));
41+
}
2242

2343
_infoBarServiceMock = new();
2444
}

0 commit comments

Comments
 (0)