public void WillSetTheReturnedValueFromPlayerCreationToTheTile()
        {
            Mock <IPlayerCreationService> mockService = new Mock <IPlayerCreationService>(MockBehavior.Loose);
            Tile   tile = new Tile();
            Player p    = new RandomAi(null, null);

            tile.owner = 0;
            mockService.Setup(x => x.createPlayer(It.IsAny <JObject>())).Returns(p);
            service = new UltimateTicTacToeCreationService(new Mock <IWinChecker>().Object);
            List <List <JObject> > board = new List <List <JObject> >
            {
                new List <JObject>
                {
                    JObject.FromObject(tile)
                }
            };
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            Assert.AreEqual((PlayerColour)0, (game.board[0][0] as Tile).owner);
        }
        public void NestedGamesWillHaveAWinChecker()
        {
            Mock <IWinChecker> mockHandler = new Mock <IWinChecker>(MockBehavior.Loose);

            mockHandler.Setup(x => x.checkForWin(It.IsAny <BoardGame>())).Returns(0);
            service = new UltimateTicTacToeCreationService(mockHandler.Object);;
            JObject ticTacToe = new JObject();

            ticTacToe.Add("board", JToken.FromObject(new List <List <BoardGame> >()));
            List <List <JObject> > board = JNestedBoard;
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            try
            {
                (game.getBoard()[0][0] as TicTacToe).getWinner();
            }
            catch (Exception e)
            {
                Assert.Fail("Expected no exception but got: " + e);
            }
        }
        public void WillPassAWinCheckerToTheTicTacToeGameOuter()
        {
            Mock <IWinChecker> mockHandler = new Mock <IWinChecker>();

            service = new UltimateTicTacToeCreationService(mockHandler.Object);
            TicTacToe result       = service.createBoardGame(3) as TicTacToe;
            TicTacToe internalGame = result.board[0][0] as TicTacToe;

            internalGame.getWinner();
        }
 public void Setup()
 {
     service = new UltimateTicTacToeCreationService(new Mock <IWinChecker>().Object);
     JBoard  = new JObject();
     JBoard.Add("board", JToken.FromObject(new List <List <BoardGame> >()));
     JBoard.Add("owner", JToken.FromObject(0));
     JNestedBoard = new List <List <JObject> >
     {
         new List <JObject>
         {
             JBoard
         }
     };
 }
        public void WillSupplyAWinCheckerToTheGame()
        {
            Mock <IWinChecker>            mockHandler = new Mock <IWinChecker>(MockBehavior.Loose);
            List <List <JObject> >        board       = JNestedBoard;
            Mock <IPlayerCreationService> mockService = new Mock <IPlayerCreationService>(MockBehavior.Loose);

            mockService.Setup(x => x.createPlayer(It.IsAny <JObject>()));
            service = new UltimateTicTacToeCreationService(mockHandler.Object);
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            game.getWinner();
        }
        public void WillPopulateALongRows()
        {
            List <List <JObject> > board = JNestedBoard;

            board[0].Add(JBoard);
            Mock <IPlayerCreationService> mockService = new Mock <IPlayerCreationService>(MockBehavior.Loose);

            mockService.Setup(x => x.createPlayer(It.IsAny <JObject>()));
            service = new UltimateTicTacToeCreationService(new Mock <IWinChecker>().Object);
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            Assert.IsTrue(game.getBoard()[0].Count == 2);
        }
        public void WillPopulateAOneByOneGame()
        {
            List <List <JObject> > board = new List <List <JObject> > {
                new List <JObject> {
                    JObject.FromObject(new Tile())
                }
            };
            Mock <IPlayerCreationService> mockService = new Mock <IPlayerCreationService>(MockBehavior.Loose);

            mockService.Setup(x => x.createPlayer(It.IsAny <JObject>()));
            service = new UltimateTicTacToeCreationService(new Mock <IWinChecker>().Object);
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            Assert.IsTrue(game.getBoard()[0][0] is Tile);
        }
        public void WillPassCreateTilesWithAssignedOwners()
        {
            service = new UltimateTicTacToeCreationService(new Mock <IWinChecker>().Object);
            List <List <JObject> > board = new List <List <JObject> >
            {
                new List <JObject>
                {
                    JObject.FromObject(new Tile
                    {
                        owner = 0
                    })
                }
            };
            Move move = new Move();

            move.next = new Move();
            TicTacToe game = service.createBoardGame(new BoardGameDTO {
                game = board, lastMove = move
            }) as TicTacToe;

            Assert.IsTrue(game.board[0][0].getWinner() == (PlayerColour)0);
        }
 public GameController(IGameService gameService, BoardCreationService boardCreationService, IPlayerCreationService playerCreationService)
 {
     this.gameService           = gameService;
     this.boardCreationService  = boardCreationService;
     this.playerCreationService = playerCreationService;
 }