Ejemplo n.º 1
0
        public void CannotPlaceATokenOnASquareThatAlreadyHasATokenOnIt()
        {
            Board board = New();

            PlaceTokenResponse placeXResponse = Execute(new PlaceTokenRequest
            {
                Board  = board,
                Type   = "X",
                Column = 1,
                Row    = 1,
            });

            PlaceTokenResponse placeOResponse = Execute(new PlaceTokenRequest
            {
                Board  = placeXResponse.Board,
                Type   = "O",
                Column = 1,
                Row    = 1,
            });

            ExpectAResponseWithAGivenGridAndError(
                placeOResponse,
                new string[9] {
                "X", null, null, null, null, null, null, null, null
            },
                new AlreadyPlacedException()
                );
        }
Ejemplo n.º 2
0
        public void CanCompleteAGameByPlacingMultipleOTokens()
        {
            Board board = New();

            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = board,
                Type   = "O",
                Column = 1,
                Row    = 1,
            });

            response = Execute(new PlaceTokenRequest
            {
                Board  = response.Board,
                Type   = "O",
                Column = 1,
                Row    = 2,
            });

            response = Execute(new PlaceTokenRequest
            {
                Board  = response.Board,
                Type   = "O",
                Column = 1,
                Row    = 3,
            });

            ExpectACompleteBoard(response);
        }
Ejemplo n.º 3
0
        public void GivenACompleteGameWhenIPlaceATokenOnTheBoardThenTheStateOfTheBoardShouldNotChange()
        {
            GivenACompleteGame();
            PlaceTokenResponse response = WhenIPlaceAToken("X", 2, 2);

            response.Board.IsComplete().Should().BeTrue("The game is finished");
            response.Board.Grid[3 * 1 + 1].Should().BeNullOrEmpty("New tokens are not allowed");
        }
Ejemplo n.º 4
0
        public void GivenANewGameWhenIPlaceAWinningCombinationOfOThenIShouldHaveACompleteBoard()
        {
            GivenANewGame();
            WhenIPlaceAToken("O", 1, 1);
            WhenIPlaceAToken("O", 1, 2);
            PlaceTokenResponse response = WhenIPlaceAToken("O", 1, 3);

            ExpectACompleteBoard(response);
        }
Ejemplo n.º 5
0
        public void GivenANewGameWhenIPlaceAWinningSetOfTokensDiagonallyOnTheBoardThenIShouldHaveACompleteBoard()
        {
            GivenANewGame();
            WhenIPlaceAToken("X", 1, 1);
            WhenIPlaceAToken("X", 2, 2);
            PlaceTokenResponse response = WhenIPlaceAToken("X", 3, 3);

            ExpectACompleteBoard(response);
        }
Ejemplo n.º 6
0
        public void CannotPlaceATokenOnASquareOutsideOfTheBoard()
        {
            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = New(),
                Type   = "X",
                Column = 4,
                Row    = 4,
            });

            ExpectAResponseWithAGivenGridAndError(response, new string[9], new OffBoardException());
        }
Ejemplo n.º 7
0
        public void CanPlaceATokenOnTheLastSquareOfABoard()
        {
            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = New(),
                Type   = "X",
                Column = 3,
                Row    = 3,
            });

            ExpectTheBoardToHaveAAt(response, "X", 8);
        }
Ejemplo n.º 8
0
        private static void ExpectTheBoardToHaveAAt(PlaceTokenResponse response, string type, int index)
        {
            string[] grid = new string[9];

            grid[index] = type;

            response.Should().BeEquivalentTo(new NewGameResponse
            {
                Board = new Board
                {
                    Grid = grid
                },
                Status = new Incomplete(),
            });
        }
Ejemplo n.º 9
0
 private static void ExpectAResponseWithAGivenGridAndError(
     PlaceTokenResponse response,
     string[] expectedGrid,
     System.Exception expectedError
     )
 {
     response.Should().BeEquivalentTo(new PlaceTokenResponse
     {
         Board = new Board
         {
             Grid = expectedGrid,
         },
         Error  = expectedError,
         Status = new Incomplete(),
     });
 }
Ejemplo n.º 10
0
        private PlaceTokenResponse WhenIPlaceAToken(string type, int column, int row)
        {
            PlaceTokenRequest request = new PlaceTokenRequest
            {
                Board  = _board,
                Row    = row,
                Column = column,
                Type   = type,
            };

            PlaceTokenResponse response = _placeToken.Execute(request);

            _board = response.Board;

            return(response);
        }
Ejemplo n.º 11
0
        public void CannotPlaceAnInvalidToken()
        {
            Board board = New();

            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = board,
                Type   = "Y",
                Column = 1,
                Row    = 1,
            });

            ExpectAResponseWithAGivenGridAndError(
                response,
                new string[9],
                new InvalidTokenException()
                );
        }
Ejemplo n.º 12
0
        public void CannotPlaceATokenOnACompleteBoard()
        {
            Board board = New();

            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = board,
                Type   = "X",
                Column = 1,
                Row    = 1,
            });

            response = Execute(new PlaceTokenRequest
            {
                Board  = response.Board,
                Type   = "X",
                Column = 1,
                Row    = 2,
            });

            response = Execute(new PlaceTokenRequest
            {
                Board  = response.Board,
                Type   = "X",
                Column = 1,
                Row    = 3,
            });

            response = Execute(new PlaceTokenRequest
            {
                Board  = response.Board,
                Type   = "X",
                Column = 2,
                Row    = 2,
            });

            response.Error.Should().BeOfType <BoardCompleteException>();
        }
Ejemplo n.º 13
0
 private static void ExpectACompleteBoard(PlaceTokenResponse response)
 {
     response.Status.Should().BeOfType <Complete>();
 }