/// <summary> /// Persist a levelexam instance object to the datasource. /// </summary> /// <param name="levelExam">A levelexam persist.</param> public void CreateLevelExam(LevelExam levelExam) { if (levelExam != null) { levelExam.CreateDateTime = DateTime.Now; GameSchoolEntities.LevelExams.AddObject(levelExam); Save(); } }
public void HasAccessToExamTest() { /* Setup user data */ int userInfoId = 1; var user = UserServiceTest.GetUser(userInfoId, UserType.Student); /* Setup levelexam data */ var levelExamData = new FakeObjectSet<LevelExam>(); var levelExam = new LevelExam(); levelExam.LevelExamId = 1; levelExam.Stop = DateTime.Now.AddDays(1); 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); /* Test the business logic */ var actual = _levelService.HasAccessToExam(levelExam.LevelExamId, userInfoId); var shouldfailactual = _levelService.HasAccessToExam(levelExam.LevelExamId, userInfoId+1); /* Assert */ Assert.AreEqual(true, actual); Assert.AreEqual(false, shouldfailactual); /* Verify all the mock calls */ _mockRepository.VerifyAllExpectations(); }
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); }
/// <summary> /// Updates a levelexam. /// </summary> /// <param name="levelExam">Levelexam instance to update.</param> public void UpdateLevelExam(LevelExam levelExam) { if (levelExam != null) { Save(); } }
public ActionResult Edit(LevelExam model) { var exam = LevelService.GetLevelExam(model.LevelExamId); ViewBag.Levels = new SelectList(LevelService.GetLevels(exam.Level.CourseId), "LevelId", "Name"); ViewBag.GradePercentageValue = GetPercentageValue(); if (ModelState.IsValid) { var levelExam = LevelService.GetLevelExam(model.LevelExamId); if (TryUpdateModel(levelExam)) { LevelService.UpdateLevelExam(levelExam); ViewBag.SuccessMessage = "Upplýsingar um próf hafa verið uppfærðar"; return View(levelExam); } } ViewBag.ErrorMessage = "Náði ekki að skrá/uppfæra upplýsingar! Lagfærðu villur og reyndur aftur."; return View(model); }
public ActionResult Create(LevelExam levelExam) { if (ModelState.IsValid) { LevelService.CreateLevelExam(levelExam); return RedirectToAction("Edit", "Exam", new {id = levelExam.LevelExamId}); } return View(levelExam); }
public ActionResult Create(int? id) { if (id.HasValue) { ViewBag.GradePercentageValues = GetPercentageValue(); ViewBag.Levels = new SelectList(LevelService.GetLevels(id.Value), "LevelId", "Name"); ViewBag.CourseId = id.Value; ViewBag.CourseName = CourseService.GetCourse(id.Value).Name; ViewBag.Title = "Búa til nýtt próf"; LevelExam model = new LevelExam(); model.Start = DateTime.Now; model.Stop = DateTime.Now.AddDays(2); return View(model); } return RedirectToAction("NotFound", "Home"); }
private void FixupLevelExam(LevelExam previousValue) { if (previousValue != null && previousValue.LevelExamResults.Contains(this)) { previousValue.LevelExamResults.Remove(this); } if (LevelExam != null) { if (!LevelExam.LevelExamResults.Contains(this)) { LevelExam.LevelExamResults.Add(this); } if (LevelExamId != LevelExam.LevelExamId) { LevelExamId = LevelExam.LevelExamId; } } }