public void AddNullDataMustRaiseException() { // Given MockRepository rep = new MockRepository(); // When / Then NotValidValueException exc = Assert.Throws <NotValidValueException>(() => rep.Add(null), "Adding null object must raise exception"); Assert.AreEqual(exc.ErrorCode, ErrorCode.NULL_VALUE_NOT_ALLOWED); }
public void PlayerAMustBeDifferentFromPlayerB() { // Given Player player = new Player(); ITicTacToe game = new TicTacToeImpl(); // When/Then NotValidValueException exc = Assert.Throws <NotValidValueException>(() => game.StartGame(grid, player, player), "Initializing with same player must return exception"); Assert.AreEqual(ErrorCode.PLAYERS_ARE_SAME, exc.ErrorCode, "Exception ErrorCode must be PLAYERS_ARE_SAME"); }
public void AddedGameMustNotBeNull() { // Given IBoringToeRepository repo = new BoringToeSetRepository(); long id; // When / Then NotValidValueException excep = Assert.Throws <NotValidValueException>(() => id = repo.AddGame(null), "Adding null game must return NotValidValueException"); Assert.AreEqual(excep.ErrorCode, ErrorCode.NULL_VALUE_NOT_ALLOWED, "Exception's error code must be NULL_VALUE_NOT_ALLOWED"); }
public void InexistingPlayerMustThrowException() { // Given Player playerA = new Player(); Player playerB = new Player(); Player other = new Player(); ITicTacToe game = new TicTacToeImpl(); // When game.StartGame(grid, playerA, playerB); // Then NotValidValueException exc = Assert.Throws <NotValidValueException>(() => game.PlayerMove(other, new Coordinate(0, 0)), "Move must return an exception is player is not in initialization"); Assert.AreEqual(ErrorCode.PLAYER_NOT_EXISTS, exc.ErrorCode, "Exception ErrorCode must be PLAYER_NOT_EXISTS"); }
public void NewGameExceptionMustBeThrownWhenPlayerBNotExistsInDatabase() { // Given playerMock.SetupSequence(m => m.GetPlayerById(It.IsAny <long>())) .Returns(new Player("")) .Throws(new NotExistingValueException("", ErrorCode.VALUE_NOT_EXISTING_IN_DATABASE)); // When IBoringToeService service = new BoringToeService(gameMock.Object, playerMock.Object); // Then NotValidValueException resp = Assert.Throws <NotValidValueException>(() => service.NewGame(new BoringToeNewGameRequest(10, 20)), "New game must raise an exception"); Assert.AreEqual(ErrorCode.PLAYER_B_NOT_EXISTING, resp.ErrorCode, "Exception's error code must be PLAYER_B_NOT_EXISTING"); playerMock.Verify(m => m.GetPlayerById(It.IsAny <long>()), Times.Exactly(2), "Must call 2 times to player repository get"); }
public void IfPlayerDoesntExistInRepoExceptionMustBeThrown() { // Given playerMock.Setup(m => m.GetPlayerById(It.IsAny <long>())) .Throws(new NotExistingValueException("", ErrorCode.VALUE_NOT_EXISTING_IN_DATABASE)); gameMock.Setup(m => m.GetGameById(It.IsAny <long>())) .Returns(tictacMock.Object); // When IBoringToeService service = new BoringToeService(gameMock.Object, playerMock.Object); // Then NotValidValueException exc = Assert.Throws <NotValidValueException>(() => service.PlayerMove(1, new BoringToeMoveRequest(1, 1, 1)), "Player move must raise NotValidValueException"); Assert.AreEqual(ErrorCode.PLAYER_NOT_EXISTS, exc.ErrorCode, "Exception's code must be PLAYER_NOT_EXISTS"); }
public void IfPlayerDoesntExistInGameExceptionMustBeRethrown() { // Given tictacMock.Setup(m => m.PlayerMove(It.IsAny <Player>(), It.IsAny <Coordinate>())) .Throws(new NotValidValueException("", ErrorCode.PLAYER_NOT_EXISTS)); gameMock.Setup(m => m.GetGameById(It.IsAny <long>())) .Returns(tictacMock.Object); // When IBoringToeService service = new BoringToeService(gameMock.Object, playerMock.Object); // Then NotValidValueException exc = Assert.Throws <NotValidValueException>(() => service.PlayerMove(1, new BoringToeMoveRequest(1, 1, 1)), "Player move must raise NotValidValueException"); Assert.AreEqual(ErrorCode.PLAYER_NOT_EXISTS, exc.ErrorCode, "Exception's code must be PLAYER_NOT_EXISTS"); tictacMock.Verify(m => m.PlayerMove(It.IsAny <Player>(), It.IsAny <Coordinate>()), Times.Once, "Must call game's playermove once"); gameMock.Verify(m => m.GetGameById(It.IsAny <long>()), Times.Once, "Must call game repository get game once"); }