public async void GetBetForSpecificGameModeId()
        {
            var bet  = new DatabaseModel.Bet(_setup.User2.Id, _setup.Match3.Id, _setup.GameMode.Id, DateTime.Now);
            var bet1 = new DatabaseModel.Bet(_setup.User2.Id, _setup.CoinFlip1.Id, _setup.GameMode1.Id, DateTime.Now);

            var betRepo = new BetRepoService(_fakedFactory, new BetQueries());
            await betRepo.InsertAsync(bet);

            var insertedBet1 = await betRepo.InsertAsync(bet1);

            var res = await betRepo.FindAsync(new List <LookUpGameModeBet>
            {
                new LookUpGameModeBet
                {
                    GameMode = _setup.GameMode1,
                    MatchIds = new List <int>
                    {
                        _setup.CoinFlip1.Id
                    },
                    User = _setup.User2
                }
            });

            Assert.Equal(1, res.Count);
            Assert.Equal(insertedBet1.Id, res.First().Id);
        }
Exemple #2
0
        private async Task SendWebsocketMatchEvent(DatabaseModel.User user, int matchId, List <Item> itemModels,
                                                   DatabaseModel.Bet insertedBet)
        {
            foreach (var itemModel in itemModels)
            {
                itemModel.Owner = new User
                {
                    ImageUrl = user.ImageUrl,
                    Name     = user.Name,
                    SteamId  = user.SteamId
                };
            }

            var model = new UserBetsOnMatchModel
            {
                MatchId = matchId,
                Bet     = new Bet
                {
                    DateTime = insertedBet.Created,
                    Items    = itemModels,
                    User     = new User
                    {
                        Name     = user.Name,
                        ImageUrl = user.ImageUrl,
                        SteamId  = user.SteamId
                    },
                }
            };

            await _matchHub.UserBetsOnMatch(model);
        }
        public async void InsertBetSuccess()
        {
            var bet = new DatabaseModel.Bet(_setup.User1.Id, _setup.Match1.Id, _setup.GameMode.Id, DateTime.Now);

            var betRepo = new BetRepoService(_fakedFactory, new BetQueries());
            var res     = await betRepo.InsertAsync(bet);

            Assert.True(res.Id > 0);
        }
        public async Task <List <DatabaseModel.ItemBetted> > FindAsync(DatabaseModel.Bet bet)
        {
            var query = _itemBetQueries.GetItemBetsOnBet(bet.Id);

            using (var sqlResult = await _databaseConnection.ExecuteSqlQueryAsync(query))
            {
                return(await sqlResult.GetListAsync <DatabaseModel.ItemBetted>());
            }
        }
        public async void GetBetForSpecificGameModeIdMultipleSuccess()
        {
            var bet1 = new DatabaseModel.Bet(_setup.User4.Id, _setup.Match1.Id, _setup.GameMode.Id, DateTime.Now);
            var bet2 = new DatabaseModel.Bet(_setup.User4.Id, _setup.Match2.Id, _setup.GameMode.Id, DateTime.Now);
            var bet3 = new DatabaseModel.Bet(_setup.User4.Id, _setup.Match3.Id, _setup.GameMode.Id, DateTime.Now);
            var bet4 = new DatabaseModel.Bet(_setup.User1.Id, _setup.Match3.Id, _setup.GameMode.Id, DateTime.Now);
            var bet5 = new DatabaseModel.Bet(_setup.User4.Id, _setup.CoinFlip1.Id, _setup.GameMode1.Id, DateTime.Now);
            var bet6 = new DatabaseModel.Bet(_setup.User4.Id, _setup.CoinFlip2.Id, _setup.GameMode1.Id, DateTime.Now);
            var bet7 = new DatabaseModel.Bet(_setup.User1.Id, _setup.CoinFlip3.Id, _setup.GameMode1.Id, DateTime.Now);
            var bet8 = new DatabaseModel.Bet(_setup.User4.Id, _setup.CoinFlip3.Id, _setup.GameMode1.Id, DateTime.Now);

            var betRepo = new BetRepoService(_fakedFactory, new BetQueries());

            await betRepo.InsertAsync(bet1);

            await betRepo.InsertAsync(bet2);

            await betRepo.InsertAsync(bet3);

            await betRepo.InsertAsync(bet4);

            await betRepo.InsertAsync(bet5);

            await betRepo.InsertAsync(bet6);

            await betRepo.InsertAsync(bet7);

            await betRepo.InsertAsync(bet8);

            var res = await betRepo.FindAsync(new List <LookUpGameModeBet>
            {
                new LookUpGameModeBet
                {
                    GameMode = _setup.GameMode1,
                    MatchIds = new List <int>
                    {
                        _setup.CoinFlip1.Id,
                        _setup.CoinFlip2.Id,
                        _setup.CoinFlip3.Id
                    },
                    User = _setup.User4
                },
                new LookUpGameModeBet
                {
                    GameMode = _setup.GameMode,
                    MatchIds = new List <int>
                    {
                        _setup.Match1.Id,
                        _setup.Match3.Id,
                    },
                    User = _setup.User4
                }
            });

            Assert.Equal(5, res.Count);
        }
        public async void InsertSameBetThrows()
        {
            var bet = new DatabaseModel.Bet(_setup.User2.Id, _setup.Match1.Id, _setup.GameMode.Id, DateTime.Now);

            var betRepo = new BetRepoService(_fakedFactory, new BetQueries());
            await betRepo.InsertAsync(bet);

            var exception1 = await Record.ExceptionAsync(async() => { await betRepo.InsertAsync(bet); });

            Assert.IsType(typeof(SqlException), exception1);
        }
        public async void GetBetForMatchIdAndUserId()
        {
            var user  = _setup.User1;
            var match = _setup.Match2;
            var bet   = new DatabaseModel.Bet(user.Id, match.Id, _setup.GameMode.Id, DateTime.Now);

            var betRepo = new BetRepoService(_fakedFactory, new BetQueries());
            await betRepo.InsertAsync(bet);

            var betResponse = await betRepo.FindAsync(match, user);

            Assert.Equal(user.Id, betResponse.UserId);
            Assert.Equal(match.Id, betResponse.MatchId);
        }
