Пример #1
0
        [TestMethod] // TestMethod attribute
        public void UpdateGamer()
        {
            //Call ConfigMgr to get connection string, and save it
            string connectionString =
                ConfigurationManager.ConnectionStrings["GamingCenterDBConnectionString"].ConnectionString;

            //Create new GCDB object using connString, and open connection
            using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(connectionString))
            {
                //Create new GamingCenter object and initialize given values
                GamingCenter gamer = new GamingCenter()
                {
                    Id           = -1, // database will re-populate id
                    FirstName    = "Monkey",
                    LastName     = "McTester",
                    UserID       = "9999999",
                    GameType     = GameType.Foos,
                    ItemType     = ItemType.Ball,
                    IsUVUStudent = true,
                    Date         = new DateTime(2015, 2, 2)
                }; // end constructor

                //Create gamer entry
                db.CreateGamer(gamer);

                //Verify Id is NOT negative
                Assert.IsTrue(gamer.Id > 0);

                //Change all properties to different values
                gamer.FirstName    = "Champ";
                gamer.LastName     = "Awesometon";
                gamer.UserID       = "1010101";
                gamer.GameType     = GameType.PS4;
                gamer.ItemType     = ItemType.Generic;
                gamer.IsUVUStudent = false;
                gamer.Date         = new DateTime(2000, 10, 10);

                //Update the entry
                db.UpdateGamer(gamer);

                //Read gamer back in and verify changes were made
                GamingCenter gamerCopy = db.ReadGamer(gamer.Id);
                Assert.AreEqual(gamer.FirstName, gamerCopy.FirstName);
                Assert.AreEqual(gamer.LastName, gamerCopy.LastName);
                Assert.AreEqual(gamer.UserID, gamerCopy.UserID);
                Assert.AreEqual(gamer.GameType, gamerCopy.GameType);
                Assert.AreEqual(gamer.ItemType, gamerCopy.ItemType);
                Assert.AreEqual(gamer.IsUVUStudent, gamerCopy.IsUVUStudent);
                Assert.AreEqual(gamer.Date, gamerCopy.Date);
            } // end using
        }     // end method UpdateGamer()
Пример #2
0
        }         // end method POST Edit()

        //The Delete method - GET
        //Purpose: To connect to the DAL and get gamer with specified id from database
        //Parameters: An int represented as _id - Value pulled from URI
        //Return: The gamingModel View in the form of an ActionResult, or status code "NOT FOUND" for no gamer w/ id, or 500 error for all other
        // GET: Gaming/Delete/5
        public ActionResult Delete(int id)
        {
            //Create GamingModel instance and initialize to null
            GamingModel gamingModel = null;

            try
            {
                //Create instance of DAL, and pass connection string by calling ConnectionString property
                using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(ConnectionString))
                {
                    //Get GamingCenter object with specified _id, and save
                    GamingCenter dbGamer = db.ReadGamer(id);

                    //If gamer cannot be found
                    if (dbGamer == null)
                    {
                        //Return 404 - Not found status code
                        return(new HttpStatusCodeResult(
                                   HttpStatusCode.NotFound,
                                   string.Format("Gamer with id={0} unknown", id)));
                    } // end if

                    //Save dbGamer data members as GamingModel object data members
                    gamingModel = new GamingModel()
                    {
                        Id              = dbGamer.Id.ToString(),
                        FirstName       = dbGamer.FirstName,
                        LastName        = dbGamer.LastName,
                        UserID          = dbGamer.UserID.ToString(),
                        GameType        = dbGamer.GameType.ToString(),
                        ItemType        = dbGamer.ItemType.ToString(),
                        IsUVUStudent    = dbGamer.IsUVUStudent,
                        Date            = dbGamer.Date, // ToString()
                        GameTypeOptions = GetGameTypeOptions(),
                        ItemTypeOptions = GetItemTypeOptions()
                    }; // end initialize GamingModel
                } // end using
            } // end try
            catch (Exception)
            {
                //Return a HttpStatusCodeResult object, and set status code as 500 (InternalServerError) and pass string to print
                return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "Internal Server Error "));
            } // end catch

            return(View(gamingModel));
        } // end method GET Delete()
Пример #3
0
        [TestMethod] // TestMethod attribute
        public void ReadGamer()
        {
            //Call ConfigMgr to get connection string, and save it
            string connectionString =
                ConfigurationManager.ConnectionStrings["GamingCenterDBConnectionString"].ConnectionString;

            //Create new GCDB object using connString, and open connection
            using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(connectionString))
            {
                //Call ReadGamer with id of 1, and save returned gamer object
                GamingCenter gamer = db.ReadGamer(1);

                //Verify gamer EXISTS
                Assert.IsNotNull(gamer);

                //Verify gamer's FirstName is NOT null
                Assert.IsFalse(string.IsNullOrEmpty(gamer.FirstName));

                //Write First & LastName to console
                Console.WriteLine("{0} {1}", gamer.FirstName, gamer.LastName);
            } // end using
        }     // end method ReadGamer()
Пример #4
0
        [TestMethod] // TestMethod attribute
        public void DeleteGamer()
        {
            //Call ConfigMgr to get connection string, and save it
            string connectionString =
                ConfigurationManager.ConnectionStrings["GamingCenterDBConnectionString"].ConnectionString;

            //Create new GCDB object using connString, and open connection
            using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(connectionString))
            {
                //Create new GamingCenter object and initialize given values
                GamingCenter gamer = new GamingCenter()
                {
                    Id           = -1, // database will re-populate id
                    FirstName    = "Ender",
                    LastName     = "Gameless",
                    UserID       = "1111111",
                    GameType     = GameType.Pong,
                    ItemType     = ItemType.PongSet,
                    IsUVUStudent = false,
                    Date         = new DateTime(2009, 4, 11)
                }; // end constructor

                //Create gamer entry
                db.CreateGamer(gamer);

                //Verify Id is NOT negative
                Assert.IsTrue(gamer.Id > 0);

                //Delete the entry
                db.DeleteGamer(gamer.Id);

                //Get the recently deleted gamer
                GamingCenter gamerOld = db.ReadGamer(gamer.Id);

                //Verify the entry is null
                Assert.IsTrue(gamerOld == null);
            } // end using
        }     // end method DeleteGamer()