Beispiel #1
0
        public async Task NoGamesInitially()
        {
            using var fixture = new ApiFixture(5016);

            var graphQLResponse = await fixture.Execute <GraphQlGameModel>(gamesRequest());

            graphQLResponse.Games.Length.Should().Be(0);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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");
        }
Beispiel #5
0
        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");
        }
Beispiel #6
0
        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");
        }