Esempio n. 1
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");
            }
        }
Esempio n. 2
0
        public async Task GetAvalibleBotsForDepositUserBotHasNoSkinsSuccess()
        {
            var user = new DatabaseModel.User("steamId", "name", "imgUrl", "tade", DateTime.Now, DateTime.Now, false, null, 10);

            var allItems = new List<DatabaseModel.Item>
            {
                new DatabaseModel.Item("assetId1", 1, 3, 6, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId2", 1, 3, 6, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId3", 1, 3, 6, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId4", 1, 7, 5, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId5", 1, 1, 5, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId6", 1, 1, 5, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId7", 1, 1, 1, DateTimeOffset.Now),
                new DatabaseModel.Item("assetId8", 1, 1, 4, DateTimeOffset.Now),
            };

            A.CallTo(() => _fakedItemRepoService.GetAll()).Returns(allItems);
            A.CallTo(() => _fakedItemRepoService.FindAsync(A<DatabaseModel.User>._))
                .Returns(allItems.Where(item => item.OwnerId == user.Id).ToList());
            A.CallTo(() => _fakedBotRepoService.FindAsync(154)).ReturnsLazily(call => Task.FromResult(CreateBot((int) call.Arguments[0])));
            A.CallTo(() => _fakedBotRepoService.FindAsync(A<List<int>>._)).ReturnsLazily(CreateBots);
            A.CallTo(() => _fakedBotRepoService.GetAll()).Returns(new List<DatabaseModel.Bot>
            {
                CreateBot(1),
                CreateBot(154),
                CreateBot(3),
                CreateBot(7),
            });

            var bots = await _botService.GetAvalibleBotsForDeposit(user, new List<DatabaseModel.Item>());

            Assert.Equal(1, bots.Count);
            Assert.Equal(154, bots.Pop().Id);

            A.CallTo(() => _fakedBotRepoService.FindAsync(154)).MustHaveHappened();
        }