Пример #1
0
        public async Task UserPrepareWithdrawalItemsSuccess()
        {
            _offerMinmalInfo.OfferSend.SteamOffer.ItemsToReceive.Clear();
            _offerMinmalInfo.OfferSend.SteamOffer.Id = "12346";

            var offerTransInsertWithId = new DatabaseModel.OfferTransaction(1, 14, new decimal(196.91), false, "12346", DateTime.Today, 75);
            var bot = new DatabaseModel.Bot("botSteamId", "botName", 14);

            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(bot);

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

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

            await _offerService.PrepareWithdrawlSteamOffer(_offerMinmalInfo.OfferSend.SteamOffer.ItemsToGive.ToList(), bot, userInsertRes);

            A.CallTo(() => _fakedOfferTranascrionRepoService.InsertAsync(A <DatabaseModel.OfferTransaction> .That.Matches(o =>
                                                                                                                          !o.IsDeposit && o.Accepted == null && 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();
        }
Пример #2
0
        public async Task <DatabaseModel.OfferTransaction> InsertAsync(DatabaseModel.OfferTransaction offerTransaction,
                                                                       ITransactionWrapper transactionWrapper = null)
        {
            var query = _offerTransationQueries.InsertReturnsId(offerTransaction);

            int id;

            if (transactionWrapper != null)
            {
                id = await transactionWrapper.ExecuteSqlCommand <int>(query);
            }
            else
            {
                id = (int)await _databaseConnection.ExecuteScalarAsync(query);
            }

            return(new DatabaseModel.OfferTransaction(
                       offerTransaction.UserId,
                       offerTransaction.BotId,
                       offerTransaction.TotalValue,
                       offerTransaction.IsDeposit,
                       offerTransaction.SteamOfferId,
                       offerTransaction.Accepted,
                       id
                       ));
        }
Пример #3
0
        private async Task <OfferData> CreateTransactionOfferAsync
        (
            List <Item> itemsInOfferRequest,
            DatabaseModel.Bot bot,
            DatabaseModel.User owner,
            bool isDeposit
        )
        {
            var listOfNames = itemsInOfferRequest.Select(item => item.MarketHashName).ToList();

            var itemsDesc = await _itemDescRepoServcice.FindAsync(listOfNames);

            var databaseItems = new List <DatabaseModel.Item>();
            var itemsInOffer  = new List <DatabaseModel.ItemInOfferTransaction>();

            decimal sumOfItems = 0;

            foreach (var item in itemsInOfferRequest)
            {
                DatabaseModel.ItemDescription itemDesc;

                try
                {
                    itemDesc = itemsDesc.First(i => i.Name == item.MarketHashName);
                }
                catch (System.Exception e)
                {
                    var ex = new SteamMarketNameFuckupException(item.MarketHashName, e);
                    ex.Data.Add("marketHashName", item.MarketHashName);
                    ex.Data.Add("itemDescriptions", itemsDesc);
                    _logService.Critical(ex);
                    throw ex;
                }

                var steamLockTime = DateTimeOffset.Now;

                if (item.AppId == 730)
                {
                    steamLockTime = steamLockTime.Add(_steamLock);
                }

                databaseItems.Add(new DatabaseModel.Item(item.AssetId, itemDesc.Id, bot.Id, owner.Id, steamLockTime));
                sumOfItems += itemDesc.Value;

                var itemInOffer = new DatabaseModel.ItemInOfferTransaction(int.MinValue, itemDesc.Id, item.AssetId, itemDesc.Value);
                itemsInOffer.Add(itemInOffer);
            }

            var offer = new DatabaseModel.OfferTransaction(owner.Id, bot.Id, sumOfItems, isDeposit, null, DateTime.Now);

            return(new OfferData
            {
                Items = databaseItems,
                ItemsInOffer = itemsInOffer,
                OfferTransactions = offer
            });
        }
Пример #4
0
        public async Task <List <DatabaseModel.ItemInOfferTransaction> > FindAsync(DatabaseModel.OfferTransaction offerTransaction)
        {
            var query = _itemInOfferTransactionQueries.GetFromTransactionId(offerTransaction.Id);

            using (var sqlRes = await _databaseConnection.ExecuteSqlQueryAsync(query))
            {
                var items = await sqlRes.GetListAsync <DatabaseModel.ItemInOfferTransaction>();

                return(items);
            }
        }
        public async Task InitTest()
        {
            var offerTransactionServiceRepo = new OfferTransactionRepoService(DatabaseConnectionFactory, new OfferTransationQueries());
            var botServiceRepo      = new BotRepoService(DatabaseConnectionFactory, new BotQueries());
            var userServiceRepo     = new UserRepoService(DatabaseConnectionFactory, new UserQueries());
            var itemDescServiceRepo = new ItemDescriptionRepoService(DatabaseConnectionFactory, new ItemDescriptionQueries());

            _user1 = await userServiceRepo.InsertAsync(new DatabaseModel.User("steamId1", "name1", "imgUrl", "tradelink", DateTime.Now,
                                                                              DateTime.Now, false));

            _user2 = await userServiceRepo.InsertAsync(new DatabaseModel.User("steamId2", "name2", "imgUrl", "tradelink", DateTime.Now,
                                                                              DateTime.Now, false));

            _bot1 = await botServiceRepo.InsertAsync(new DatabaseModel.Bot("botSteamId1", "botName1"));


            var toInsert1 = new DatabaseModel.OfferTransaction(_user1.Id, _bot1.Id, new decimal(10.45), true, "456232", DateTime.Now);
            var toInsert2 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(54.45), false, "456332", DateTime.Now);
            var toInsert3 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(666.66), false, "454132", DateTime.Now);
            var toInsert4 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(544.75), false, "455132", null);
            var toInsert5 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(10.75), true, "456162", DateTime.Today);
            var toInsert6 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(10.75), true, "44864748654", DateTime.Today);
            var toInsert7 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(10.75), true, "548", DateTime.Today);
            var toInsert8 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(10.75), true, "555", DateTime.Today);
            var toInsert9 = new DatabaseModel.OfferTransaction(_user2.Id, _bot1.Id, new decimal(10.75), true, "5646555", DateTime.Today);

            OfferTransaction1 = await offerTransactionServiceRepo.InsertAsync(toInsert1);

            OfferTransaction2 = await offerTransactionServiceRepo.InsertAsync(toInsert2);

            OfferTransaction3 = await offerTransactionServiceRepo.InsertAsync(toInsert3);

            OfferTransaction4 = await offerTransactionServiceRepo.InsertAsync(toInsert4);

            OfferTransaction5 = await offerTransactionServiceRepo.InsertAsync(toInsert5);

            OfferTransaction6 = await offerTransactionServiceRepo.InsertAsync(toInsert6);

            OfferTransaction7 = await offerTransactionServiceRepo.InsertAsync(toInsert7);

            OfferTransaction8 = await offerTransactionServiceRepo.InsertAsync(toInsert8);

            OfferTransaction9 = await offerTransactionServiceRepo.InsertAsync(toInsert9);

            ItemDescription1 =
                await itemDescServiceRepo.InsertAsync(new DatabaseModel.ItemDescription("weapon1", new decimal(1.40), "720", "2", "imgUrl1", true));

            ItemDescription2 =
                await itemDescServiceRepo.InsertAsync(new DatabaseModel.ItemDescription("weapon2", new decimal(8.75), "720", "2", "imgUrl2", true));
        }
