コード例 #1
0
        public void GivenAGame_WhenAttacked_ThenReturnResult()
        {
            var game = _mockGame.Object;

            _mockGameRegistry
            .Setup(x => x.GetGame(game.Id))
            .Returns(game);

            var request = new AttackRequest
            {
                XCoordinate = 1,
                YCoordinate = 0
            };
            var result = _controller.Attack(game.Id, request) as OkObjectResult;

            result.Should().NotBeNull();
            _mockGameRegistry.Verify(x => x.GetGame(game.Id), Times.Once);
        }
コード例 #2
0
        void ready_to_play()
        {
            before = () =>
            {
                result = GivenAGame(name: "join now");

                gameId = result.GameId();

                player1 = result.UserId();

                player2 = Guid.NewGuid().ToString();

                JoinGame(gameId, player2);

                SetupGame(player1, gameId, "1A");

                SetupGame(player2, gameId, "1B");
            };

            act = () =>
            {
                controller.Ready(new { gameId, playerId = player1 }.ToParams());

                controller.Ready(new { gameId, playerId = player2 }.ToParams());
            };

            it["the game is considered started"] = () =>
                                                   ((bool)GetGame(gameId).Started).should_be_true();

            it["a loser hasn't been assigned"] = () =>
                                                 (GetGame(gameId).Loser as string).should_be("");

            context["player 1 hits"] = () =>
            {
                act = () =>
                      controller.Attack(new
                {
                    gameId,
                    playerId = player1,
                    location = "1B"
                }.ToParams());

                it["the hit is marked"] = () =>
                                          ((bool)GetGame(gameId).Player1HitsOnPlayer2.Contains("1B")).should_be_true();

                it["the loser is set"] = () =>
                                         ((string)GetGame(gameId).Loser).should_be(player2);
            };

            context["player 1 misses"] = () =>
            {
                act = () =>
                      controller.Attack(new
                {
                    gameId,
                    playerId = player1,
                    location = "2A"
                }.ToParams());

                it["the miss is marked"] = () =>
                                           ((bool)GetGame(gameId).Player1MissesOnPlayer2.Contains("2A")).should_be_true();

                it["is the next player's turn"] = () =>
                                                  ((string)GetGame(gameId).CurrentTurn).should_be(player2);

                it["attempts to attack by player 1 are ignored"] = () =>
                {
                    controller.Attack(new
                    {
                        gameId,
                        playerId = player1,
                        location = "3A"
                    }.ToParams());

                    ((bool)GetGame(gameId).Player1MissesOnPlayer2.Contains("3A")).should_be_false();
                };

                context["player 2 misses"] = () =>
                {
                    act = () =>
                          controller.Attack(new
                    {
                        gameId,
                        playerId = player2,
                        location = "5A"
                    }.ToParams());

                    it["the miss is marked"] = () =>
                                               ((bool)GetGame(gameId).Player2MissesOnPlayer1.Contains("5A")).should_be_true();

                    it["is the next player's turn"] = () =>
                                                      ((string)GetGame(gameId).CurrentTurn).should_be(player1);
                };

                context["player 2 hits"] = () =>
                {
                    act = () =>
                          controller.Attack(new
                    {
                        gameId,
                        playerId = player2,
                        location = "1A"
                    }.ToParams());

                    it["the hit is marked"] = () =>
                                              ((bool)GetGame(gameId).Player2HitsOnPlayer1.Contains("1A")).should_be_true();

                    it["the loser is set"] = () =>
                                             ((string)GetGame(gameId).Loser).should_be(player1);
                };
            };
        }