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); }
public SteamServiceTest() { var host = "testHost"; var port = 8080; _realUser = new DatabaseModel.User("realUserSteamud", "realUser", "realImg", "myTradelink", DateTime.Now, DateTime.Now, false, null, 10); _scammerUser = new DatabaseModel.User("scammerUserSteamud", "scamerUser", "fakeImg", "myTradelink1", DateTime.Now, DateTime.Now, false, null, 20); _realUsersItems = new List <DatabaseModel.Item>(); _scammerUsersItems = new List <DatabaseModel.Item>(); _fakedGrpcServiceFactory = A.Fake <IGrpcServiceFactory>(); _fakedBotService = A.Fake <IBotService>(); _fakeRepoServiceFacotry = A.Fake <IRepoServiceFactory>(); _fakedSteamServiceClient = A.Fake <ISteamServiceClientWrapper>(); _fakedUserRepoService = A.Fake <IUserRepoService>(); _fakedItemRepoService = A.Fake <IItemRepoService>(); _fakedItemDescRepoService = A.Fake <IItemDescriptionRepoService>(); _fakedSettingsRepoService = A.Fake <ISettingRepoService>(); _fakedOfferTransactionRepoService = A.Fake <IOfferTranascrionRepoService>(); _fakedOfferService = A.Fake <IOfferService>(); A.CallTo(() => _fakeRepoServiceFacotry.UserRepoService).Returns(_fakedUserRepoService); A.CallTo(() => _fakeRepoServiceFacotry.ItemRepoService).Returns(_fakedItemRepoService); A.CallTo(() => _fakeRepoServiceFacotry.SettingRepoService).Returns(_fakedSettingsRepoService); A.CallTo(() => _fakeRepoServiceFacotry.ItemDescriptionRepoService).Returns(_fakedItemDescRepoService); A.CallTo(() => _fakeRepoServiceFacotry.OfferTranascrionRepoService).Returns(_fakedOfferTransactionRepoService); A.CallTo(() => _fakedUserRepoService.FindAsync("scammerUserSteamud")).Returns(_scammerUser); A.CallTo(() => _fakedUserRepoService.FindAsync("realUserSteamud")).Returns(_realUser); A.CallTo(() => _fakedItemRepoService.FindAsync(A <DatabaseModel.User> .That.Matches(user => user.Id == _realUser.Id))) .Returns(_realUsersItems); A.CallTo(() => _fakedItemRepoService.FindAsync(A <DatabaseModel.User> .That.Matches(user => user.Id == _scammerUser.Id))) .Returns(_scammerUsersItems); A.CallTo(() => _fakedGrpcServiceFactory.GetSteamServiceClient(A <ISteamInventoryCacheManager> ._)).Returns(_fakedSteamServiceClient); _steamService = new SteamService( _fakedGrpcServiceFactory, _fakeRepoServiceFacotry, _fakedBotService, A.Dummy <ILogServiceFactory>(), _fakedOfferService, A.Dummy <ISteamInventoryCacheManager>() ); }
private async Task <List <Item> > GetItemsThatUsersOwns(DatabaseModel.User user) { var rawItems = await _itemRepoSerive.FindAsync(user); var list = rawItems.Select(item => item.DescriptionId).ToList(); var itemDescriptions = await _itemDescriptionRepoService.FindAsync(list); return(rawItems.MapItemsToItemsDescription(itemDescriptions)); }
public async Task ChangeOwnerOfItemsSuccess() { var matchId = 1; decimal rake = 10; var gameModeId = 2; var winningUserId = 1337; var bets = new List <DatabaseModel.Bet>(); var items = new List <DatabaseModel.ItemBetted>(); var winningUser = new DatabaseModel.User("steamId", "name", "img", "tradelin", DateTime.Now, DateTime.Now, false, null, winningUserId); A.CallTo(() => _fakedRakeService.GetItemsThatWeShouldTake(rake, bets, items, winningUser)).Returns(new RakeService.RakeResult { ItemIdsToUs = new List <AssetAndDescriptionId> { new AssetAndDescriptionId { AssetId = "1", DescriptionId = 2, } }, ItemIdsToWinner = new List <AssetAndDescriptionId> { new AssetAndDescriptionId { AssetId = "2", DescriptionId = 2, }, new AssetAndDescriptionId { AssetId = "3", DescriptionId = 2, }, new AssetAndDescriptionId { AssetId = "4", DescriptionId = 2, }, } }); A.CallTo(() => _fakedItemRepoService.FindAsync(A <List <AssetAndDescriptionId> > ._)).Returns(new List <DatabaseModel.Item> { new DatabaseModel.Item("1", 2, 3, 5, DateTimeOffset.Now) }); await _service.ChangeOwnerOfItems(bets, items, winningUser, matchId, rake, gameModeId); A.CallTo(() => _fakedItemRepoService.ChangeOwner(A <List <AssetAndDescriptionId> > .That.Matches(list => list.Count == 3), winningUser)).MustHaveHappened(); A.CallTo(() => _fakedRakeItemRepoService.InsertAsync(A <List <DatabaseModel.RakeItem> > .That.Matches( list => list.Count == 1 && list[0].AssetId == "1" && list[0].DescriptionId == 2 && list[0].GameModeId == gameModeId && list[0].MatchId == matchId ), null)).MustHaveHappened(); A.CallTo(() => _fakedRakeItemRepoService.InsertAsync(A <List <DatabaseModel.RakeItem> > .That.Matches(list => list.Count == 1 && list[0].AssetId == "1" && list[0].DescriptionId == 2 ), null )).MustHaveHappened(); A.CallTo(() => _fakedRakeService.GetItemsThatWeShouldTake(rake, bets, items, winningUser)).MustHaveHappened(); }
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); }
public async Task UserHasToManyItemInOurBotInventoryAndDepositThrows() { _realUsersItems = new List <DatabaseModel.Item> { new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), new DatabaseModel.Item("assetId11", 2, 1, _realUser.Id, DateTimeOffset.Now), }; var listOfDepositItems = new List <Item> { new Item { AssetId = "assetId1", AppId = 730, ContextId = "2", MarketHashName = "weapon1" }, new Item { AssetId = "assetId2", AppId = 730, ContextId = "2", MarketHashName = "weapon2" }, new Item { AssetId = "assetId3", AppId = 730, ContextId = "2", MarketHashName = "weapon3" }, new Item { AssetId = "assetId4", AppId = 730, ContextId = "2", MarketHashName = "weapon1" }, }; var itemDescriptions = new List <DatabaseModel.ItemDescription> { new DatabaseModel.ItemDescription("weapon1", new decimal(1), "730", "2", "img", true, 1), new DatabaseModel.ItemDescription("weapon2", new decimal(2), "730", "2", "img", true, 2), new DatabaseModel.ItemDescription("weapon3", new decimal(3), "730", "2", "img", true, 3), }; var steamInventory = new GetPlayerSteamInventoryResponse { PlayerInventory = new PlayerResponseItems { Items = { listOfDepositItems } } }; A.CallTo(() => _fakedSteamServiceClient.GetPlayerSteamInventoryAsync(A <GetPlayerSteamInventoryRequest> ._)).Returns(steamInventory); var botStack = new Stack <DatabaseModel.Bot>(); botStack.Push(new DatabaseModel.Bot("botSteamId", "botName")); A.CallTo(() => _fakedItemRepoService.FindAsync(A <DatabaseModel.User> .That.Matches(user => user.Id == _realUser.Id))) .Returns(_realUsersItems); A.CallTo(() => _fakedSettingsRepoService.GetSettingsAsync()) .Returns(new DatabaseModel.Settings(10, new decimal(0), 0, DateTime.Today, 20)); A.CallTo(() => _fakedBotService.GetAvalibleBotsForDeposit(A <DatabaseModel.User> ._, A <List <DatabaseModel.Item> > ._)).Returns(botStack); A.CallTo(() => _fakedItemDescRepoService.FindAsync(A <List <string> > ._)).Returns(itemDescriptions); await Assert.ThrowsAsync <InventoryLimitExceeded>(async() => await _steamService.MakeDepositOfferAsync(_realUser.SteamId, listOfDepositItems)); }
public async Task <Dictionary <DatabaseModel.Bot, List <DatabaseModel.Item> > > GetBotsWithWithdrawItems(List <AssetAndDescriptionId> ids) { var items = await _itemRepoService.FindAsync(ids); return(await GroupItemByBotLocation(items)); }