public static Player CreateNewPlayer(string name, IPlayerDataMapper playerDataMapper = null) { // If a PlayerDataMapper was not passed in, use a real one. // This allows us to pass in a "mock" PlayerDataMapper (for testing), // but use a real PlayerDataMapper, when running the program. if (null == playerDataMapper) { playerDataMapper = new PlayerDataMapper(); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Player name cannot be empty"); } // Throw an exception if there is already a player with this name in the database. if (playerDataMapper.PlayerNameExistInDatabase(name)) { throw new ArgumentException("Player name already exists."); } // Add the player to the database. playerDataMapper.InsertNewPlayerIntoDatabase(name); return(new Player(name, 0, 10)); }
public static Player CreateNewPlayer(string name, IPlayerDataMapper playerDataMapper = null) { if (playerDataMapper == null) { playerDataMapper = new PlayerDataMapper(); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("Player name cannot be empty."); } if (playerDataMapper.PlayerNameExistsInDatabase(name)) { throw new ArgumentException("Player name already exists."); } playerDataMapper.InsertNewPlayerIntoDatabase(name); return(new Player(name, 0, 10)); }
public static Player CreateNewPlayer(string name, IPlayerDataMapper playerDataMapper = null) { if (playerDataMapper == null) { playerDataMapper = new PlayerDataMapper(); } if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("PLayer name cannot be empty"); } // Throw an exception if there is already a player with this name in the database. if (playerDataMapper.PlayerNameExistsInDatabase(name)) { throw new ArgumentException("Player name already exists."); } // Add the player to the database. playerDataMapper.InsertNewPlayerIntoDatabase(name); return(new Player(name, 0, 10)); }
private void button1_Click(object sender, EventArgs e) { IPlayerDataMapper dataMapper = null; Player player = Player.CreateNewPlayer("Eric", dataMapper); }