public async Task InitTest()
        {
            var itemDesc1 = new DatabaseModel.ItemDescription("item1", new decimal(10.20), "730", "2", "imageUrl", true);
            var itemDesc2 = new DatabaseModel.ItemDescription("item2", new decimal(11.40), "730", "2", "imageUrl", true);

            ItemDescription1 = await new ItemDescriptionRepoService(DatabaseConnectionFactory, new ItemDescriptionQueries()).InsertAsync(itemDesc1);
            ItemDescription2 = await new ItemDescriptionRepoService(DatabaseConnectionFactory, new ItemDescriptionQueries()).InsertAsync(itemDesc2);

            var gameMode  = new DatabaseModel.GameMode("Jackpot", 1);
            var gameMode2 = new DatabaseModel.GameMode("Jackpot1", 2);
            var gameMode3 = new DatabaseModel.GameMode("Jackpot2", 3);
            var gameMode4 = new DatabaseModel.GameMode("Jackpot3", 4);

            GameMode  = await new GameModeRepoService(DatabaseConnectionFactory).Insert(gameMode);
            GameMode2 = await new GameModeRepoService(DatabaseConnectionFactory).Insert(gameMode2);
            GameMode3 = await new GameModeRepoService(DatabaseConnectionFactory).Insert(gameMode3);
            GameMode4 = await new GameModeRepoService(DatabaseConnectionFactory).Insert(gameMode4);

            var bot = new DatabaseModel.Bot(",anotherBot", "Bot 2");

            Bot1 = await new BotRepoService(DatabaseConnectionFactory, new BotQueries()).InsertAsync(bot);
            var match = new DatabaseModel.Match(1, "salt", "hash", 55.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, GameMode.Id,
                                                DateTime.Now);

            Match1 = await new MatchRepoService(DatabaseConnectionFactory, new MatchQueries()).InsertAsync(match);
            var match1 = new DatabaseModel.Match(2, "salt", "hash", 55.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, GameMode.Id,
                                                 DateTime.Now);

            Match2 = await new MatchRepoService(DatabaseConnectionFactory, new MatchQueries()).InsertAsync(match1);
        }
Пример #2
0
        public async void InsertPercentageSuccess()
        {
            var match = new DatabaseModel.Match(300, "hash", "salt", 42.31767743933838.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                _setup.GameMode.Id, DateTime.Now);
            var match1 = new DatabaseModel.Match(301, "hash", "salt", 99.0.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId, _setup.GameMode.Id,
                                                 DateTime.Now);
            var match2 = new DatabaseModel.Match(302, "hash", "salt", 98.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId, _setup.GameMode.Id,
                                                 DateTime.Now);
            var match3 = new DatabaseModel.Match(303, "hash", "salt", 1.0000001.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId, _setup.GameMode.Id,
                                                 DateTime.Now);
            var match4 = new DatabaseModel.Match(304, "hash", "salt", 58.448484131151515145.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                 _setup.GameMode.Id, DateTime.Now);
            var match5 = new DatabaseModel.Match(305, "hash", "salt", 54.1215110.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId, _setup.GameMode.Id,
                                                 DateTime.Now);
            await _matchRepoService.InsertAsync(match);

            await _matchRepoService.InsertAsync(match1);

            await _matchRepoService.InsertAsync(match2);

            await _matchRepoService.InsertAsync(match3);

            await _matchRepoService.InsertAsync(match4);

            await _matchRepoService.InsertAsync(match5);

            Assert.Equal(42.31767743933838.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(300)).Percentage);
            Assert.Equal(99.0.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(301)).Percentage);
            Assert.Equal(98.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(302)).Percentage);
            Assert.Equal(1.0000001.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(303)).Percentage);
            Assert.Equal(58.448484131151515145.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(304)).Percentage);
            Assert.Equal(54.1215110.ToString(CultureInfo.InvariantCulture), (await _matchRepoService.FindAsync(305)).Percentage);
        }
