Ejemplo n.º 1
0
        public async Task Bet_Placed_With_Brand_Timezone(string timezoneId)
        {
            // Arrange
            var brandId = Guid.NewGuid();

            _repository.Brands.Add(new Core.Game.Interface.Data.Brand
            {
                Id         = brandId,
                TimezoneId = timezoneId
            });

            var playerId = Guid.NewGuid();

            _repository.Players.Add(new Core.Game.Interface.Data.Player()
            {
                Id      = playerId,
                BrandId = brandId
            });

            var placeBetAction = GenerateRandomGameAction();

            // Act
            await _commands.PlaceBetAsync(placeBetAction, _GameActionContext, playerId);

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

            winBetAction.TransactionReferenceId = placeBetAction.ExternalTransactionId;
            winBetAction.RoundId = placeBetAction.RoundId;
            winBetAction.Amount  = 25;

            await _commands.WinBetAsync(winBetAction, _GameActionContext);

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

            var timeComparePattern = "yyyy-MM-dd HH:mm";

            actualRound.Should().NotBeNull();
            actualRound.Data.CreatedOn.ToString(timeComparePattern).Should()
            .Be(DateTimeOffset.UtcNow.ToBrandOffset(timezoneId).ToString(timeComparePattern));
            actualRound.Data.ClosedOn.Value.ToString(timeComparePattern).Should()
            .Be(DateTimeOffset.UtcNow.ToBrandOffset(timezoneId).ToString(timeComparePattern));

            var actualGameAction = actualRound.Data.GameActions[0];

            actualGameAction.GameActionType.Should().Be(GameActionType.Placed);
            actualGameAction.Timestamp.ToString(timeComparePattern).Should()
            .Be(DateTimeOffset.UtcNow.ToBrandOffset(timezoneId).ToString(timeComparePattern));
        }
        private async Task <BetCommandResponseTransaction> PlaceBet(Guid playerId, BetCommandTransactionRequest transaction)
        {
            var  isDuplicate = 0;
            Guid gameActionId;

            ValidateAccountFrozenStatus(playerId);

            try
            {
                gameActionId = await _gameCommands.PlaceBetAsync(
                    new GameActionData
                {
                    RoundId               = transaction.RoundId,
                    ExternalGameId        = transaction.GameId,
                    ExternalTransactionId = transaction.Id,
                    Amount       = transaction.Amount,
                    CurrencyCode = transaction.CurrencyCode,
                    Description  = transaction.Description,
                }, Context, playerId);
            }
            catch (DuplicateGameActionException ex)
            {
                gameActionId = ex.GameActionId;
                isDuplicate  = 1;
            }

            return(new BetCommandResponseTransaction
            {
                GameActionId = gameActionId,
                Id = transaction.Id,
                IsDuplicate = isDuplicate
            });
        }
Ejemplo n.º 3
0
        public async Task <string> PlaceBet(decimal amount, Guid playerId, string gameProviderCode, string gameId, string roundId = null, string transactionId = null)
        {
            roundId = roundId ?? Guid.NewGuid().ToString();
            await _gameCommands.PlaceBetAsync(
                GameActionData.NewGameActionData(roundId, amount, "CAD",
                                                 gameId,
                                                 transactionId),
                new GameActionContext
            {
                GameProviderCode = gameProviderCode
            }, playerId);

            return(roundId);
        }
Ejemplo n.º 4
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();
                    }
                }
            };
        }