private BetCommandResponseTransaction AdjustTransaction(IBetCommandTransactionRequest transaction, string batchId = null)
        {
            var  isDuplicate = 0;
            Guid gameActionId;

            try
            {
                gameActionId = _gameCommands.AdjustTransaction(
                    new GameActionData
                {
                    RoundId = transaction.RoundId,
                    ExternalTransactionId  = transaction.Id,
                    TransactionReferenceId = transaction.ReferenceId,
                    Amount       = transaction.Amount,
                    CurrencyCode = transaction.CurrencyCode,
                    Description  = transaction.Description,
                    BatchId      = batchId,
                },
                    Context);
            }
            catch (DuplicateGameActionException ex)
            {
                gameActionId = ex.GameActionId;
                isDuplicate  = 1;
            }

            return(new BetCommandResponseTransaction
            {
                GameActionId = gameActionId,
                Id = transaction.Id,
                IsDuplicate = isDuplicate
            });
        }
Example #2
0
        public async Task Can_Adjust_Bet()
        {
            // Arrange
            var placeBetAction = GenerateRandomGameAction();
            var playerId       = _playerId;

            await _commands.PlaceBetAsync(placeBetAction, _GameActionContext, playerId); // place initial bet

            var adjustingAction = GenerateRandomGameAction(Guid.NewGuid().ToString());

            adjustingAction.TransactionReferenceId = placeBetAction.ExternalTransactionId;
            adjustingAction.RoundId = placeBetAction.RoundId;
            adjustingAction.Amount  = placeBetAction.Amount + 20;

            _gameWalletsOperationsMock.Setup(
                t => t.AdjustBetTransaction(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <decimal>(), It.IsAny <string>(), It.IsAny <string>()))
            .Returns(Guid.NewGuid());

            // Act
            _commands.AdjustTransaction(adjustingAction, _GameActionContext);

            // Assert
            var actualRound = _repository.GetRound(x => x.ExternalRoundId == placeBetAction.RoundId);

            actualRound.WonAmount.Should().Be(0);
            actualRound.AdjustedAmount.Should().Be(adjustingAction.Amount);
            actualRound.Amount.Should().Be(placeBetAction.Amount);
            actualRound.Data.GameActions.Count.Should().Be(2);

            var actualAdjustmentGameAction = actualRound.Data.GameActions[1];

            actualAdjustmentGameAction.GameActionType.Should().Be(GameActionType.Adjustment);
            actualAdjustmentGameAction.WalletTransactionId.Should().NotBeEmpty();
            actualAdjustmentGameAction.ExternalTransactionId.Should().Be(adjustingAction.ExternalTransactionId);
            actualAdjustmentGameAction.ExternalTransactionReferenceId.Should().Be(placeBetAction.ExternalTransactionId);
            actualAdjustmentGameAction.ExternalBatchId.Should().BeNull();
            actualAdjustmentGameAction.Description.Should().Be(adjustingAction.Description);
            actualAdjustmentGameAction.Amount.Should().Be(adjustingAction.Amount);
            actualAdjustmentGameAction.Round.Id.Should().Be(actualRound.Data.Id);


            _eventBusMock.Verify(x => x.Publish(It.IsAny <BetAdjusted>()));
        }
Example #3
0
        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();
                    }
                }
            };
        }