Пример #3
0
        private async Task DraftWinner(DatabaseModel.Match match)
        {
            var betsOnMatch = await _repoServiceFactory.BetRepoService.FindAsync(match);

            var itemBetsOnMatch = await _repoServiceFactory.ItemBettedRepoService.FindAsync(betsOnMatch);

            var percentage  = Convert.ToDouble(match.Percentage, CultureInfo.InvariantCulture);
            var winningBet  = _draftService.GetWinningBet(percentage, betsOnMatch, itemBetsOnMatch);
            var winningUser = await _repoServiceFactory.UserRepoService.FindAsync(winningBet.Bet.UserId);

            await _repoServiceFactory.MatchRepoService.AddWinnerToMatch(winningUser, match.RoundId);

            var sum = itemBetsOnMatch.Sum(itemBet => itemBet.Value);
            await _matchHubConnections.Winner(new JackpotWinnerSelected
            {
                ImageUrl         = winningUser.ImageUrl,
                Name             = winningUser.Name,
                SteamId          = winningUser.SteamId,
                Percentage       = match.Percentage,
                PotValue         = sum,
                Quote            = winningUser.Quote,
                RoundId          = match.RoundId,
                DraftingGraph    = _currentMatchSettings.DraftingGraph,
                DraftingTimeInMs = _currentMatchSettings.DraftingTimeInMilliSec
            });

            await _draftService.ChangeOwnerOfItems(betsOnMatch, itemBetsOnMatch, winningUser, match.Id, _currentMatchSettings.Rake, _gameMode.Id);

            _discordService.JackpotWinnerAsync(match.RoundId, sum);
        }
Пример #4
0
        protected async Task <JackpotMatchHistoryBasic> GetHistoryBasic(DatabaseModel.Match match)
        {
            if (!match.WinnerId.HasValue)
            {
                throw new Exception("We have no winner for this match");
            }

            var winningUser = await _repoServiceFactory.UserRepoService.FindAsync(match.WinnerId.Value);

            var matchHistory =
                new JackpotMatchHistoryBasic
            {
                Created           = match.Created,
                Hash              = match.Hash,
                Percentage        = match.Percentage,
                RoundId           = match.RoundId,
                Salt              = match.Salt,
                UserWinnerImgUrl  = winningUser.ImageUrl,
                UserWinnerName    = winningUser.Name,
                UserWinnerQuote   = winningUser.Quote,
                UserWinnerSteamId = winningUser.SteamId
            };

            return(matchHistory);
        }
