//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 AddProfileProgressTest() { int UserID = 1; string ProfileName = "Test"; int ProfileID = 0; //Create a new profile using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("proc_AddNewProfile", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@UserID", UserID); cmd.Parameters.AddWithValue("@AvatarID", 1); cmd.Parameters.AddWithValue("@ProfileName", ProfileName); connection.Open(); cmd.ExecuteNonQuery(); } } //Query database to retrieve ProfileID of new profile using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = connection; cmd.CommandText = "SELECT * FROM Profiles WHERE UserID=@UserID AND ProfileName=@ProfileName"; cmd.Parameters.AddWithValue("@UserID", UserID); cmd.Parameters.AddWithValue("@ProfileName", ProfileName); cmd.Connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { ProfileID = (int)reader["ProfileID"]; } } } } //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 //if user is a new user, add a map and animal to save to ProfileProgress if (p.AnimalID == 0) { _progress.AddProfileProgress(ProfileID, newAnimal); } p = _progress.Get(ProfileID); //get profile progress again //Delete added profile from database using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Aura"].ConnectionString)) { using (SqlCommand cmd = new SqlCommand("proc_DeleteProfile", connection)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@ProfileID", ProfileID); connection.Open(); cmd.ExecuteNonQuery(); } } //check that AnimalID is equal to random number generated for AnimalID Assert.AreEqual(newAnimal, p.AnimalID); //check that MapID is equal to 1 Assert.AreEqual(1, p.CurrentMap); }