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() ); }
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); }
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"); }
public void GivenANewGameWhenIPlaceAWinningCombinationOfOThenIShouldHaveACompleteBoard() { GivenANewGame(); WhenIPlaceAToken("O", 1, 1); WhenIPlaceAToken("O", 1, 2); PlaceTokenResponse response = WhenIPlaceAToken("O", 1, 3); ExpectACompleteBoard(response); }
public void GivenANewGameWhenIPlaceAWinningSetOfTokensDiagonallyOnTheBoardThenIShouldHaveACompleteBoard() { GivenANewGame(); WhenIPlaceAToken("X", 1, 1); WhenIPlaceAToken("X", 2, 2); PlaceTokenResponse response = WhenIPlaceAToken("X", 3, 3); ExpectACompleteBoard(response); }
public void CannotPlaceATokenOnASquareOutsideOfTheBoard() { PlaceTokenResponse response = Execute(new PlaceTokenRequest { Board = New(), Type = "X", Column = 4, Row = 4, }); ExpectAResponseWithAGivenGridAndError(response, new string[9], new OffBoardException()); }
public void CanPlaceATokenOnTheLastSquareOfABoard() { PlaceTokenResponse response = Execute(new PlaceTokenRequest { Board = New(), Type = "X", Column = 3, Row = 3, }); ExpectTheBoardToHaveAAt(response, "X", 8); }
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(), }); }
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(), }); }
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); }
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() ); }
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>(); }
private static void ExpectACompleteBoard(PlaceTokenResponse response) { response.Status.Should().BeOfType <Complete>(); }