Пример #5
0
        public async void GetAvalibeItemsWhenUserHasActiveOfferTransactionAndActiveBetSuccess()
        {
            var user = new DatabaseModel.User("steamId", "name", "imageUrl", "tradelink", DateTime.Now, DateTime.Now, false, null, 10);

            //setup items
            A.CallTo(() => _itemRepoService.FindAsync(A <DatabaseModel.User> ._)).Returns(new List <DatabaseModel.Item>
            {
                new DatabaseModel.Item("assetId1", 1, -1, 10, DateTimeOffset.Now, 10),
                new DatabaseModel.Item("assetId2", 1, -1, 10, DateTimeOffset.Now, 11),
                new DatabaseModel.Item("assetId3", 2, -1, 10, DateTimeOffset.Now, 12),
                new DatabaseModel.Item("assetId4", 3, -1, 10, DateTimeOffset.Now, 13),
                new DatabaseModel.Item("assetId5", 3, -1, 10, DateTimeOffset.Now, 14),
                new DatabaseModel.Item("assetId6", 3, -1, 10, DateTimeOffset.Now, 15)
            });
            A.CallTo(() => _descriptionRepoService.FindAsync(A <List <int> > ._)).Returns(new List <DatabaseModel.ItemDescription>
            {
                new DatabaseModel.ItemDescription("itemDesc1", 1, "730", "2", "img1", true, 1),
                new DatabaseModel.ItemDescription("itemDesc2", 1, "730", "2", "img1", true, 2),
                new DatabaseModel.ItemDescription("itemDesc3", 1, "730", "2", "img1", true, 3)
            });

            //setup active bet
            var match = new DatabaseModel.Match(1, "salt", "hash", 14.4.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1, DateTime.Now, 1);
            var bets  = new List <DatabaseModel.Bet> {
                new DatabaseModel.Bet(10, 1, 1, DateTime.Now, 11)
            };

            A.CallTo(() => _matchRepoService.GetCurrentMatch()).Returns(match);
            A.CallTo(() => _betRepoService.FindAsync(A <List <LookUpGameModeBet> > ._)).Returns(bets);
            A.CallTo(() => _itemBettedRepoSerivce.FindAsync(A <List <DatabaseModel.Bet> > ._)).Returns(new List <DatabaseModel.ItemBetted>
            {
                new DatabaseModel.ItemBetted(bets[0].Id, 1, "assetId1", 1),
                new DatabaseModel.ItemBetted(bets[0].Id, 3, "assetId4", 1),
            });
            //setup active offer
            A.CallTo(() => _offerTransactionRepoService.FindActiveAsync(A <DatabaseModel.User> ._)).Returns(new List <DatabaseModel.OfferTransaction>
            {
                new DatabaseModel.OfferTransaction(10, 1, new decimal(15), false, "someSteamId", null, 5)
            });
            var itemsInActiveOffer = new List <DatabaseModel.ItemInOfferTransaction>
            {
                new DatabaseModel.ItemInOfferTransaction(5, 1, "assetId2", new decimal(1)),
                new DatabaseModel.ItemInOfferTransaction(5, 2, "assetId3", new decimal(1)),
            };

            A.CallTo(() => _itemsInOfferTransactionRepoService.FindAsync(A <List <DatabaseModel.OfferTransaction> > .That.Matches(
                                                                             list => list.Count == 1 && list[0].Id == 5)))
            .Returns(itemsInActiveOffer);

            var itemService = new ItemService(_fakedRepoService);

            var avalibleItemsForUser = await itemService.GetAvalibleItemsForUser(user);


            Assert.Equal(2, avalibleItemsForUser.Count);

            Assert.Equal("itemDesc3", avalibleItemsForUser.Single(item => item.AssetId == "assetId5").Name);
            Assert.Equal("itemDesc3", avalibleItemsForUser.Single(item => item.AssetId == "assetId6").Name);
        }
Пример #6
0
        public async Task <List <DatabaseModel.Bet> > FindAsync(DatabaseModel.Match match)
        {
            var query = _betQueries.GetAllBetsForMatch(match.Id, match.GameModeId);

            using (var sqlResult = await _databaseConnection.ExecuteSqlQueryAsync(query))
            {
                return(await sqlResult.GetListAsync <DatabaseModel.Bet>());
            }
        }
Пример #7
0
        public async Task <DatabaseModel.Bet> FindAsync(DatabaseModel.Match match, DatabaseModel.User user)
        {
            var query = _betQueries.GetBet(match.Id, user.Id, match.GameModeId);

            using (var sqlResult = await _databaseConnection.ExecuteSqlQueryAsync(query))
            {
                return(await sqlResult.GetSingleAsync <DatabaseModel.Bet>());
            }
        }
