public async Task StartGame() { using var fixture = new ApiFixture(5019); var r = await fixture.SendMutation <GraphQlPlayerModelRoot>(createGameRequest("Game1", "Lorem Ipsum", "Player1")); await fixture.SendMutation <GraphQlGameModel>(startGameRequest("Game1")); var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest()); graphQLResponse.Games[0].Started.Should().Be(true); }
public async Task CreateGame() { using var fixture = new ApiFixture(5015); var r = await fixture.SendMutation <GraphQlPlayerModelRoot>(createGameRequest("Game1", "Lorem Ipsum", "Player1")); await fixture.SendMutation <GraphQlPlayerModelRoot>(createGameRequest("Game1", "Lorem Ipsum", "Player1")); var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest()); graphQLResponse.Games.Length.Should().Be(1); graphQLResponse.Games[0].Name.Should().Be("Game1"); graphQLResponse.Games[0].Started.Should().Be(false); graphQLResponse.Games[0].GameText.Should().Be("Lorem Ipsum"); graphQLResponse.Games[0].Players.Length.Should().Be(1); }
public async Task PlayerJoin() { using var fixture = new ApiFixture(5014); // todo: gameText shouldn't be required await fixture.SendMutation <GraphQlPlayerModelRoot>(joinGameRequest("Game1", "Steve", "Lorem Ipsum")); await fixture.SendMutation <GraphQlPlayerModelRoot>(joinGameRequest("Game1", "Steve", "Lorem Ipsum")); var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest()); graphQLResponse.Games.Length.Should().Be(1); graphQLResponse.Games[0].Name.Should().Be("Game1"); graphQLResponse.Games[0].Players.Count().Should().Be(1); graphQLResponse.Games[0].Players.Single().Name.Should().Be("Steve"); }
public async Task PlayerKeystroke() { using var fixture = new ApiFixture(5017); var playerName = "Player 1"; var gameName = "Game1"; var playerKeystrokeRequest = new GraphQLRequest { Query = @"mutation Keystroke($gameName: String!, $playerName: String!, $keystroke: String!) { addGameKeystroke(gameName: $gameName, playerName: $playerName, keystroke: $keystroke) { playerName keystroke id } }", Variables = new { gameName = gameName, playerName = playerName, keystroke = "A" } }; await fixture.SendMutation <GraphQlPlayerModelRoot>(joinGameRequest(gameName, playerName, "Lorem Ipsum")); await fixture.SendMutation <GraphQlGameModel>(startGameRequest(gameName)); await fixture.SendMutation <GraphQlPlayerModelRoot>(playerKeystrokeRequest); await fixture.SendMutation <GraphQlPlayerModelRoot>(playerKeystrokeRequest); var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest()); graphQLResponse.Games.Length.Should().Be(1); graphQLResponse.Games[0].Name.Should().Be(gameName); graphQLResponse.Games[0].Players.Count().Should().Be(1); var p = graphQLResponse.Games[0].Players.Single(); p.Name.Should().Be(playerName); p.Keystrokes.ElementAt(0).Should().Be("A"); p.Keystrokes.ElementAt(1).Should().Be("A"); }
public async Task PlayerCantJoinStartedGame() { using var fixture = new ApiFixture(5014); await fixture.SendMutation <GraphQlPlayerModelRoot>(createGameRequest("Game1", "Lorem Ipsum", "Player 1")); await fixture.SendMutation <GraphQlGameModel>(startGameRequest("Game1")); try { await fixture.SendMutation <GraphQlPlayerModelRoot>(joinGameRequest("Game1", "Player2", "Lorem Ipsum")); } catch { } var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest()); graphQLResponse.Games.Length.Should().Be(1); graphQLResponse.Games[0].Name.Should().Be("Game1"); graphQLResponse.Games[0].Players.Count().Should().Be(1); graphQLResponse.Games[0].Players.Single().Name.Should().Be("Player 1"); }
internal static async Task<T> Apply<T>(Func<GraphQLHttpClient, Task<GraphQLResponse<T>>> func, ApiFixture fixture) { await fixture.ServerRunning; var graphQLClient = new GraphQLHttpClient(fixture.Url, new NewtonsoftJsonSerializer()); var graphQLResponse = await func(graphQLClient); if (graphQLResponse.Errors?.Any() ?? false) { throw new System.Exception(graphQLResponse.Errors.First().Message); } return graphQLResponse.Data; }
internal static Task<T> Execute<T>(this ApiFixture fixture, GraphQLRequest heroRequest) { return Apply(graphQLClient => graphQLClient.SendQueryAsync<T>(heroRequest), fixture); }
internal static Task<T> SendMutation<T>(this ApiFixture fixture, GraphQLRequest heroRequest) { return Apply(graphQLClient => graphQLClient.SendMutationAsync<T>(heroRequest), fixture); }