Exemple #8
0
        public SqlQuery InsertReturnsId(DatabaseModel.Bet bet)
        {
            var dict = new Dictionary <string, object>
            {
                { "@userId", bet.UserId },
                { "@matchId", bet.MatchId },
                { "@created", bet.Created },
                { "@gameModeId", bet.GameModeId },
            };

            return(new SqlQuery(
                       "INSERT INTO [Bet] (UserId, MatchId, Created, GameModeId) OUTPUT INSERTED.Id VALUES (@userId, @matchId, @created,@gameModeId);",
                       dict));
        }
        public async Task <DatabaseModel.Bet> InsertAsync(DatabaseModel.Bet bet, ITransactionWrapper transactionWrapper = null)
        {
            var query = _betQueries.InsertReturnsId(bet);

            if (transactionWrapper != null)
            {
                var idFromTrans = await transactionWrapper.ExecuteSqlCommand <int>(query);

                return(new DatabaseModel.Bet(bet.UserId, bet.MatchId, bet.GameModeId, bet.Created, idFromTrans));
            }

            var id = (int)await _databaseConnection.ExecuteScalarAsync(query);

            return(new DatabaseModel.Bet(bet.UserId, bet.MatchId, bet.GameModeId, bet.Created, id));
        }
Exemple #10
0
        private async Task InsertBetWithTransaction
        (
            DatabaseModel.User user,
            int matchId,
            List <DatabaseModel.Item> items,
            DatabaseModel.GameMode gameMode,
            List <DatabaseModel.ItemDescription> itemDescriptions
        )
        {
            List <DatabaseModel.ItemBetted> itemBets;

            DatabaseModel.Bet insertedBet;
            List <Item>       itemModels;

            using (var transaction = _transactionFactory.BeginTransaction())
            {
                try
                {
                    var bet = new DatabaseModel.Bet(user.Id, matchId, gameMode.Id, DateTime.Now);
                    insertedBet = await _betRepoService.InsertAsync(bet, transaction);

                    itemBets = CreateItemBets(insertedBet.Id, itemDescriptions, items, out itemModels);

                    await _itemBettedRepoService.InsertAsync(itemBets, transaction);

                    transaction.Commit();
                }
                catch (SqlException e)
                {
                    throw new InvalidBetException("Can't inset bet due to sql error", e);
                }
            }

            if (gameMode.Type == GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo))
            {
                await SendWebsocketMatchEvent(user, matchId, itemModels, insertedBet);
            }
        }
Exemple #11
0
 public SqlQuery Insert(DatabaseModel.Bet bet)
 {
     return(InsertRange(new List <DatabaseModel.Bet> {
         bet
     }));
 }