Пример #8
0
        public async void CreateNewMatchSuccess()
        {
            var matchInsert =
                new DatabaseModel.Match(1, "salt", "hash", "10", 1, null, null, 1, 1, DateTime.Now);
            var matchReturn = new DatabaseModel.Match(1, "salt", "hash", 10.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1,
                                                      default(DateTime), 1);

            A.CallTo(() => _fakeMatchRepoServicey.InsertAsync(
                         A <DatabaseModel.Match> .That.Matches(m =>
                                                               m.Hash == matchInsert.Hash &&
                                                               m.Salt == matchInsert.Salt &&
                                                               m.Percentage == matchInsert.Percentage &&
                                                               m.RoundId == matchInsert.RoundId &&
                                                               m.Status == matchInsert.Status
                                                               )
                         )).Returns(matchReturn);

            A.CallTo(() => _fakeHashService.CreateBase64Sha512Hash(A <string> ._, A <string> ._)).Returns("hash");
            A.CallTo(() => _fakeRandomService.GeneratePercentage()).Returns("10");
            A.CallTo(() => _fakeRandomService.GenerateSalt()).Returns("salt");

            A.CallTo(() => _fakedGameModeSettingService.GetSettingForType(GameModeType.JackpotCsgo))
            .Returns(new DatabaseModel.JackpotSetting(0, 0, 0, 0, 0, 0, 0, 0, true, false, ""));
            A.CallTo(() => _fakedGameModeSettingService.Find(A <int> ._, A <GameModeType> ._))
            .Returns(new DatabaseModel.JackpotSetting(0, 0, 0, 0, 0, 0, 0, 0, true, false, ""));

            var jackpotMatchManager = new JackpotMatchManager(
                _fakedRepoServiceFactory,
                _fakeBetService,
                _fakeHashService,
                _fakeRandomService,
                A.Dummy <IJackpotDraftService>(),
                A.Dummy <ILogServiceFactory>(),
                A.Dummy <IBetOrWithdrawQueueManager>(),
                _fakedGameModeSettingService,
                _fakedBetHub,
                _fakedMatchHub,
                A.Dummy <IDiscordService>()
                );
            var match = await jackpotMatchManager.CreateNewMatchAsync(1);


            A.CallTo(() => _fakeMatchRepoServicey.InsertAsync(
                         A <DatabaseModel.Match> .That.Matches(m =>
                                                               m.Hash == matchInsert.Hash &&
                                                               m.Salt == matchInsert.Salt &&
                                                               m.Percentage == matchInsert.Percentage &&
                                                               m.RoundId == matchInsert.RoundId &&
                                                               m.Status == matchInsert.Status
                                                               ))).MustHaveHappened();
            A.CallTo(() => _fakeHashService.CreateBase64Sha512Hash(A <string> ._, A <string> ._)).MustHaveHappened();
            A.CallTo(() => _fakeRandomService.GeneratePercentage()).MustHaveHappened();
            A.CallTo(() => _fakeRandomService.GenerateSalt()).MustHaveHappened();
            Assert.Equal(1, match.Id);
        }
