public void StoreQuestionToUsersAnswersTest() { model.GetListOfQuestionsByQuiz("Test Quiz"); var currentQuestion = model.AvailableQuestionsByNumber.First().Value; model.CurrentAnswers = currentQuestion.Answers.ToList(); model.CurrentAnswers.First().IsSelected = true; model.StoreQuestionToUsersAnswers(currentQuestion); Assert.AreEqual(model.UsersAnswers.First().Key, currentQuestion); }
//GET: Question Page public ActionResult Question(TakeQuizViewModel model, string QuizName) { model.CurrentQuiz = Session["CurrentQuiz"] as Quiz; if (model.CurrentAnswers == null) { model.GetListOfQuestionsByQuiz(QuizName); model.CurrentQuestion = model.GetRandomQuestion(); model.CurrentAnswers = model.CurrentQuestion.Answers.ToList(); model.UsersAnswers = new Dictionary <Question, Answer>(); Session["CurrentQuestion"] = model.CurrentQuestion; Session["CurrentAnswers"] = model.CurrentAnswers; Session["AvailableQuestions"] = model.AvailableQuestionsByNumber; Session["UsersAnswers"] = model.UsersAnswers; } model.CurrentQuestion = Session["CurrentQuestion"] as Question; model.AvailableQuestionsByNumber = Session["AvailableQuestions"] as Dictionary <int, Question>; model.UsersAnswers = Session["UsersAnswers"] as Dictionary <Question, Answer>; if (model.CurrentAnswers.Any(x => x.IsSelected == true) && model.AvailableQuestionsByNumber.Count != 0) { model.StoreQuestionToUsersAnswers(model.CurrentQuestion); Session["UsersAnswers"] = model.UsersAnswers; model.RemoveQuestionFromAvailableList(model.CurrentQuestion); if (model.AvailableQuestionsByNumber.Count != 0) { model.CurrentQuestion = model.GetRandomQuestion(); model.CurrentAnswers = model.CurrentQuestion.Answers.ToList(); Session["CurrentQuestion"] = model.CurrentQuestion; Session["CurrentAnswers"] = model.CurrentAnswers; } foreach (var item in model.CurrentAnswers) { item.IsSelected = false; } } if (model.AvailableQuestionsByNumber.Count != 0) { return(View(model)); } else { model.UsersAnswers = Session["UsersAnswers"] as Dictionary <Question, Answer>; model.CheckUsersAnswers(model.UsersAnswers); Session["UsersAnswers"] = model.UsersAnswers; return(RedirectToAction("QuizFinish", model)); } }