/* * this method saves a game */ public bool Save(GameStorageModel storageModel) { // assume the game will not be saved bool success = false; // databse connection string String connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MinesweeperDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; // connect to databse in business service to support ACID transactions using (SqlConnection connection = new SqlConnection(connectionString)) { // instantiate DAO GameDAO dao = new GameDAO(connection); // open databse connection connection.Open(); // pass control to DAO to delete user previous save dao.Delete(storageModel.User); // pass control to DAO to save the current game and catch return value success = dao.Create(storageModel); // close database connection connection.Close(); } // return result of save attempt return(success); }
public void DeleteGame_Success() { //arrange //----make a game model Game gameModel = new Game() { GameState = GameState.Abandoned }; //----make gameDAO GameDAO gameDAO = new GameDAO(); //----make game to be deleted Game gameToBeDeleted = gameDAO.Create(gameModel); //act int?result = gameDAO.Delete(gameToBeDeleted.GameId); //assert Assert.IsNotNull(result); Assert.AreEqual(1, result.Value); }
public void CreateGame_Success() { //arrange //----make a game model Game gameModel = new Game() { GameState = GameState.Abandoned }; //----make gameDAO GameDAO gameDAO = new GameDAO(); //act Game result = gameDAO.Create(gameModel); //assert Assert.IsNotNull(result); Assert.AreEqual(gameModel.GameId, result.GameId); Assert.AreEqual(gameModel.GameState, result.GameState); //clean up gameDAO.Delete(result.GameId); }
public void FindGame_Success() { //arrange //----make a game model Game gameModel = new Game() { GameState = GameState.Abandoned }; //----make gameDAO GameDAO gameDAO = new GameDAO(); //----create game from gameModel and save as gameToBeFound Game gameToBeFound = gameDAO.Create(gameModel); //act Game foundGame = gameDAO.Find(gameToBeFound.GameId); //assert Assert.AreEqual(gameToBeFound.GameId, foundGame.GameId); Assert.AreEqual(gameToBeFound.GameState, foundGame.GameState); //clean up gameDAO.Delete(foundGame.GameId); }
public void UpdateGame_Success() { //arrange //----make a game model Game gameModel = new Game() { GameState = GameState.Abandoned }; //----make gameDAO GameDAO gameDAO = new GameDAO(); //----create game from gameModel and save as gameToBeFound Game gameToBeUpdated = gameDAO.Create(gameModel); //----update gameModel to be reused to update updatedGame gameModel.GameState = GameState.Draw; //act Game updatedGame = gameDAO.Update(gameModel); //assert Assert.AreEqual(gameModel.GameId, updatedGame.GameId); Assert.AreEqual(gameModel.GameState, updatedGame.GameState); //clean up gameDAO.Delete(updatedGame.GameId); }