Example #1
0
        public void PlayerMoveMustReturnAnExceptionIfGridCheckReturnsNotValidPlayerValue()
        {
            // Given
            ITicTacToe game    = new TicTacToeImpl();
            Player     playerA = new Player();
            Player     playerB = new Player();

            igridMock.Setup(m => m.Check()).Returns(CellPlayer.TEST_OTHER_PLAYER);

            // When
            game.StartGame(igridMock.Object, playerA, playerB);

            // Then
            NotValidStateException exc = Assert.Throws <NotValidStateException>(() => game.PlayerMove(playerA, new Coordinate(0, 0)), "PlayerMove must raise NotValidStateException");

            Assert.AreEqual(exc.ErrorCode, ErrorCode.OUT_OF_RANGE, "Exception must have OUT_OF_RANGE error code");
        }
Example #2
0
        public void PlayerMoveMustSpreadExceptionWhenGridSetReturnsNotValidStateExceptionWithUnknownErrorCode()
        {
            // Given
            ITicTacToe game    = new TicTacToeImpl();
            Player     playerA = new Player();
            Player     playerB = new Player();

            igridMock.Setup(m => m.Set(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CellPlayer>())).Throws(new NotValidStateException("", ErrorCode.UNKNOWN));

            // When
            game.StartGame(igridMock.Object, playerA, playerB);

            // Then
            NotValidStateException exc = Assert.Throws <NotValidStateException>(() => game.PlayerMove(playerA, new Coordinate(0, 0)), "PlayerMove must raise NotValidStateException");

            Assert.AreEqual(exc.ErrorCode, ErrorCode.UNKNOWN, "Exception must have UNKNOWN error code");
        }