private async Task <MongoDbModels.JackpotMatch> InsertIntoMongoDb ( DatabaseModel.CoinFlip insertedMatch, List <DatabaseModel.Item> items, List <DatabaseModel.ItemDescription> itemDescription, JackpotMatchSetting jackpotMatchSetting, DatabaseModel.User user ) { var mapedItems = items.MapItemsToItemsDescription(itemDescription); var coinFlipMatchModel = new MongoDbModels.JackpotMatch { LookUpId = insertedMatch.Id, RoundId = insertedMatch.RoundId, Hash = insertedMatch.Hash, Salt = insertedMatch.Salt, Percentage = insertedMatch.Percentage, Status = insertedMatch.Status, TimerStarted = insertedMatch.TimerStarted, Bets = new List <CoinFlipBet> { new CoinFlipBet { User = new User { ImageUrl = user.ImageUrl, Name = user.Name, SteamId = user.SteamId, }, DateTime = DateTime.Now, Items = mapedItems, Tickets = new RoundTicket { Start = 1, End = (int)(mapedItems.Sum(item => item.Value) * 100) }, IsHead = insertedMatch.CreatorIsHead } }, Setting = jackpotMatchSetting }; await _mongoJackpotRepoService.InsertAsync(coinFlipMatchModel); return(coinFlipMatchModel); }
public async Task CreateMatchSuccess() { var percentage = 12.4587; var percentageAsString = percentage.ToString(CultureInfo.InvariantCulture); var salt = "randomSalt"; var hash = "ranomdHash"; var creatorUser = new DatabaseModel.User("steamId", "name", "imageURl", null, DateTime.Today, DateTime.Today, false, null, 10); var gameMode = new DatabaseModel.GameMode { CurrentSettingId = 1, IsEnabled = true, Type = GameModeHelper.GetStringFromType(GameModeType.CoinFlip), Id = 2 }; A.CallTo(() => _fakedMongoDbPreHashRepoService.Find(hash, creatorUser.SteamId)).Returns(new MongoDbModels.PreHash { Created = DateTime.Today, Hash = hash, Percentage = percentageAsString, Salt = salt, UserSteamId = creatorUser.SteamId }); A.CallTo(() => _fakedRandomService.GenerateNewGuidAsString()).Returns("GUID"); A.CallTo(() => _fakedJackpotSettingRepoService.InsertAsync(A <DatabaseModel.JackpotSetting> ._, A <ITransactionWrapper> ._)) .Returns(new DatabaseModel.JackpotSetting { Id = 1 }); A.CallTo(() => _fakedUserRepoService.FindAsync(creatorUser.SteamId)).Returns(creatorUser); A.CallTo(() => _fakedGameModeRepoSerivce.Find(GameModeHelper.GetStringFromType(GameModeType.CoinFlip))).Returns(gameMode); var itemList = new List <AssetAndDescriptionId> { new AssetAndDescriptionId { AssetId = "assetId1", DescriptionId = 1 } }; await _coinFlipService.CreateMatch(creatorUser.SteamId, true, itemList, _defaultSetting); A.CallTo(() => _fakedCoinFlipMatchRepoService.InsertAsync(A <DatabaseModel.CoinFlip> .That.Matches (m => m.Created > DateTime.Today && m.CreatorUserId == 10 && m.CreatorIsHead == true && m.Hash == hash && m.Salt == salt && m.Percentage == percentageAsString && m.RoundId == "GUID" && m.Status == (int)MatchStatus.Open && m.TimerStarted == null && m.WinnerId == null && m.GameModeId == 2 && m.SettingId == 1 ), A <ITransactionWrapper> ._ )).MustHaveHappened(); A.CallTo(() => _fakedMongoDbPreHashRepoService.Find(hash, creatorUser.SteamId)).MustHaveHappened(); A.CallTo(() => _fakedUserRepoService.FindAsync(creatorUser.SteamId)).MustHaveHappened(); A.CallTo(() => _fakedTransactionWrapper.Commit()).MustHaveHappened(); A.CallTo(() => _fakedBetService.PlaceBetOnCoinFlipMatch ( A <DatabaseModel.CoinFlip> ._, A <JackpotMatchSetting> ._, A <DatabaseModel.GameMode> ._, A <int> ._, A <List <DatabaseModel.Item> > ._, A <DatabaseModel.User> ._, A <List <DatabaseModel.ItemDescription> > ._ )).MustHaveHappened(); A.CallTo(() => _fakedMongoDbJackpotRepoService.InsertAsync(A <MongoDbModels.JackpotMatch> ._)).MustHaveHappened(); }