public void Play_CallsBoardGame_ToDrawTheTicTacToeBoard() { //Arrange var players = new List<IPlayer>(); IResultsCheckingService resultsCheckingService = new ResultsCheckingService(); var game = new Game(_board, resultsCheckingService); //Act game.Play(players); //Assert _board.AssertWasCalled(b => b.Render()); }
public void CheckForAnyResult_ReturnsTrue_WhenAnyOfTheRulesPasses() { IGameRule diagonalWinningRule = MockRepository.GenerateMock<IGameRule>(); IGameRule verticalWinningRule = MockRepository.GenerateMock<IGameRule>(); IGameRule horizantalWinningRule = MockRepository.GenerateMock<IGameRule>(); IGameRule gameIsADrawRule = MockRepository.GenerateMock<IGameRule>(); diagonalWinningRule.Stub(r => r.Apply()).Return(true); verticalWinningRule.Stub(r => r.Apply()).Return(false); horizantalWinningRule.Stub(r => r.Apply()).Return(false); gameIsADrawRule.Stub(r => r.Apply()).Return(false); IGameRule[] gameRules = { diagonalWinningRule,verticalWinningRule,horizantalWinningRule,gameIsADrawRule }; var resultsCheckingService = new ResultsCheckingService(gameRules); Assert.IsTrue(resultsCheckingService.CheckForAnyResult()); }
public void Play_MustAlternateBetweenThePlayersWhenCalled() { //Arrange var player1 = MockRepository.GenerateMock<IPlayer>(); var player2 = MockRepository.GenerateMock<IPlayer>(); var players = new List<IPlayer>() { player1, player2 }; _board.Stub(b => b.Render()); IResultsCheckingService resultsCheckingService = new ResultsCheckingService(); var game = new Game(_board, resultsCheckingService); //Act for (int i = 0; i < 2; i++) { game.Play(players); } //Assert player1.AssertWasCalled(p1 => p1.MakeMove(Arg<int>.Is.Anything), options => options.Repeat.Once()); player2.AssertWasCalled(p2 => p2.MakeMove(Arg<int>.Is.Anything), options => options.Repeat.Once()); }
public void CheckForDraw_ReturnsFalse_WhenDrawRuleFails() { IGameRule diagonalWinningRule = MockRepository.GenerateMock<IGameRule>(); IGameRule verticalWinningRule = MockRepository.GenerateMock<IGameRule>(); IGameRule horizantalWinningRule = MockRepository.GenerateMock<IGameRule>(); IBoard board = MockRepository.GenerateMock<IBoard>(); char[] drawBoardPositions = { '0', 'X', 'X', 'X', '4', '5', '6', '7', '8', '9' }; board.Stub(b => b.BoardPositions).Return(drawBoardPositions); IGameRule gameIsADrawRule = new GameIsADrawRule(board); diagonalWinningRule.Stub(r => r.Apply()).Return(false); verticalWinningRule.Stub(r => r.Apply()).Return(false); horizantalWinningRule.Stub(r => r.Apply()).Return(false); IGameRule[] gameRules = { diagonalWinningRule,verticalWinningRule,horizantalWinningRule,gameIsADrawRule }; var resultsCheckingService = new ResultsCheckingService(gameRules); Assert.IsFalse(resultsCheckingService.CheckForDraw()); }
private static void StartANewGame(List<IPlayer> players, Board board) { var diagonalWinningRule = new DiagonalWinningRule(board); var horizantalWinningRule = new HorizantalWinningRule(board); var verticalWinningRule = new VerticalWinningRule(board); var gameIsADrawRule = new GameIsADrawRule(board, diagonalWinningRule, horizantalWinningRule, verticalWinningRule); IResultsCheckingService resultsCheckingService = new ResultsCheckingService(gameIsADrawRule, diagonalWinningRule, horizantalWinningRule, verticalWinningRule); var game = new Game(board, resultsCheckingService); game.Play(players); }