Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public async Task <List <Item> > GetAvalibleItemsForUser(DatabaseModel.User user)
        {
            var jackpotGameModeTask  = _gameModeRepoService.Find(GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo));
            var coinFlipGameModeTask = _gameModeRepoService.Find(GameModeHelper.GetStringFromType(GameModeType.CoinFlip));

            var currentMatchTask             = _matchRepoService.GetCurrentMatch();
            var notClosedCoinFlipmatchesTask = _coinFlipMatchRepoService.FindAllNotClosedMatches();

            await Task.WhenAll(jackpotGameModeTask, coinFlipGameModeTask, currentMatchTask, notClosedCoinFlipmatchesTask);

            var coinFlipGameMode         = coinFlipGameModeTask.Result;
            var currentMatch             = currentMatchTask.Result;
            var jackpotGameMode          = jackpotGameModeTask.Result;
            var notClosedCoinFlipmatches = notClosedCoinFlipmatchesTask.Result;

            var coinflipLookUpGameModeBet = new LookUpGameModeBet
            {
                GameMode = coinFlipGameMode,
                User     = user,
                MatchIds = notClosedCoinFlipmatches.Select(coin => coin.Id).ToList()
            };

            var jackpotLookUpGameModeBet = new LookUpGameModeBet
            {
                GameMode = jackpotGameMode,
                User     = user,
                MatchIds = new List <int> {
                    currentMatch.Id
                }
            };

            var userBets = await _betRepoService.FindAsync(new List <LookUpGameModeBet>
            {
                coinflipLookUpGameModeBet,
                jackpotLookUpGameModeBet
            });

            var offers = await _offerTransactionRepoService.FindActiveAsync(user);


            var itemThatUserOwns = await GetItemsThatUsersOwns(user);

            if (userBets.Count == 0 && offers.Count == 0)
            {
                return(itemThatUserOwns);
            }


            if (userBets.Count > 0 && offers.Count == 0)
            {
                return(await GetNoneBetedItems(userBets, itemThatUserOwns));
            }


            if (userBets.Count == 0 && offers.Count > 0)
            {
                return(await GetItemsThatIsNotInAOffer(offers, itemThatUserOwns));
            }


            var itemNotInOffer = await GetItemsThatIsNotInAOffer(offers, itemThatUserOwns);

            var itemNotInBetAndNotInOffer = await GetNoneBetedItems(userBets, itemNotInOffer);

            return(itemNotInBetAndNotInOffer);
        }