Пример #6
0
        public SqlQuery InsertReturnsId(DatabaseModel.OfferTransaction offerTransactions)
        {
            var dict = new Dictionary <string, object>
            {
                { "@userId", offerTransactions.UserId },
                { "@botId", offerTransactions.BotId },
                { "@totalValue", offerTransactions.TotalValue },
                { "@isDeposit", offerTransactions.IsDeposit },
                { "@steamOfferId", offerTransactions.SteamOfferId },
                { "@accepted", offerTransactions.Accepted }
            };

            return(new SqlQuery(
                       "INSERT INTO [OfferTransaction] (UserId, BotId, TotalValue, isDeposit,SteamOfferId, Accepted) OUTPUT INSERTED.Id  " +
                       "VALUES (@userId ,@botId, @totalValue, @isDeposit,@steamOfferId, @accepted);",
                       dict));
        }
Пример #7
0
        private async Task <DatabaseModel.OfferTransaction> InsertTransactionOfferAndItemsInTransactionOffer
        (
            ITransactionWrapper transactionWrapper,
            DatabaseModel.OfferTransaction offerTransactions,
            List <DatabaseModel.ItemInOfferTransaction> itemsInOffer
        )
        {
            var offerInsertResponse = await _offerRepoService.InsertAsync(offerTransactions, transactionWrapper);

            foreach (var itemInOfferTransaction in itemsInOffer)
            {
                itemInOfferTransaction.OfferTransactionId = offerInsertResponse.Id;
            }

            await _itemInOfferTransactionRepoService.InsertAsync(itemsInOffer, transactionWrapper);

            transactionWrapper?.Commit();
            return(offerInsertResponse);
        }
Пример #8
0
        public async Task UserDepositItemsTransactionThrows()
        {
            _offerMinmalInfo.OfferSend.SteamOffer.ItemsToGive.Clear();

            var offerTransInsertWithId = new DatabaseModel.OfferTransaction(1, 14, new decimal(196.91), true, "12347", 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> ._, A <ITransactionWrapper> ._))
            .Throws(new CantCompleteTransaction(new System.Exception()));

            await Assert.ThrowsAsync <CantCompleteSteamDeposit>(async() => await _offerService.DepositSteamOfferAsync(_offerMinmalInfo));

            A.CallTo(() => _fakedTransactionWrapper.Commit()).MustNotHaveHappened();
            A.CallTo(() => _fakedTransactionWrapper.Rollback()).MustHaveHappened();
        }
Пример #9
0
        public async Task UserWithdrawalItemsSuccess()
        {
            _offerMinmalInfo.OfferSend.SteamOffer.ItemsToReceive.Clear();
            _offerMinmalInfo.OfferSend.SteamOffer.Id = "12346";

            var offerTransInsertWithId = new DatabaseModel.OfferTransaction(1, 14, new decimal(196.91), false, "12346", 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.FindAsync("12346")).Returns(offerTransInsertWithId);

            await _offerService.WithdrawalSteamOffer(_offerMinmalInfo);

            A.CallTo(() => _fakedOfferTranascrionRepoService.AddAcceptedTimesptampToOffer(A <DateTime> ._, 75)).MustHaveHappened();

            A.CallTo(() => _fakedItemRepoService.DeleteAsync(A <List <DatabaseModel.Item> > ._)).MustHaveHappened();
        }
Пример #10
0
 public SqlQuery Insert(DatabaseModel.OfferTransaction itemDescription)
 {
     return(InsertRange(new List <DatabaseModel.OfferTransaction> {
         itemDescription
     }));
 }