private async Task <BetCommandResponseTransaction> CancelTransaction(IBetCommandTransactionRequest transaction, string batchId = null) { var isDuplicate = 0; Guid gameActionId; try { gameActionId = await _gameCommands.CancelTransactionAsync( new GameActionData { RoundId = transaction.RoundId, ExternalTransactionId = transaction.Id, Amount = 0, TransactionReferenceId = transaction.ReferenceId, Description = transaction.Description, BatchId = batchId, }, Context); } catch (DuplicateGameActionException ex) { gameActionId = ex.GameActionId; isDuplicate = 1; } return(new BetCommandResponseTransaction { GameActionId = gameActionId, Id = transaction.Id, IsDuplicate = isDuplicate }); }
private void CancelBet(string roundId, decimal amount, string transactionIdToCancel, string gameProviderCode) { var newBet = GameActionData.NewGameActionData(roundId, amount, "CAD"); newBet.TransactionReferenceId = transactionIdToCancel; _gameCommands.CancelTransactionAsync(newBet, new GameActionContext() { GameProviderCode = gameProviderCode }); }
public async Task Can_Cancel_BetTransaction() { // Arrange var placeBetAction = GenerateRandomGameAction(); var playerId = _playerId; await _commands.PlaceBetAsync(placeBetAction, _GameActionContext, playerId); // place initial bet var cancelBetAction = GenerateRandomGameAction(Guid.NewGuid().ToString()); cancelBetAction.RoundId = placeBetAction.RoundId; cancelBetAction.TransactionReferenceId = placeBetAction.ExternalTransactionId; _gameWalletsOperationsMock.Setup( t => t.CancelBetAsync(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(Guid.NewGuid())); // Act await _commands.CancelTransactionAsync(cancelBetAction, _GameActionContext); // Assert var actualRound = _repository.GetRound(x => x.ExternalRoundId == placeBetAction.RoundId); actualRound.WonAmount.Should().Be(0); actualRound.AdjustedAmount.Should().Be(cancelBetAction.Amount); actualRound.Amount.Should().Be(placeBetAction.Amount); actualRound.Data.GameActions.Count.Should().Be(2); var actualCancelBetAction = actualRound.Data.GameActions[1]; actualCancelBetAction.GameActionType.Should().Be(GameActionType.Cancel); actualCancelBetAction.WalletTransactionId.Should().NotBeEmpty(); actualCancelBetAction.ExternalTransactionId.Should().Be(cancelBetAction.ExternalTransactionId); actualCancelBetAction.ExternalTransactionReferenceId.Should().Be(placeBetAction.ExternalTransactionId); actualCancelBetAction.ExternalBatchId.Should().BeNull(); actualCancelBetAction.Description.Should().Be(cancelBetAction.Description); actualCancelBetAction.Amount.Should().Be(placeBetAction.Amount); actualCancelBetAction.Round.Id.Should().Be(actualRound.Data.Id); _eventBusMock.Verify(x => x.Publish(It.IsAny <BetCancelled>())); }
public UgsGameCommandsAdapter(IGameCommands gameCommands) { _gameCommands = gameCommands; _gameEventsMap = new Dictionary <BusEventType, Action <UgsGameEvent> > { { BusEventType.BetPlaced, @event => { @event.amount = (@event.amount < 0) ? [email protected] : @event.amount; _gameCommands.PlaceBetAsync(GetGameActionData(@event), GetGameActionContext(@event), Guid.Parse(@event.userid)).GetAwaiter().GetResult(); } }, { BusEventType.BetWon, @event => { _gameCommands.WinBetAsync(GetGameActionData(@event), GetGameActionContext(@event)) .GetAwaiter() .GetResult(); } }, { BusEventType.BetLost, @event => { _gameCommands.LoseBetAsync(GetGameActionData(@event), GetGameActionContext(@event)) .GetAwaiter() .GetResult(); } }, { BusEventType.BetFree, @event => { _gameCommands.FreeBetAsync(GetGameActionData(@event), GetGameActionContext(@event), Guid.Parse(@event.userid)).GetAwaiter().GetResult(); } }, { BusEventType.BetTied, @event => { _gameCommands.TieBetAsync(GetGameActionData(@event), GetGameActionContext(@event)) .GetAwaiter() .GetResult(); } }, { BusEventType.BetAdjusted, @event => { _gameCommands.AdjustTransaction(GetGameActionData(@event), GetGameActionContext(@event)); } }, { BusEventType.GameActionCancelled, @event => { _gameCommands.CancelTransactionAsync(GetGameActionData(@event), GetGameActionContext(@event)) .GetAwaiter() .GetResult(); } } }; }