Exemplo n.º 1
0
        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]);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void PMGetAPlayerScoreTest()
        {
            // Test parameters
            string testName = "Zelda";
            bool testStatus = true;
            int testNumScores = 4,
                testScoreRet = 0;
            List<int> testScores = new List<int>() { 45, 10, 8, 4, 0 };    // Test score ArrayList
            Player newPlayer = new Player(testName, testStatus,
                                        testNumScores, testScores);

            PlayerManager testPlayMngr = new PlayerManager();

            // Use a For loop to check each value
            for (int i = 0; i < testNumScores; i++)
            {
                testScoreRet = testPlayMngr.GetAPlayerScore(newPlayer, i);
                Assert.AreEqual(testScores[i], testScoreRet);
            }
        }
Exemplo n.º 5
0
        public void PMGetNumberOfPlayerScoresTest()
        {
            // Test parameters
            string testName = "Zelda";
            bool testStatus = true;
            int testNumScores = 4,
                testNumScoreRet = 0;
            List<int> testScores = new List<int>() { 45, 10, 8, 4, 0 };    // Test score ArrayList
            Player newPlayer = new Player(testName, testStatus,
                                        testNumScores, testScores);

            PlayerManager testPlayMnger = new PlayerManager();

            testNumScoreRet = testPlayMnger.GetNumberOfPlayerScores(newPlayer);

            Assert.AreEqual(testNumScores, testNumScoreRet);
        }
Exemplo n.º 6
0
        public void PMDeletePlayerTest()
        {
            bool testDelete = false;

            // Test Parameters
            string deleteName = "Bunny",
                   testName = "Hugh",
                   testName2 = "Randall";
            List<int> tinkleScores = new List<int>() { 2, 6, 9, 90 };
            List<int> testScores = new List<int>() { 45, 87, 99 };
            List<int> testScores2 = new List<int>() { 5, 6, 7, 8 };

            Player deletePlayer = new Player(deleteName, false, 4, tinkleScores);
            Player testPlayer1 = new Player(testName, false, 3, testScores);
            Player testPlayer2 = new Player(testName2, false, 4, testScores2);

            PlayerManager testPlayMngr = new PlayerManager();

            // Add players to DB for
            testPlayMngr.SavePlayer(testPlayer1, testName);
            testPlayMngr.SavePlayer(deletePlayer, deleteName);
            testPlayMngr.SavePlayer(testPlayer2, testName2);

            // Delete testPlayer and test return value
            testDelete = testPlayMngr.DeletePlayerData(deleteName);

            Assert.IsTrue(testDelete);
        }
Exemplo n.º 7
0
        private void SavePlayerAction()
        {
            // Save player data if player is loaded //
            bool saveGood = false;
            if ((this.PlayerNameTextBox.Text.Length > 0) && (Session["Player"] != null))
            {
                // Get player object from session
                GamePlayer = (Player)Session["Player"];

                PlayerManager playerManager = new PlayerManager();
                saveGood = playerManager.SavePlayer(GamePlayer, GamePlayer.PlayerName);

                // Report save status to message window
                if (saveGood)
                {
                    this.FeedbackListBox.Items.Add(GamePlayer.PlayerName + " saved = " + saveGood);
                }
                else
                {
                    this.FeedbackListBox.Items.Add("Player save failed");
                }
            }
            else
            {
                this.FeedbackListBox.Items.Add("No player to save!");
            }
        }
Exemplo n.º 8
0
        // 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 = "";
            }
        }
Exemplo n.º 9
0
        private void FillScoreList(Player GamePlayer)
        {
            // Create Player Manager
            PlayerManager playerManager = new PlayerManager();

            // Clear current scores to populate in order
            this.ScoreListBox.Items.Clear();

            // Load player scores from object
            if (GamePlayer.NumberOfScores > 0)
            {

                for (int i = 0; i < GamePlayer.NumberOfScores; i++)
                {
                    this.ScoreListBox.Items.Add(playerManager.GetAPlayerScore(GamePlayer, i).ToString());
                }
            }

            // Change label to reflect player name
            this.ScoreListLabel.Text = "Top Scores for " + GamePlayer.PlayerName + "!";
        }
Exemplo n.º 10
0
        private void DeletePlayerAction()
        {
            // Use PlayerManager to delete selected Player object
            // Use Manager to load player data

            // Retrieve session object if available
            if (Session["Player"] != null)
                GamePlayer = (Player)Session["Player"];

            PlayerManager playerManager = new PlayerManager();
            if ((this.PlayerNameTextBox.Text.Length > 0) && (GamePlayer != null))
            {
                if (GamePlayer.PlayerName == this.PlayerNameTextBox.Text)
                {
                    if (playerManager.DeletePlayerData(this.EnteredNameTextBox.Text))
                    {
                        // Clear Entered Text box
                        ClearForm();
                        this.FeedbackListBox.Items.Add(EnteredNameTextBox.Text + " deleted!");
                        this.EnteredNameTextBox.Text = "";
                        this.PlayerNameTextBox.Text = "";
                        Session.Remove("Player");
                    }
                }
                else
                {
                    this.FeedbackListBox.Items.Add("Loaded player mismatch!");
                }

            }
            else
                this.FeedbackListBox.Items.Add("Plaer not loaded, delete aborted"); ;
        }