Exemple #1
0
        public async Task UserDepositItemsSuccess()
        {
            _offerMinmalInfo.OfferSend.SteamOffer.ItemsToGive.Clear();

            var offerTransInsertWithId = new DatabaseModel.OfferTransaction(1, 14, new decimal(196.91), true, "12345", DateTime.Today, 75);

            var userInsertRes = new DatabaseModel.User("userSteamId", "name", "img", "tradeLink", DateTime.Today, DateTime.Today, false, null, 1);

            A.CallTo(() => _fakedUserRepoService.FindAsync("userSteamId")).Returns(userInsertRes);

            var botLookRes = Task.FromResult(new DatabaseModel.Bot("botSteamId", "botName", 14));

            A.CallTo(() => _fakedBotRepoService.FindAsync("botSteamId")).Returns(botLookRes);

            A.CallTo(() => _fakedOfferTranascrionRepoService.InsertAsync(A <DatabaseModel.OfferTransaction> .That.Matches(o =>
                                                                                                                          o.IsDeposit && o.Accepted > DateTime.Today && o.BotId == 14 && o.UserId == 1 && o.Id == 0 && o.TotalValue == new decimal(196.91)
                                                                                                                          ), A <ITransactionWrapper> ._)).Returns(offerTransInsertWithId);

            await _offerService.DepositSteamOfferAsync(_offerMinmalInfo);

            A.CallTo(() => _fakedOfferTranascrionRepoService.InsertAsync(A <DatabaseModel.OfferTransaction> .That.Matches(o =>
                                                                                                                          o.IsDeposit && o.Accepted > DateTime.Today && o.BotId == 14 && o.UserId == 1 && o.Id == 0 && o.TotalValue == new decimal(196.91)
                                                                                                                          ), A <ITransactionWrapper> ._)).MustHaveHappened();
            A.CallTo(() => _fakedItemInOfferTransactionRepoService.InsertAsync(A <List <DatabaseModel.ItemInOfferTransaction> > .That.Matches(i =>
                                                                                                                                              i.Where(o => o.OfferTransactionId == 75 && o.ItemDescriptionId == 1 && o.Value == new decimal(11.22)).ToList().Count == 2 &&
                                                                                                                                              i.Where(o => o.OfferTransactionId == 75 && o.ItemDescriptionId == 3 && o.Value == new decimal(78.00)).ToList().Count == 1 &&
                                                                                                                                              i.Where(o => o.OfferTransactionId == 75 && o.ItemDescriptionId == 4 && o.Value == new decimal(5.47)).ToList().Count == 1 &&
                                                                                                                                              i.Where(o => o.OfferTransactionId == 75 && o.ItemDescriptionId == 2 && o.Value == new decimal(45.5)).ToList().Count == 2
                                                                                                                                              ), A <ITransactionWrapper> ._)).MustHaveHappened();

            A.CallTo(() => _fakedTransactionWrapper.Commit()).MustHaveHappened();
        }
Exemple #2
0
        private async Task <OfferData> CreateOfferData(OfferStatusRequest request, bool isDeposit)
        {
            var bot = await _botRepoService.FindAsync(request.Bot.SteamId);

            var owner = await _userRepoService.FindAsync(request.SteamId);

            var itemsInOfferRequest = isDeposit ? request.OfferSend.SteamOffer.ItemsToReceive : request.OfferSend.SteamOffer.ItemsToGive;

            return(await CreateTransactionOfferAsync(itemsInOfferRequest.ToList(), bot, owner, isDeposit));
        }
Exemple #3
0
        private async Task <DatabaseModel.Bot> GetBotWithLeastItem()
        {
            var allAvalibleBots = await _botRepoService.GetAll();

            var items = await _itemRepoService.GetAll();

            var botIdsInUse       = items.Select(item => item.LocationId).Distinct().ToList();
            var allAvalibleBotIds = allAvalibleBots.Select(bot => bot.Id).ToList();

            var botsNotInUse = allAvalibleBotIds.Except(botIdsInUse).ToList();

            if (botsNotInUse.Count > 0)
            {
                var bot = await _botRepoService.FindAsync(botsNotInUse.First());

                return(bot);
            }

            try
            {
                var botId = items.GroupBy(item => item.LocationId)
                            .OrderBy(item => item.Count())
                            .First()
                            .Select(item => item.LocationId)
                            .First();
                var bot = await _botRepoService.FindAsync(botId);

                return(bot);
            }
            catch (InvalidOperationException)
            {
            }

            try
            {
                return((await _botRepoService.GetAll()).First());
            }
            catch (InvalidOperationException)
            {
                throw new NoBotInDatabaseException("No bots is in the database");
            }
        }
Exemple #4
0
        private async void RpcSteamListenerOnOnBotStatusChanged(object sender, BotStatusChangedRequest offer)
        {
            //todo make this into the manger it deservs!
            if (offer.Bot.BotType != botType.OfferVendor)
            {
                return;
            }
            if (offer.StatusCode != 1)
            {
                return;
            }

            var reqBot = offer.Bot;

            var databaseBot = await _botServiceRepo.FindAsync(offer.Bot.SteamId);

            if (databaseBot == null)
            {
                await _botServiceRepo.InsertAsync(new DatabaseModel.Bot(reqBot.SteamId, reqBot.Username));
            }
        }
        public async Task GetBotsAndItemsForWithdrawSuccess()
        {
            //this will lookup where his items is and create a new offer for every bot that the item is in.

            var assetAndDescIds = new List<AssetAndDescriptionId>
            {
                new AssetAndDescriptionId {AssetId = "assetId1", DescriptionId = 1},
                new AssetAndDescriptionId {AssetId = "assetId2", DescriptionId = 3},
                new AssetAndDescriptionId {AssetId = "assetId1", DescriptionId = 2},
                new AssetAndDescriptionId {AssetId = "assetId5", DescriptionId = 1},
            };

            var databaseItem = new List<DatabaseModel.Item>
            {
                new DatabaseModel.Item("assetId1", 1, 1, -1, DateTimeOffset.Now, -1),
                new DatabaseModel.Item("assetId2", 3, 2, -1, DateTimeOffset.Now, -1),
                new DatabaseModel.Item("assetId1", 2, 3, -1, DateTimeOffset.Now, -1),
                new DatabaseModel.Item("assetId5", 1, 1, -1, DateTimeOffset.Now, -1),
            };

            A.CallTo(() => _fakedItemRepoService.FindAsync(A<List<AssetAndDescriptionId>>._)).Returns(databaseItem);
            A.CallTo(() => _fakedBotRepoService.FindAsync(A<List<int>>._)).ReturnsLazily(CreateBots);

            var dict = await _botService.GetBotsWithWithdrawItems(assetAndDescIds);

            Assert.Equal(3, dict.Count);
            Assert.Equal(2, dict.First(kvp => kvp.Key.Id == 1).Value.Count);
            Assert.Equal(1, dict.First(kvp => kvp.Key.Id == 2).Value.Count);
            Assert.Equal(1, dict.First(kvp => kvp.Key.Id == 3).Value.Count);
        }