[TestMethod] // TestMethod attribute public void ReadAllGamingCenter() { //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 ReadAllGamers() and save returned list List <GamingCenter> list = db.ReadAllGamingCenter(); //Verify list is NOT empty Assert.IsTrue(list.Count > 0); //Foreach gamer foreach (GamingCenter gamer in list) { //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 foreach } // end using } // end method ReadAllGamingCenter()
} // end method GetGameTypeOptions() //The Index method //Purpose: To connect to the DAL, pull all records from the database and convert them to GamingModel objects //Parameters: None //Return: The gaming list in the form of a View, or a 500 error if connection or data doesn't exist // GET: Gaming public ActionResult Index() { //Create a list of GamingModel objects List <GamingModel> gamingList = new List <GamingModel>(); try { //Create instance of DAL, and pass connection string by calling ConnectionString property using (GamingCenterDirectoryDB db = new GamingCenterDirectoryDB(ConnectionString)) { //Foreach GamingCenter object in the database foreach (GamingCenter dbGaming in db.ReadAllGamingCenter()) { //Get the db data members, and save as GamingModel data members GamingModel gamingModel = new GamingModel() { Id = dbGaming.Id.ToString(), FirstName = dbGaming.FirstName, LastName = dbGaming.LastName, UserID = dbGaming.UserID, GameType = dbGaming.GameType.ToString(), ItemType = dbGaming.ItemType.ToString(), IsUVUStudent = dbGaming.IsUVUStudent, Date = dbGaming.Date, GameTypeOptions = GetGameTypeOptions(), ItemTypeOptions = GetItemTypeOptions() }; // end initialize GamingModel //Add this model to the list gamingList.Add(gamingModel); } // end foreach } // 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(gamingList)); } // end method Index()