Пример #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()
                );
        }
Пример #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);
        }
Пример #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");
        }
Пример #4
0
        public void GivenANewGameWhenIPlaceAWinningCombinationOfOThenIShouldHaveACompleteBoard()
        {
            GivenANewGame();
            WhenIPlaceAToken("O", 1, 1);
            WhenIPlaceAToken("O", 1, 2);
            PlaceTokenResponse response = WhenIPlaceAToken("O", 1, 3);

            ExpectACompleteBoard(response);
        }
Пример #5
0
        public void GivenANewGameWhenIPlaceAWinningSetOfTokensDiagonallyOnTheBoardThenIShouldHaveACompleteBoard()
        {
            GivenANewGame();
            WhenIPlaceAToken("X", 1, 1);
            WhenIPlaceAToken("X", 2, 2);
            PlaceTokenResponse response = WhenIPlaceAToken("X", 3, 3);

            ExpectACompleteBoard(response);
        }
Пример #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());
        }
Пример #7
0
        public void CanPlaceATokenOnTheLastSquareOfABoard()
        {
            PlaceTokenResponse response = Execute(new PlaceTokenRequest
            {
                Board  = New(),
                Type   = "X",
                Column = 3,
                Row    = 3,
            });

            ExpectTheBoardToHaveAAt(response, "X", 8);
        }
Пример #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(),
            });
        }
Пример #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(),
     });
 }
Пример #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);
        }
Пример #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()
                );
        }
Пример #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>();
        }
Пример #13
0
 private static void ExpectACompleteBoard(PlaceTokenResponse response)
 {
     response.Status.Should().BeOfType <Complete>();
 }