//update ProfileProgress to a new map public void NewMap() { if (User.Identity.IsAuthenticated) { ProfileProgress p = _progress.Get((int)Session["profileID"]); Random random = new Random(); int newAnimal = random.Next(1, 21); //generate a number between 1 and 20 //if user is a new user, add a map and animal to save to ProfileProgress if (p.AnimalID == 0) { _progress.AddProfileProgress((int)Session["profileID"], newAnimal); } //if user hasn't reached last map, go to next map else if (p.CurrentMap < LAST_MAP) { _progress.RescueAnimal((int)Session["profileID"], p.AnimalID); //save animal to ProfileAnimals _progress.UpdateCurrentMap((int)Session["profileID"], p.CurrentMap, newAnimal); //new map and animal } else //pass in FIRST_MAP - 1 so increment in UpdateCurrentMap function will increment to MapID = 1 { _progress.RescueAnimal((int)Session["profileID"], p.AnimalID); //save animal to ProfileAnimals _progress.UpdateCurrentMap((int)Session["profileID"], (FIRST_MAP - 1), newAnimal); //return to map1 } } else //free play mode { if ((int)Session["fp_animalID"] == NUM_ANIMALS) { Session["fp_animalID"] = 1; } else { Session["fp_animalID"] = (int)Session["fp_animalID"] + 1; //go to next animal } Session["fp_nodeID"] = 1; //reset to first node //if user hasn't reached last map, go to next map if ((int)Session["fp_mapID"] < LAST_MAP) { Session["fp_mapID"] = (int)Session["fp_mapID"] + 1; } else { Session["fp_mapID"] = 1; //return to first map } } }
public void IncrementMapTest() { //get profile progress from ProfileProgress table for profile by ProfileID ProfileProgress p = _progress.Get(profileID); Random random = new Random(); int newAnimal = random.Next(1, 21); //generate a number between 1 and 20 for animal to rescue int savedAnimal = p.AnimalID; //id of saved animal int verifySavedAnimal = 0; //id of saved animal from database int verifyNewMap = 0; //id of new map from database //if user hasn't reached last map, go to next map if (p.CurrentMap < LAST_MAP) { _progress.RescueAnimal(profileID, p.AnimalID); //save animal to ProfileAnimals _progress.UpdateCurrentMap(profileID, p.CurrentMap, newAnimal); //new map and animal } //Query database to retrieve recently saved AnimalID from ProfileAnimals by AnimalID and ProfileID using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = connection; cmd.CommandText = "SELECT * FROM ProfileAnimals WHERE ProfileID=@ProfileID AND AnimalID=@AnimalID"; cmd.Parameters.AddWithValue("@ProfileID", profileID); cmd.Parameters.AddWithValue("@AnimalID", savedAnimal); cmd.Connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { verifySavedAnimal = (int)reader["AnimalID"]; } } } } //requery database for new current map p = _progress.Get(profileID); verifyNewMap = p.CurrentMap; //reset AnimalID and MapID values back to original //pass in mapID = 0 so will be incremented back to 1 _progress.UpdateCurrentMap(profileID, (FIRST_MAP - 1), animalID); //check that AnimalID from database is same as saved AnimalID Assert.AreEqual(savedAnimal, verifySavedAnimal); //check that new MapID is one higher than original MapID Assert.AreEqual((mapID + 1), verifyNewMap); }