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 Delete_NonexistentPower_PreservesNumberOfRecords() { // Arrange var numPreExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); // Act Adapter.Delete(Guid.NewGuid()); // Assert var numPostExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); Assert.AreEqual(numPreExistingPowers, numPostExistingPowers); }
public void Save_NewPower_InsertsOneRecord() { // Arrange var numPreExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); var newPower = new Power(Guid.NewGuid(), "Super Archery"); // Act Adapter.Save(newPower); // Assert var numPostExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); Assert.AreEqual(numPreExistingPowers + 1, numPostExistingPowers); }
public void Save_NewHero_InsertsOneRecord() { // Arrange var numPreExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); var newHero = new Hero(Guid.NewGuid(), "Hawkeye", "???", new List <Power>()); // Act Adapter.Save(newHero); // Assert var numPostExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); Assert.AreEqual(numPreExistingHeroes + 1, numPostExistingHeroes); }
public void Save_NewTeam_InsertsOneRecord() { // Arrange var numPreExistingTeams = AdapterTestHelpers.CountRedisTeams(ConnectionString); var newTeam = new Team(Guid.NewGuid(), "Guardians of the Galaxy", new List <Hero>()); // Act Adapter.Save(newTeam); // Assert var numPostExistingTeams = AdapterTestHelpers.CountRedisTeams(ConnectionString); Assert.AreEqual(numPreExistingTeams + 1, numPostExistingTeams); }
public void SavingNewObject_ShouldInsertOneRecord() { // Arrange int numPreExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); // Act var newGame = new TicTacToeData(); Adapter.Save(newGame); // Assert int numPostExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); Assert.AreEqual(numPreExistingGames + 1, numPostExistingGames); }
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(); Adapter.Save(gameToUpdate); int numPreExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); // Act Adapter.Delete(gameToUpdate.Id); // Assert int numPostExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); Assert.AreEqual(numPreExistingGames - 1, numPostExistingGames); }
public void Delete_ExistingHero_RemovesOneRecord() { // Arrange // make sure at least one hero exists, so we can delete it var hero = new Hero(Guid.NewGuid(), "Batman", "Gotham", new List <Power>()); Adapter.Save(hero); var numPreExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); // Act Adapter.Delete(hero.Id); // Assert var numPostExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); Assert.AreEqual(numPreExistingHeroes - 1, numPostExistingHeroes); }
public void Delete_ExistingTeam_RemovesOneRecord() { // Arrange // make sure at least one team exists, so we can delete it var team = new Team(Guid.NewGuid(), "Bat-Family", new List <Hero>()); Adapter.Save(team); var numPreExistingTeams = AdapterTestHelpers.CountRedisTeams(ConnectionString); // Act Adapter.Delete(team.Id); // Assert var numPostExistingPowers = AdapterTestHelpers.CountRedisTeams(ConnectionString); Assert.AreEqual(numPreExistingTeams - 1, numPostExistingPowers); }
public void Delete_ExistingPower_RemovesOneRecord() { // Arrange // make sure at least one power exists, so we can delete it var power = new Power(Guid.NewGuid(), "Some ridiculous Silver Age stuff"); Adapter.Save(power); var numPreExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); // Act Adapter.Delete(power.Id); // Assert var numPostExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); Assert.AreEqual(numPreExistingPowers - 1, numPostExistingPowers); }
public void SavingExistingObject_ShouldPreserveNumberOfRecords() { // Arrange // create new game and insert it, so we have something to update var gameToUpdate = new TicTacToeData(); Adapter.Save(gameToUpdate); int numPreExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); // Act gameToUpdate.CurrentPlayer = Player.O; Adapter.Save(gameToUpdate); // Assert int numPostExistingGames = AdapterTestHelpers.CountRedisGames(ConnectionString); Assert.AreEqual(numPreExistingGames, numPostExistingGames); }
public void Save_ExistingTeam_PreservesNumberOfRecords() { // Arrange // make sure at least one power exists, so we have something to update var oldTeam = new Team(Guid.NewGuid(), "Justice League", new List <Hero>()); Adapter.Save(oldTeam); var numPreExistingTeams = AdapterTestHelpers.CountRedisTeams(ConnectionString); // Act var newTeam = new Team(oldTeam.Id, "SUPER JUSTICE LEAGUE!!!!11", new List <Hero>()); Adapter.Save(newTeam); // Assert var numPostExistingTeams = AdapterTestHelpers.CountRedisTeams(ConnectionString); Assert.AreEqual(numPreExistingTeams, numPostExistingTeams); }
public void Save_ExistingHero_PreservesNumberOfRecords() { // Arrange // make sure at least one hero exists, so we have something to update var oldHero = new Hero(Guid.NewGuid(), "Superman", "Metropolis", new List <Power>()); Adapter.Save(oldHero); var numPreExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); // Act var newHero = new Hero(oldHero.Id, "Superman Red Son", "Moscow", new List <Power>()); Adapter.Save(newHero); // Assert var numPostExistingHeroes = AdapterTestHelpers.CountRedisHeroes(ConnectionString); Assert.AreEqual(numPreExistingHeroes, numPostExistingHeroes); }
public void Save_ExistingPower_PreservesNumberOfRecords() { // Arrange // make sure at least one power exists, so we have something to update var oldPower = new Power(Guid.NewGuid(), "Flight"); Adapter.Save(oldPower); var numPreExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); // Act var newPower = new Power(oldPower.Id, "SUUUUPER FLIGHT"); Adapter.Save(newPower); // Assert var numPostExistingPowers = AdapterTestHelpers.CountSqlPowers(ConnectionString); Assert.AreEqual(numPreExistingPowers, numPostExistingPowers); }
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); }