public void PMCreatePlayerTest() { // Create file and data for testing // Test parameters string testName = "Zelda"; bool testStatus = true; int testNumScores = 4; Player testPlayer = new Player(); PlayerManager testManager = new PlayerManager(); List<int> testScores = new List<int>() { 60, 32, 15, 4}; // Test score ArrayList Player newPlayer = new Player(testName, testStatus, testNumScores, testScores); Factory testFactory = Factory.GetInstance(); IPlayerSvc testSVC = (IPlayerSvc) testFactory.GetService(typeof(IPlayerSvc).Name); // Create file for test try { testSVC.SavePlayerToDb(newPlayer); } catch (IOException e) { Console.WriteLine(e.Message); Assert.Fail("Unable to create test file"); } // Create new player using business manager try { testPlayer = testManager.LoadPlayer(testName); } catch (IOException e) { Console.WriteLine(e.Message); Assert.Fail("Unable to create player!"); } //Test if player data has been loaded Assert.AreEqual(testPlayer.PlayerName, testName); Assert.AreEqual(testPlayer.GameStatus, testStatus); Assert.AreEqual(testPlayer.NumberOfScores, testNumScores); //Test arbitrary list value // Sort test array first testScores.Sort(); Assert.AreEqual(testPlayer.ScoreList[1], testScores[1]); }
public void PMCreateNewPlayerTest() { string fileName = "Tinker"; // File name for test that does not exist Player testPlayer = new Player(); PlayerManager testManager = new PlayerManager(); // Create player object from file try { testPlayer = testManager.LoadPlayer(fileName); } catch (PlayerNotFoundException) { Console.WriteLine("Caught Exception in Test"); } finally { //Test if player is created based on input filename //If the exception is caught and handled, it should //Create a new player with the specified name Assert.AreEqual(testPlayer.PlayerName, fileName); } }
public void PMSavePlayerTest() { // Create player for testing // Test parameters string testName = "Link"; bool testStatus = false, SaveGood = false; int testNumScores = 2; PlayerManager testManager; List<int> testScores = new List<int>() { 99, 23 }; // Test score ArrayList Player newPlayer = new Player(testName, testStatus, testNumScores, testScores); // Try to save Player using Manager testManager = new PlayerManager(); try { SaveGood = testManager.SavePlayer(newPlayer, testName); } catch (IOException e) { Console.WriteLine(e.Message); Assert.Fail("Unable to create player object"); } //Test if player was saved to database //Create compare player using database Player comparePlayer = null; comparePlayer = testManager.LoadPlayer(testName); Assert.AreEqual(testName, comparePlayer.PlayerName); Assert.IsTrue(SaveGood); }
// Methods for game functions // private void LoadPlayerAction() { if (this.EnteredNameTextBox.Text.Length > 0) { // Update play field this.PlayerNameTextBox.Text = this.EnteredNameTextBox.Text; // Use Manager to load player data PlayerManager playerManager = new PlayerManager(); GamePlayer = playerManager.LoadPlayer(this.PlayerNameTextBox.Text); // Load player scores from object FillScoreList(GamePlayer); // Check to see if player is already stored in session object // remove if necessary if (Session["Player"] != null) Session.Remove("Player"); // Store player object in Session Session["Player"] = GamePlayer; // Update Message Window if (GamePlayer.PlayerName.Length > 0) { this.FeedbackListBox.Items.Add(GamePlayer.PlayerName + " loaded!"); } } else { this.FeedbackListBox.Items.Add("Load Player Aborted! Name was blank."); // Clear name from play filed if aborted this.PlayerNameTextBox.Text = ""; } }