public void ReturnExamTest() { /* Setup user data */ int userInfoId = 1; var user = UserServiceTest.GetUser(userInfoId, UserType.Student); /* Setup answer data*/ var levelExamAnswer1 = new LevelExamAnswer(); levelExamAnswer1.LevelExamAnswerId = 1; levelExamAnswer1.LevelExamQuestionId = 1; levelExamAnswer1.Correct = true; levelExamAnswer1.UserInfoes.Add(user); var levelExamAnswer2 = new LevelExamAnswer(); levelExamAnswer2.LevelExamAnswerId = 2; levelExamAnswer2.LevelExamQuestionId = 2; levelExamAnswer2.Correct = true; levelExamAnswer2.UserInfoes.Add(user); var levelExamAnswer3 = new LevelExamAnswer(); levelExamAnswer3.LevelExamAnswerId = 3; levelExamAnswer3.LevelExamQuestionId =3; levelExamAnswer3.Correct = true; levelExamAnswer3.UserInfoes.Add(user); var levelExamAnswer4 = new LevelExamAnswer(); levelExamAnswer4.LevelExamAnswerId = 4; levelExamAnswer4.LevelExamQuestionId = 4; levelExamAnswer4.Correct = true; levelExamAnswer4.UserInfoes.Add(user); var levelExamAnswer5 = new LevelExamAnswer(); levelExamAnswer5.LevelExamAnswerId = 5; levelExamAnswer5.LevelExamQuestionId = 5; levelExamAnswer5.Correct = true; levelExamAnswer5.UserInfoes.Add(user); /* Setup level exam question data */ var levelExamQuestion1 = new LevelExamQuestion(); levelExamQuestion1.LevelExamQuestionId = 1; levelExamQuestion1.LevelExamAnswers.Add(levelExamAnswer1); var levelExamQuestion2 = new LevelExamQuestion(); levelExamQuestion2.LevelExamQuestionId = 2; levelExamQuestion2.LevelExamAnswers.Add(levelExamAnswer2); var levelExamQuestion3 = new LevelExamQuestion(); levelExamQuestion3.LevelExamQuestionId = 3; levelExamQuestion3.LevelExamAnswers.Add(levelExamAnswer3); var levelExamQuestion4 = new LevelExamQuestion(); levelExamQuestion4.LevelExamQuestionId = 4; levelExamQuestion4.LevelExamAnswers.Add(levelExamAnswer4); var levelExamQuestion5 = new LevelExamQuestion(); levelExamQuestion5.LevelExamQuestionId = 5; levelExamQuestion5.LevelExamAnswers.Add(levelExamAnswer5); var levelExamQuestion6 = new LevelExamQuestion(); levelExamQuestion6.LevelExamQuestionId = 6; var levelExamQuestion7 = new LevelExamQuestion(); levelExamQuestion7.LevelExamQuestionId = 7; var levelExamQuestion8 = new LevelExamQuestion(); levelExamQuestion8.LevelExamQuestionId = 8; var levelExamQuestion9 = new LevelExamQuestion(); levelExamQuestion9.LevelExamQuestionId = 9; var levelExamQuestion10 = new LevelExamQuestion(); levelExamQuestion10.LevelExamQuestionId = 10; /* Setup levelexam data */ var levelExamData = new FakeObjectSet<LevelExam>(); var levelExam = new LevelExam(); levelExam.LevelExamId = 1; levelExam.Stop = DateTime.Now.AddDays(1); levelExam.LevelExamQuestions.Add(levelExamQuestion1); levelExam.LevelExamQuestions.Add(levelExamQuestion2); levelExam.LevelExamQuestions.Add(levelExamQuestion3); levelExam.LevelExamQuestions.Add(levelExamQuestion4); levelExam.LevelExamQuestions.Add(levelExamQuestion5); levelExam.LevelExamQuestions.Add(levelExamQuestion6); levelExam.LevelExamQuestions.Add(levelExamQuestion7); levelExam.LevelExamQuestions.Add(levelExamQuestion8); levelExam.LevelExamQuestions.Add(levelExamQuestion9); levelExam.LevelExamQuestions.Add(levelExamQuestion10); levelExamData.AddObject(levelExam); /* Setup level data */ var level = new Level(); level.LevelExams.Add(levelExam); /* Setup course data */ var course = new Course(); course.UserInfoes.Add(user); course.Levels.Add(level); /* Setup the mock expectations */ _mockRepository.Expect(x => x.LevelExams).Return(levelExamData); _mockRepository.Expect(x => x.LevelExamResults).Return(new FakeObjectSet<LevelExamResult>()); /* Test the business logic */ var actual = _levelService.ReturnExam(1, 1); /* Assert */ Assert.AreEqual(5, actual); }
public void GetUserQuestionAnswerTest() { /* Setup user data */ int userInfoId = 1; var userData = new FakeObjectSet<UserInfo>(); var user = UserServiceTest.GetUser(userInfoId, UserType.Student); userData.AddObject(user); /* Setup levelexamanswer data */ var answerData = new FakeObjectSet<LevelExamAnswer>(); var levelExamAnswer = new LevelExamAnswer(); levelExamAnswer.LevelExamAnswerId = 1; levelExamAnswer.LevelExamQuestionId = 1; levelExamAnswer.UserInfoes.Add(user); var levelExamAnswerNumberTwo = new LevelExamAnswer(); levelExamAnswerNumberTwo.LevelExamAnswerId = 2; levelExamAnswerNumberTwo.LevelExamQuestionId = 1; answerData.AddObject(levelExamAnswer); answerData.AddObject(levelExamAnswerNumberTwo); /* Setup levelexamquestion data*/ var questionData = new FakeObjectSet<LevelExamQuestion>(); var levelExamQuestion = new LevelExamQuestion(); levelExamQuestion.LevelExamQuestionId = 1; levelExamQuestion.LevelExamAnswers.Add(levelExamAnswer); levelExamQuestion.LevelExamAnswers.Add(levelExamAnswerNumberTwo); questionData.AddObject(levelExamQuestion); /* Setup the mock expectations */ _mockRepository.Expect(x => x.LevelExamQuestions).Return(questionData); /* Test the business logic */ var actualOne = _levelService.GetUserQuestionAnswer(1, userInfoId); var actualTwo = _levelService.GetUserQuestionAnswer(1, userInfoId+1); /* Assert */ Assert.AreEqual(levelExamAnswer.LevelExamAnswerId, actualOne); Assert.AreEqual(-1, actualTwo); /* Verify all the mock calls */ _mockRepository.VerifyAllExpectations(); }
public void AnswerLevelExamQuestionTest() { /* Setup user data */ int userInfoId = 1; var userData = new FakeObjectSet<UserInfo>(); var user = UserServiceTest.GetUser(userInfoId, UserType.Student); userData.AddObject(user); /* Setup levelexamanswer data */ var answerData = new FakeObjectSet<LevelExamAnswer>(); var levelExamAnswer = new LevelExamAnswer(); levelExamAnswer.LevelExamAnswerId = 1; levelExamAnswer.LevelExamQuestionId = 1; levelExamAnswer.UserInfoes.Add(user); var levelExamAnswerNumberTwo = new LevelExamAnswer(); levelExamAnswerNumberTwo.LevelExamAnswerId = 2; levelExamAnswerNumberTwo.LevelExamQuestionId = 1; answerData.AddObject(levelExamAnswer); answerData.AddObject(levelExamAnswerNumberTwo); /* Setup levelexamquestion data*/ var questionData = new FakeObjectSet<LevelExamQuestion>(); var levelExamQuestion = new LevelExamQuestion(); levelExamQuestion.LevelExamQuestionId = 1; levelExamQuestion.LevelExamAnswers.Add(levelExamAnswer); levelExamQuestion.LevelExamAnswers.Add(levelExamAnswerNumberTwo); questionData.AddObject(levelExamQuestion); /* Setup the mock expectations */ _mockRepository.Expect(x => x.UserInfoes).Return(userData); _mockRepository.Expect(x => x.LevelExamAnswers).Return(answerData); _mockRepository.Expect(x => x.LevelExamQuestions).Return(questionData); _mockRepository.Expect(x => x.SaveChanges()).Return(1); /* Test the business logic */ _levelService.AnswerLevelExamQuestion(1, userInfoId); _levelService.AnswerLevelExamQuestion(2,userInfoId); /* Verify all the mock calls */ _mockRepository.VerifyAllExpectations(); }
/// <summary> /// Creates a LevelExamAnswer /// </summary> /// <param name="levelExamAnswer">Levelexamanswer instance</param> public void CreateLevelExamAnswer(LevelExamAnswer levelExamAnswer) { if (levelExamAnswer != null) { GameSchoolEntities.LevelExamAnswers.AddObject(levelExamAnswer); Save(); } }
public ActionResult ExamAnswer(LevelExamAnswer model) { if (model!=null) { if (model.LevelExamQuestionId == 0) return RedirectToAction("NotFound", "Home"); LevelService.CreateLevelExamAnswer(model); var item = LevelService.GetLevelExamQuestion(model.LevelExamQuestionId); return RedirectToAction("ExamQuestions", "Exam", new {id = item.LevelExamId}); } return RedirectToAction("NotFound", "Home"); }
public ActionResult Question(LevelExamAnswer model) { if (model != null) { var user = MembershipHelper.GetUser(); if (model.LevelExamAnswerId != 0) { LevelService.AnswerLevelExamQuestion(model.LevelExamAnswerId, user.UserInfoId); } var nextQuestion = LevelService.GetNextLevelExamQuestion(model.LevelExamQuestionId); if (nextQuestion == null) { var examQuestion = LevelService.GetLevelExamQuestion(model.LevelExamQuestionId); var firstQuestion = LevelService.GetFirstQuestionByExamId(examQuestion.LevelExamId); return RedirectToAction("Question", "Exam", new { id = firstQuestion.LevelExamQuestionId }); } return RedirectToAction("Question", "Exam", new {id = nextQuestion.LevelExamQuestionId}); } return RedirectToAction("NotFound", "Home"); }