Пример #9
0
 private bool ShouldStartTimmer(List <DatabaseModel.Bet> betsOnMatch, DatabaseModel.Match match)
 {
     if (betsOnMatch.Count > 1 && match.TimerStarted == null)
     {
         if (betsOnMatch.Count > 0 && match.TimerStarted == null)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #10
0
 public async Task PlaceBetOnJackpotMatch
 (
     DatabaseModel.Match match,
     JackpotMatchSetting setting,
     DatabaseModel.GameMode gameMode,
     List <AssetAndDescriptionId> assetAndDescriptionIds,
     string userSteamId
 )
 {
     await PlaceBetOnMatch(match.Id, setting, gameMode, assetAndDescriptionIds, userSteamId);
 }
Пример #11
0
        public async void CloseMatchSuccess()
        {
            var match = new DatabaseModel.Match(246, "salt", "hash", 42.31767743933838.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                _setup.GameMode.Id, DateTime.Today);
            await _matchRepoService.InsertAsync(match);

            await _matchRepoService.CloseMatch(match.RoundId);

            var selectRes2 = await _matchRepoService.FindAsync(match.RoundId);

            Assert.Equal(246, selectRes2.RoundId);
            Assert.Equal(0, selectRes2.Status);
        }
Пример #12
0
        public async Task <DatabaseModel.Match> InsertAsync(DatabaseModel.Match match)
        {
            if (match.SettingId <= 0)
            {
                throw new ArgumentOutOfRangeException("The settingId on a match must be grater than 0");
            }
            using (var cn = _databaseConnection.GetNewOpenConnection())
            {
                await cn.InsertAsync(match);

                cn.Close();
                return(match);
            }
        }
Пример #13
0
        public async Task <List <DatabaseModel.RakeItem> > FindAsync(DatabaseModel.Match match)
        {
            if (match == null)
            {
                return(new List <DatabaseModel.RakeItem>());
            }

            var query = _rakeItemQueries.GetFromMatchId(match.Id);

            using (var sqlResult = await _databaseConnection.ExecuteSqlQueryAsync(query))
            {
                return(await sqlResult.GetListAsync <DatabaseModel.RakeItem>());
            }
        }
Пример #14
0
        public async void MatchIsClosedSaltAndPercentageIsValidSuccess()
        {
            var matchToReturn = new DatabaseModel.Match(1, "salt", "hash", 10.ToString(CultureInfo.InvariantCulture), 0, null, null, 1, 1,
                                                        DateTime.Now, 1);

            A.CallTo(() => _fakeMatchRepoServicey.GetCurrentMatch()).Returns(matchToReturn);

            A.CallTo(() => _fakedGameModeSettingService.Find(A <int> ._, A <GameModeType> ._))
            .Returns(new DatabaseModel.JackpotSetting(0, 0, 0, 0, 0, 0, 0, 0, true, false, ""));

            A.CallTo(() => _fakeBetService.GetBettedItemsOnMatch(1, matchToReturn.GameModeId)).Returns(new List <Item>
            {
                new Item
                {
                    IconUrl = "imageUrl",
                    Name    = "name1",
                    Value   = 10,
                    Owner   = new User
                    {
                        ImageUrl = "userImage",
                        Name     = "userName",
                        SteamId  = "123456789"
                    }
                }
            });

            var jackpotMatchManager = new JackpotMatchManager(
                _fakedRepoServiceFactory,
                _fakeBetService,
                _fakeHashService,
                _fakeRandomService,
                A.Dummy <IJackpotDraftService>(),
                A.Dummy <ILogServiceFactory>(),
                A.Dummy <IBetOrWithdrawQueueManager>(),
                _fakedGameModeSettingService,
                _fakedBetHub,
                _fakedMatchHub,
                A.Dummy <IDiscordService>()
                );
            var currentJackpotMatch = await jackpotMatchManager.GetCurrentMatch();


            Assert.Equal("hash", currentJackpotMatch.Hash);
            Assert.Equal("salt", currentJackpotMatch.Salt);
            Assert.Equal(10.ToString(CultureInfo.InvariantCulture), currentJackpotMatch.Percentage);
            Assert.Equal(MatchStatus.Closed, currentJackpotMatch.Status);
            Assert.Equal("closed", currentJackpotMatch.ReadableStatus.ToLower());
        }
Пример #15
0
        public async void UpdateTimerOnMatch()
        {
            var match = new DatabaseModel.Match(245, "salt", "hash", 42.31767743933838.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                _setup.GameMode.Id, DateTime.Today);
            await _matchRepoService.InsertAsync(match);

            var selectRes1 = await _matchRepoService.FindAsync(match.RoundId);

            Assert.Null(selectRes1.TimerStarted);

            await _matchRepoService.StartTimerForMatch(match.RoundId, DateTime.Today);

            var selectRes2 = await _matchRepoService.FindAsync(match.RoundId);

            Assert.Equal(245, selectRes2.RoundId);
            Assert.Equal(DateTime.Today, selectRes2.TimerStarted);
        }
Пример #16
0
        public async void AddWinnerToMatch()
        {
            var winner = await _userRepoService.InsertAsync("randomSteamId1", "randomName", "imgUr,");

            var match = new DatabaseModel.Match(178, "salt", "hash", 42.31767743933838.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                _setup.GameMode.Id, DateTime.Today);

            await _matchRepoService.InsertAsync(match);

            await _matchRepoService.CloseMatch(match.RoundId);

            await _matchRepoService.AddWinnerToMatch(winner, match.RoundId);

            var selectRes2 = await _matchRepoService.FindAsync(match.RoundId);

            Assert.Equal(178, selectRes2.RoundId);
            Assert.Equal(0, selectRes2.Status);
            Assert.Equal(winner.Id, selectRes2.WinnerId);
        }
Пример #17
0
        public async void MatchInsertThenGetThatMatchSuccess()
        {
            var match = new DatabaseModel.Match(1, "salt", "hash", 42.31767743933838.ToString(CultureInfo.InvariantCulture), 1, null, null, _setup.GameMode.CurrentSettingId,
                                                _setup.GameMode.Id, DateTime.Today);

            var returnMatch = await _matchRepoService.InsertAsync(match);

            Assert.True(returnMatch.Id > 0);


            var selectRes = await _matchRepoService.FindAsync(1);

            Assert.Equal(1, selectRes.RoundId);
            Assert.Equal(42.31767743933838.ToString(CultureInfo.InvariantCulture), selectRes.Percentage);
            Assert.Equal("hash", selectRes.Hash);
            Assert.Equal("salt", selectRes.Salt);
            Assert.Equal(DateTime.Today, selectRes.Created);
            Assert.Null(selectRes.TimerStarted);
        }
Пример #18
0
        public async void GetEmptyMatchSuccess()
        {
            var matchToReturn = new DatabaseModel.Match(1, "salt", "hash", 10.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1,
                                                        DateTime.Now, 1);

            A.CallTo(() => _fakeMatchRepoServicey.GetCurrentMatch()).Returns(matchToReturn);
            A.CallTo(() => _fakedGameModeSettingService.Find(A <int> ._, A <GameModeType> ._))
            .Returns(new DatabaseModel.JackpotSetting(0, 10000, 0, 0, 0, 0, 0, 0, true, false, ""));
            A.CallTo(() => _fakeBetService.GetBettedItemsOnMatch(1, matchToReturn.GameModeId)).Returns(new List <Item>());

            var jackpotMatchManager = new JackpotMatchManager(
                _fakedRepoServiceFactory,
                _fakeBetService,
                _fakeHashService,
                _fakeRandomService,
                A.Dummy <IJackpotDraftService>(),
                A.Dummy <ILogServiceFactory>(),
                A.Dummy <IBetOrWithdrawQueueManager>(),
                _fakedGameModeSettingService,
                _fakedBetHub,
                _fakedMatchHub,
                A.Dummy <IDiscordService>()
                );
            var currentJackpotMatch = await jackpotMatchManager.GetCurrentMatch();


            Assert.Equal("hash", currentJackpotMatch.Hash);
            Assert.Equal(null, currentJackpotMatch.Salt);
            Assert.Equal(null, currentJackpotMatch.Percentage);
            Assert.Equal(1.ToString(), currentJackpotMatch.RoundId);
            Assert.Equal(MatchStatus.Open, currentJackpotMatch.Status);
            Assert.Equal("open", currentJackpotMatch.ReadableStatus.ToLower());
            Assert.Equal(0, currentJackpotMatch.ItemsInPool.Count);
            Assert.Equal(0, currentJackpotMatch.ValueInPool);
            Assert.Equal(0, currentJackpotMatch.Bets.Count);
            Assert.Equal(10000, currentJackpotMatch.TimeLeft);

            A.CallTo(() => _fakedGameModeSettingService.Find(1, GameModeType.JackpotCsgo)).MustHaveHappened();
        }
Пример #19
0
        protected async Task <DatabaseModel.Match> CreateNewMatchAsync(int roundId, DatabaseModel.GameMode currentGameMode)
        {
            var percentage = _randomService.GeneratePercentage();
            var salt       = _randomService.GenerateSalt();
            var hash       = _hashService.CreateBase64Sha512Hash(percentage, salt);
            var status     = MatchStatusHelper.GetIntFromMatchStatus(MatchStatus.Open);

            var match = new DatabaseModel.Match
                        (
                roundId,
                salt,
                hash,
                percentage,
                status,
                null,
                null,
                currentGameMode.CurrentSettingId,
                currentGameMode.Id,
                DateTime.Now
                        );

            return(await _matchRepoService.InsertAsync(match));
        }
Пример #20
0
        private bool ShouldCloseMatch(DatabaseModel.Match match, List <DatabaseModel.ItemBetted> itemBets, int currentBetCount)
        {
            if (MatchStatusHelper.GetMatchStatusFromInt(match.Status) == MatchStatus.Closed)
            {
                return(true);
            }

            var itemLimit = _currentMatchSettings.ItemsLimit;

            if (itemBets.Count + currentBetCount >= itemLimit && itemBets.Select(i => i.BetId).Distinct().Count() > 1)
            {
                return(true);
            }

            var jackPotTimespan = (TimeSpan.FromMilliseconds(_currentMatchSettings.TimmerInMilliSec));

            if (match.TimerStarted.HasValue && (DateTime.Now - (match.TimerStarted.Value + jackPotTimespan)).TotalMilliseconds > 0)
            {
                return(true);
            }

            return(false);
        }
Пример #21
0
        public async void GetAvalibeItemsSuccess()
        {
            var user = new DatabaseModel.User("steamId", "name", "imageUrl", "tradelink", DateTime.Now, DateTime.Now, false);

            var match = new DatabaseModel.Match(1, "salt", "hash", 14.4.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1, DateTime.Now, 1);

            A.CallTo(() => _matchRepoService.GetCurrentMatch()).Returns(match);
            A.CallTo(() => _betRepoService.FindAsync(A <DatabaseModel.Match> ._)).Returns(new List <DatabaseModel.Bet>());
            A.CallTo(() => _offerTransactionRepoService.FindActiveAsync(A <DatabaseModel.User> ._)).Returns(new List <DatabaseModel.OfferTransaction>());

            A.CallTo(() => _itemRepoService.FindAsync(A <DatabaseModel.User> ._)).Returns(new List <DatabaseModel.Item>
            {
                new DatabaseModel.Item("assetId1", 1, -1, -1, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId2", 1, -1, -1, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId3", 2, -1, -1, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId4", 3, -1, -1, DateTimeOffset.Now)
            });
            A.CallTo(() => _descriptionRepoService.FindAsync(A <List <int> > ._)).Returns(new List <DatabaseModel.ItemDescription>
            {
                new DatabaseModel.ItemDescription("itemDesc1", 1, "730", "2", "img1", true, 1),
                new DatabaseModel.ItemDescription("itemDesc2", 1, "730", "2", "img1", true, 2),
                new DatabaseModel.ItemDescription("itemDesc3", 1, "730", "2", "img1", true, 3)
            });

            var itemService = new ItemService(_fakedRepoService);

            var avalibleItemsForUser = await itemService.GetAvalibleItemsForUser(user);


            Assert.Equal(4, avalibleItemsForUser.Count);

            Assert.Equal("itemDesc1", avalibleItemsForUser.Single(item => item.AssetId == "assetId1").Name);
            Assert.Equal("itemDesc1", avalibleItemsForUser.Single(item => item.AssetId == "assetId2").Name);
            Assert.Equal("itemDesc2", avalibleItemsForUser.Single(item => item.AssetId == "assetId3").Name);
            Assert.Equal("itemDesc3", avalibleItemsForUser.Single(item => item.AssetId == "assetId4").Name);
        }
Пример #22
0
        public async void TestForBetsJackpotAndOnCoinFlip()
        {
            var user = new DatabaseModel.User("steamId", "name", "imageUrl", "tradelink", DateTime.Now, DateTime.Now, false, null, 9);

            A.CallTo(() => _itemRepoService.FindAsync(A <DatabaseModel.User> ._)).Returns(new List <DatabaseModel.Item>
            {
                new DatabaseModel.Item("assetId1", 1, -1, 9, DateTimeOffset.Now, 10),
                new DatabaseModel.Item("assetId2", 1, -1, 9, DateTimeOffset.Now, 11),
                new DatabaseModel.Item("assetId3", 2, -1, 9, DateTimeOffset.Now, 12),
                new DatabaseModel.Item("assetId4", 3, -1, 9, DateTimeOffset.Now, 13),
                new DatabaseModel.Item("assetId5", 3, -1, 9, DateTimeOffset.Now, 13),
                new DatabaseModel.Item("assetId6", 3, -1, 9, DateTimeOffset.Now, 13),
            });
            A.CallTo(() => _descriptionRepoService.FindAsync(A <List <int> > ._)).Returns(new List <DatabaseModel.ItemDescription>
            {
                new DatabaseModel.ItemDescription("itemDesc1", 1, "730", "2", "img1", true, 1),
                new DatabaseModel.ItemDescription("itemDesc2", 1, "730", "2", "img1", true, 2),
                new DatabaseModel.ItemDescription("itemDesc3", 1, "730", "2", "img1", true, 3)
            });

            var match = new DatabaseModel.Match(1, "salt", "hash", 14.4.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, 1, DateTime.Now, 1);
            var bets  = new List <DatabaseModel.Bet>
            {
                new DatabaseModel.Bet(10, 1, 1, DateTime.Now, 11),
                new DatabaseModel.Bet(9, 1, 2, DateTime.Now, 11)
            };

            A.CallTo(() => _itemBettedRepoSerivce.FindAsync(A <List <DatabaseModel.Bet> > ._)).Returns(new List <DatabaseModel.ItemBetted>
            {
                new DatabaseModel.ItemBetted(bets[0].Id, 1, "assetId1", 1),
                new DatabaseModel.ItemBetted(bets[0].Id, 3, "assetId4", 1),
            });

            A.CallTo(() => _matchRepoService.GetCurrentMatch()).Returns(match);
            A.CallTo(() => _betRepoService.FindAsync(A <List <LookUpGameModeBet> > ._)).Returns(bets);
            A.CallTo(() => _fakedCoinFlipService.FindAllNotClosedMatches()).Returns(new List <DatabaseModel.CoinFlip>
            {
                new DatabaseModel.CoinFlip
                {
                    Created       = DateTime.Today,
                    CreatorIsHead = false,
                    CreatorUserId = 9,
                    GameModeId    = 1,
                    Hash          = "hash",
                    Salt          = "salt",
                    Id            = 1,
                    Percentage    = "",
                    RoundId       = "",
                    SettingId     = 0,
                    Status        = 1,
                    TimerStarted  = null,
                    WinnerId      = null
                },
                new DatabaseModel.CoinFlip
                {
                    Created       = DateTime.Today,
                    CreatorIsHead = false,
                    CreatorUserId = 10,
                    GameModeId    = 1,
                    Hash          = "hash",
                    Salt          = "salt",
                    Id            = 1,
                    Percentage    = "",
                    RoundId       = "",
                    SettingId     = 0,
                    Status        = 1,
                    TimerStarted  = null,
                    WinnerId      = null
                }
            });

            var itemService = new ItemService(_fakedRepoService);

            var avalibleItemsForUser = await itemService.GetAvalibleItemsForUser(user);

            A.CallTo(() => _fakedCoinFlipService.FindAllNotClosedMatches()).MustHaveHappened();

            Assert.Equal(4, avalibleItemsForUser.Count);
            Assert.Equal("itemDesc3", avalibleItemsForUser.Single(item => item.AssetId == "assetId5").Name);
            Assert.Equal("itemDesc3", avalibleItemsForUser.Single(item => item.AssetId == "assetId6").Name);
            Assert.Equal("itemDesc2", avalibleItemsForUser.Single(item => item.AssetId == "assetId3").Name);
            Assert.Equal("itemDesc1", avalibleItemsForUser.Single(item => item.AssetId == "assetId2").Name);
        }
Пример #23
0
        private async Task <JackpotMatch> GetMatch(DatabaseModel.JackpotSetting settings, DatabaseModel.Match match, DatabaseModel.GameMode gameMode)
        {
            var items = await _betService.GetBettedItemsOnMatch(match.Id, gameMode.Id) ?? new List <Item>();

            return(new JackpotMatch(
                       match.RoundId.ToString(),
                       match.Hash,
                       match.Salt,
                       match.Percentage,
                       MatchStatusHelper.GetMatchStatusFromInt(match.Status),
                       await GetBets(items, match.Id, gameMode),
                       match.TimerStarted,
                       settings.ToJackpotMatchSetting()
                       ));
        }
Пример #24
0
 public async void InsertMatchWithNoSettingIdThrows()
 {
     var match = new DatabaseModel.Match(310, "hash", "salt", 54.1215110.ToString(CultureInfo.InvariantCulture), 1, null, null, 0, _setup.GameMode.Id, DateTime.Now);
     await Assert.ThrowsAsync <ArgumentOutOfRangeException>(async() => await _matchRepoService.InsertAsync(match));
 }