public void DeletingGame_ShouldRemoveOneRecordInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); // create new game and insert it, so we have something to delete var gameToUpdate = new TicTacToeData(); cachedAdapter.Save(gameToUpdate); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act cachedAdapter.Delete(gameToUpdate.Id); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql - 1, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis - 1, numPostExistingGamesRedis); }
public void SavingExistingObject_ShouldPreserveNumberOfRecordsInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); // create new game and insert it, so we have something to update var gameToUpdate = new TicTacToeData(); cachedAdapter.Save(gameToUpdate); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act gameToUpdate.CurrentPlayer = Player.O; cachedAdapter.Save(gameToUpdate); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis, numPostExistingGamesRedis); }
public void SavingNewObject_ShouldInsertOneRecord() { // Arrange var connectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var adapter = new SqlServerAdapter(connectionString); var newGame = new TicTacToeData(); int numPreExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); // Act adapter.Save(newGame); // Assert int numPostExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); Assert.AreEqual(numPreExistingGames + 1, numPostExistingGames); }
public void DeletingGame_ShouldRemoveOneRecord() { // Arrange // create new game and insert it, so we have something to delete var gameToUpdate = new TicTacToeData(); var connectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var adapter = new SqlServerAdapter(connectionString); adapter.Save(gameToUpdate); int numPreExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); // Act adapter.Delete(gameToUpdate.Id); // Assert int numPostExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); Assert.AreEqual(numPreExistingGames - 1, numPostExistingGames); }
public void SavingExistingObject_ShouldPreserveNumberOfRecords() { // Arrange // create new game and insert it, so we have something to update var gameToUpdate = new TicTacToeData(); var connectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var adapter = new SqlServerAdapter(connectionString); adapter.Save(gameToUpdate); int numPreExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); // Act gameToUpdate.CurrentPlayer = Player.O; adapter.Save(gameToUpdate); // Assert int numPostExistingGames = AdapterTestHelpers.CountSqlGames(connectionString); Assert.AreEqual(numPreExistingGames, numPostExistingGames); }
public void SavingNewObject_ShouldInsertOneRecordInPrimaryAndCache() { // Arrange var sqlConnectionString = ConfigurationManager.ConnectionStrings["test"].ToString(); var redisConnectionString = ConfigurationManager.ConnectionStrings["redis-test"].ToString(); var sqlAdapter = new SqlServerAdapter(sqlConnectionString); var redisAdapter = new RedisAdapter(ConnectionMultiplexer.Connect(redisConnectionString)); var cachedAdapter = new SqlServerCachedAdapter(sqlAdapter, redisAdapter); var newGame = new TicTacToeData(); int numPreExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPreExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); // Act cachedAdapter.Save(newGame); // Assert int numPostExistingGamesSql = AdapterTestHelpers.CountSqlGames(sqlConnectionString); int numPostExistingGamesRedis = AdapterTestHelpers.CountRedisGames(redisConnectionString); Assert.AreEqual(numPreExistingGamesSql + 1, numPostExistingGamesSql); Assert.AreEqual(numPreExistingGamesRedis + 1, numPostExistingGamesRedis); }