public async Task <CancelGameResult> Handle(CancelGame request, CancellationToken cancellationToken) { using (var transaction = repositoryTransactionsFactory.CreateTransaction()) { var validatorResult = await validator.Validate(request); if (!validatorResult.IsSuccessful) { return(new CancelGameResult(validatorResult.Error)); } var ended = await gamesRepository.CancelGame(request.GameId); if (!ended) { return(new CancelGameResult(GameErrors.GameCouldNotBeCancelled)); } var checkpoint = await gameCheckpointUpdater.Update(request.GameId, nameof(SkipRound)); transaction.CommitTransaction(); return(new CancelGameResult()); } }
/// <summary> /// /// </summary> /// <param name="message"></param> private void HandleCancelGame(CancelGame message) { this.log.Info("Cancelling the game {0}", message.Guid); // send the cancellation message to the game server this.gameServiceSelection.Tell(message); this.isCancelling = true; }
public async Task ReturnFailureForInvalidStatus(Common.Enums.GameStatusEnum gameStatus) { var baseMock = BaseGameRequestsValidatorMock.CreateMock(); var gameRepoMock = GamesRepositoryMock.Create( gameStatus: gameStatus); var gameOwnerRuleMock = GameOwnerRuleMock.Create <CancelGame>(); var validator = new CancelGameValidator(baseMock.Object, gameOwnerRuleMock.Object, gameRepoMock.Object); var request = new CancelGame { GameId = 1, UserId = 1 }; var result = await validator.Validate(request); Assert.False(result.IsSuccessful); Assert.Equal(ValidatorErrors.Games.GameNotFoundOrInactive, result.Error); }
public async Task ReturnSuccessForValidData() { var baseMock = BaseGameRequestsValidatorMock.CreateMock(); var gameRepoMock = GamesRepositoryMock.Create(); var gameOwnerRuleMock = GameOwnerRuleMock.Create <CancelGame>(); var validator = new CancelGameValidator(baseMock.Object, gameOwnerRuleMock.Object, gameRepoMock.Object); var request = new CancelGame { GameId = 1, UserId = 1 }; var result = await validator.Validate(request); Assert.True(result.IsSuccessful); baseMock.Verify(x => x.Validate(request)); gameOwnerRuleMock.Verify(x => x.Validate(request)); }