public async void UpdateWinnerSuccess() { var entity = new DatabaseModel.CoinFlip { Created = DateTime.Now, CreatorUserId = _setup.User1.Id, CreatorIsHead = true, GameModeId = _setup.GameMode.Id, Hash = "HASh", Percentage = 10.654.ToString(CultureInfo.InvariantCulture), RoundId = Guid.NewGuid().ToString(), Salt = "SALT", SettingId = 0, Status = 0, TimerStarted = null, WinnerId = null, }; using (var trans = new TransactionWrapperWrapper(_setup.Database)) { var insertedCoinFlip = await _coinFlipMatchRepoService.InsertAsync(entity, trans); insertedCoinFlip.WinnerId = _setup.User1.Id; trans.Commit(); await _coinFlipMatchRepoService.UpdateAsync(insertedCoinFlip); var findEntiry = await _coinFlipMatchRepoService.FindAsync(entity.Id); Assert.Equal(_setup.User1.Id, findEntiry.WinnerId); } }
public async Task TransactionInsertThrows() { var userToInsert = new DatabaseModel.User("werryRandomSteamId", "name", "imgUrl", "tradeLink", DateTime.Now, DateTime.Now, false); var insertUserQuery = new QueryFactory().UserQueries.InsertReturnsId(userToInsert); var didTrow = false; using (var transaction = new TransactionWrapperWrapper(_databaseConnection)) { try { var userId = await transaction.ExecuteSqlCommand <int>(insertUserQuery); var userId1 = await transaction.ExecuteSqlCommand <int>(insertUserQuery); transaction.Commit(); } catch (Exception e) { didTrow = true; transaction.Rollback(); } Assert.True(didTrow); var fakedFactory = A.Fake <IDatabaseConnectionFactory>(); A.CallTo(() => fakedFactory.GetDatabaseConnection(Factories.Database.Main)).Returns(_databaseConnection); var userRepoService = new UserRepoService(fakedFactory, new QueryFactory().UserQueries); var user = await userRepoService.FindAsync("werryRandomSteamId"); Assert.Null(user); } }
public async void InsertFailsAndRollBackIsDoneSuccess() { var entity = new DatabaseModel.CoinFlip { Created = DateTime.Now, CreatorUserId = _setup.User1.Id, CreatorIsHead = true, GameModeId = _setup.GameMode.Id, Hash = "HASh", Percentage = 10.654.ToString(CultureInfo.InvariantCulture), RoundId = Guid.NewGuid().ToString(), Salt = "SALT", SettingId = 0, Status = 0, TimerStarted = null, WinnerId = null, }; using (var trans = new TransactionWrapperWrapper(_setup.Database)) { Assert.True(entity.IsNew); var insertedCoinFlip = await _coinFlipMatchRepoService.InsertAsync(entity, trans); Assert.False(entity.IsNew); Assert.True(insertedCoinFlip.Id > 0); trans.Rollback(); var res = await _coinFlipMatchRepoService.FindAsync(insertedCoinFlip.Id); Assert.Equal(null, res); } }
public async Task TransactionInsertSuccessfully() { var userToInsert = new DatabaseModel.User("randomSteamId", "name", "imgUrl", "tradeLink", DateTime.Now, DateTime.Now, false); var userToInsert1 = new DatabaseModel.User("randomSteamId1", "name", "imgUrl", "tradeLink", DateTime.Now, DateTime.Now, false); var insertUserQuery = new QueryFactory().UserQueries.InsertReturnsId(userToInsert); var insertUserQuery1 = new QueryFactory().UserQueries.InsertReturnsId(userToInsert1); using (var transaction = new TransactionWrapperWrapper(_databaseConnection)) { var userId = await transaction.ExecuteSqlCommand <int>(insertUserQuery); var userId1 = await transaction.ExecuteSqlCommand <int>(insertUserQuery1); Assert.NotEqual(userId, userId1); transaction.Commit(); } }
public async Task InitTest() { ConnectionString = new ConnectionStringsForTest().GetConnectionString(DatabaseName); Database = new DatabaseConnection(ConnectionString); var fakedFactory = A.Fake <IDatabaseConnectionFactory>(); A.CallTo(() => fakedFactory.GetDatabaseConnection(Factories.Database.Main)).Returns(Database); var userRepo = new UserRepoService(fakedFactory, new UserQueries()); var matchRepoService = new MatchRepoService(fakedFactory, new MatchQueries()); var coinFlipMatchRepoService = new CoinFlipMatchRepoService(fakedFactory); var gameModeRepoService = new GameModeRepoService(fakedFactory); var gameMode = new DatabaseModel.GameMode(GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo), 1); var gameMode1 = new DatabaseModel.GameMode(GameModeHelper.GetStringFromType(GameModeType.CoinFlip), 1); GameMode = await gameModeRepoService.Insert(gameMode); GameMode1 = await gameModeRepoService.Insert(gameMode1); User1 = await userRepo.InsertAsync(new DatabaseModel.User( "987654321", "Kalle", " ba/bab154f01140ec39b2986d97838f0127534ec82d_full.jpg ", "?partner=117688384&token=mn347bmb ", DateTime.Now, DateTime.Now, false )); User2 = await userRepo.InsertAsync(new DatabaseModel.User( "987154321", "Kalle", " ba/bab154f01140ec39b2986d97838f0127534ec82d_full.jpg ", "?partner=117688384&token=mn347bmb ", DateTime.Now, DateTime.Now, false )); User3 = await userRepo.InsertAsync(new DatabaseModel.User( "983654321", "Kalle", " ba/bab154f01140ec39b2986d97838f0127534ec82d_full.jpg ", "?partner=117688384&token=mn347bmb ", DateTime.Now, DateTime.Now, false )); User4 = await userRepo.InsertAsync(new DatabaseModel.User( "983656584", "Kalle", " ba/bab154f01140ec39b2986d97838f0127534ec82d_full.jpg ", "?partner=117688384&token=mn347bmb ", DateTime.Now, DateTime.Now, false )); Match1 = await matchRepoService.InsertAsync(new DatabaseModel.Match( 11, "salt", "hash", 47.5484.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, GameMode.Id, DateTime.Now )); Match2 = await matchRepoService.InsertAsync(new DatabaseModel.Match( 12, "salt", "hash", 47.5484.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, GameMode.Id, DateTime.Now )); Match3 = await matchRepoService.InsertAsync(new DatabaseModel.Match( 13, "salt", "hash", 47.5484.ToString(CultureInfo.InvariantCulture), 1, null, null, 1, GameMode.Id, DateTime.Now )); using (var transaction = new TransactionWrapperWrapper(Database)) { CoinFlip1 = await coinFlipMatchRepoService.InsertAsync(new DatabaseModel.CoinFlip { Created = DateTime.Today, CreatorIsHead = true, CreatorUserId = User1.Id, GameModeId = gameMode1.Id, Hash = "", Percentage = "", Salt = "", RoundId = "xF!", SettingId = 0, Status = 1, TimerStarted = null, WinnerId = null }, transaction); CoinFlip2 = await coinFlipMatchRepoService.InsertAsync(new DatabaseModel.CoinFlip { Created = DateTime.Today, CreatorIsHead = true, CreatorUserId = User1.Id, GameModeId = gameMode1.Id, Hash = "", Percentage = "", Salt = "", RoundId = "xD1", SettingId = 0, Status = 1, TimerStarted = null, WinnerId = null }, transaction); CoinFlip3 = await coinFlipMatchRepoService.InsertAsync(new DatabaseModel.CoinFlip { Created = DateTime.Today, CreatorIsHead = true, CreatorUserId = User1.Id, GameModeId = gameMode1.Id, Hash = "", Percentage = "", Salt = "", RoundId = "xD", SettingId = 0, Status = 1, TimerStarted = null, WinnerId = null }, transaction); transaction.Commit(); } }