/// <summary> /// Gets a course instance through a parameter of this function and if it isn't null persist it to the database. /// </summary> /// <param name="course">Instance of a course</param> public void CreateCourse(Course course) { if (course != null) { course.CreateDateTime = DateTime.Now; GameSchoolEntities.Courses.AddObject(course); Save(); } }
public void UpdateCourse(Course course) { /*var query = GameSchoolEntities.Courses.Where(n => n.CourseId == course.CourseId); var courseToUpdate = query.FirstOrDefault(); courseToUpdate.Name = course.Name; courseToUpdate.Description = course.Description; courseToUpdate.Identifier = course.Identifier; courseToUpdate.CreditAmount = course.CreditAmount; courseToUpdate.DepartmentId = course.DepartmentId; courseToUpdate.Start = course.Start; courseToUpdate.Stop = course.Stop;*/ Save(); }
public void GetCoursesByUserInfoIdTest() { var mockRepository = MockRepository.GenerateMock<IGameSchoolEntities>(); var courseService = new CourseService(); courseService.SetDatasource(mockRepository); var expectedCourse = new Course(); expectedCourse.CourseId = 1; expectedCourse.CreateDateTime = DateTime.Now; expectedCourse.CreditAmount = 3; expectedCourse.DepartmentId = 1; expectedCourse.Description = "Daniel teaches extreme pole fitness programming"; expectedCourse.Name = "Extreme pole fitness programming"; expectedCourse.Start = DateTime.Now.AddMonths(-1); expectedCourse.Stop = DateTime.Now.AddMonths(2); //Fake user data var userData = new FakeObjectSet<UserInfo>(); var expected = new UserInfo(); expected.Fullname = "Davíð Einarsson"; expected.Email = "*****@*****.**"; expected.StatusId = 1; expected.Username = "******"; expected.UserInfoId = 1; userData.AddObject(expected); mockRepository.Expect(x => x.UserInfoes).Return(userData); //Fake course data var courseData = new FakeObjectSet<Course>(); expectedCourse.UserInfoes.Add(expected); expected.Courses.Add(expectedCourse); courseData.AddObject(expectedCourse); mockRepository.Expect(x => x.Courses).Return(courseData); var courses = courseService.GetCoursesByUserInfoId(expected.UserInfoId); Assert.AreEqual(courseData.FirstOrDefault().CourseId, courses.FirstOrDefault().CourseId); Assert.AreEqual(courses.Count(), 1); //mockRepository.VerifyAllExpectations(); }
private void FixupCourse(Course previousValue) { if (previousValue != null && previousValue.Points.Contains(this)) { previousValue.Points.Remove(this); } if (Course != null) { if (!Course.Points.Contains(this)) { Course.Points.Add(this); } if (CourseId != Course.CourseId) { CourseId = Course.CourseId; } } }
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); }
public void GetLevelProjectByUserIdTest_UserInfoCourseLevelLevelProject_CollectionOfLevelProjects() { var userInfoId = 7; var userData = new FakeObjectSet<UserInfo>(); var courseData = new FakeObjectSet<Course>(); var levelProjectData = new FakeObjectSet<LevelProject>(); var levelData = new FakeObjectSet<Level>(); LevelProject levelProject1 = new LevelProject { Stop = DateTime.Now.AddDays(7), Start = DateTime.Now, Name = "Verkefni", LevelProjectId = 1, ContentID = Guid.NewGuid(), Description = "Lýsing", GradePercentageValue = 5, LevelId = 1 }; LevelProject levelProject2 = new LevelProject { Stop = DateTime.Now.AddDays(7), Start = DateTime.Now, Name = "Verkefni2", LevelProjectId = 2, ContentID = Guid.NewGuid(), Description = "Lýsing2", GradePercentageValue = 1, LevelId = 1 }; UserInfo user1 = new UserInfo { Fullname = "Davíð Einarsson", Email = "*****@*****.**", StatusId = 1, Username = "******", UserInfoId = userInfoId, Password = "******" }; Course course = new Course { CourseId = 1, Name = "Vefforritun I", CreateDateTime = DateTime.Now, Identifier = "VEFF", Start = DateTime.Now, Stop = DateTime.Now.AddDays(28), DepartmentId = 1, CreditAmount = 6, Description = "Lýsing á veff" }; Level lvl = new Level { CourseId = 1, CreateDateTime = DateTime.Now, LevelId = 1, Name = "Level", Start = DateTime.Now, Stop = DateTime.Now.AddDays(7), OrderNum = 5 }; course.Levels.Add(lvl); user1.Courses.Add(course); lvl.LevelProjects.Add(levelProject1); lvl.LevelProjects.Add(levelProject2); userData.AddObject(user1); courseData.AddObject(course); levelProjectData.AddObject(levelProject1); levelProjectData.AddObject(levelProject2); levelData.AddObject(lvl); _mockRepository.Expect(x => x.UserInfoes).Return(userData); _mockRepository.Expect(x => x.Courses).Return(courseData); _mockRepository.Expect(x => x.LevelProjects).Return(levelProjectData); _mockRepository.Expect(x => x.Levels).Return(levelData); var query = _levelService.GetLevelProjectsByUserId(userInfoId); var expectedUser = query.SelectMany(x => x.Level.Course.UserInfoes).FirstOrDefault(); var expectedFirstLevelProject = query.Where(s => s.LevelProjectId == 1).FirstOrDefault(); var expectedSecondLevelProject = query.Where(s => s.LevelProjectId == 2).FirstOrDefault(); var expectedLevel = query.Where(x => x.Level.LevelId == 1).Select(x => x.Level).FirstOrDefault(); var expectedCourse = query.Where(x => x.Level.Course.CourseId == 1).Select(x => x.Level.Course).FirstOrDefault(); Assert.AreEqual(expectedCourse.Description, course.Description); Assert.AreEqual(expectedLevel.Name,lvl.Name); Assert.AreEqual(expectedSecondLevelProject.Name, levelProject2.Name); Assert.AreEqual(expectedFirstLevelProject.Name,levelProject1.Name); Assert.AreEqual(expectedUser.Fullname,user1.Fullname); Assert.AreEqual(expectedUser.Fullname, user1.Fullname); Assert.AreEqual(expectedUser.Fullname, user1.Fullname); Assert.AreEqual(expectedUser.Fullname, user1.Fullname); }
public ActionResult Course(Course model, int? id) { ViewBag.Departments = CourseService.GetDepartments(); if (ModelState.IsValid) { if (id.HasValue) //Update existing Course { ViewBag.Title = "Breyta námskeiði"; var course = CourseService.GetCourse(id.Value); if (course != null) { if (TryUpdateModel(course)) { CourseService.UpdateCourse(course); ViewBag.SuccessMessage = "Upplýsingar um námskeið uppfærðar."; return View(model); } } ViewBag.ErrorMessage = "Ekki tókst að uppfæra námskeið!"; } else //Insert new Course { ViewBag.Title = "Nýtt námskeið"; CourseService.CreateCourse(model); ViewBag.SuccessMessage = "Nýtt námskeið skráð! Mundu að skrá nemendur og kennara á námskeið."; } } else { ViewBag.ErrorMessage = "Náði ekki að skrá/uppfæra upplýsingar! Lagfærðu villur og reyndur aftur."; } return View(model); }
public ActionResult Course(int? id) { ViewBag.Departments = CourseService.GetDepartments(); if (id.HasValue) { var course = CourseService.GetCourse((int)id); ViewBag.Courses = course; if (course != null) { ViewBag.Title = "Breyta námskeiði"; var model = new Course(); model.Name = course.Name; model.Description = course.Description; model.Identifier = course.Identifier; model.CreditAmount = course.CreditAmount; model.Start = course.Start; model.Stop = course.Stop; model.DepartmentId = course.DepartmentId; return View(model); } } ViewBag.Title = "Nýtt námskeið"; return View(); }
public void GetTopTenList_UserInfoCoursePoint_IEnumerableTupleIntUserInfo() { // lysandinafn_input_expectedreturn var userData = new FakeObjectSet<UserInfo>(); var courseData = new FakeObjectSet<Course>(); var pointData = new FakeObjectSet<Point>(); var userInfoId1 = 1; var userInfoId2 = 2; var userInfoId3 = 3; var courseId = 1; var departmentId = 1; var levelId = 1; #region data Course course = new Course { CourseId = courseId, Name = "Vefforritun I", CreateDateTime = DateTime.Now, Identifier = "VEFF", Start = DateTime.Now, Stop = DateTime.Now.AddDays(28), DepartmentId = departmentId, CreditAmount = 6, Description = "Lýsing á veff" }; UserInfo user1 = new UserInfo { Fullname = "Davíð Einarsson", Email = "*****@*****.**", StatusId = 1, Username = "******", UserInfoId = userInfoId1, Password = "******" }; Point point1_1 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId1, PointsId = 1, Points = 5 }; Point point2_1 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId1, PointsId = 2, Points = 25 }; Point point3_1 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId1, PointsId = 3, Points = 55 }; course.UserInfoes.Add(user1); course.Points.Add(point1_1); course.Points.Add(point2_1); course.Points.Add(point3_1); user1.Points.Add(point1_1); user1.Points.Add(point2_1); user1.Points.Add(point3_1); userData.AddObject(user1); courseData.AddObject(course); pointData.AddObject(point1_1); pointData.AddObject(point2_1); pointData.AddObject(point3_1); UserInfo user2 = new UserInfo { Fullname = "Davíð Einarsson", Email = "*****@*****.**", StatusId = 1, Username = "******", UserInfoId = userInfoId2, Password = "******" }; Point point1_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 4, Points = 5 }; Point point2_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 5, Points = 25 }; Point point3_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 6, Points = 55 }; Point point4_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 7, Points = 5 }; Point point5_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 8, Points = 25 }; Point point6_2 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId2, PointsId = 9, Points = 55 }; course.UserInfoes.Add(user2); course.Points.Add(point1_2); course.Points.Add(point2_2); course.Points.Add(point3_2); course.Points.Add(point4_2); course.Points.Add(point5_2); course.Points.Add(point6_2); user2.Points.Add(point1_2); user2.Points.Add(point2_2); user2.Points.Add(point3_2); user2.Points.Add(point4_2); user2.Points.Add(point5_2); user2.Points.Add(point6_2); userData.AddObject(user2); pointData.AddObject(point1_2); pointData.AddObject(point2_2); pointData.AddObject(point3_2); pointData.AddObject(point4_2); pointData.AddObject(point5_2); pointData.AddObject(point6_2); UserInfo user3 = new UserInfo { Fullname = "Davíð Einarsson", Email = "*****@*****.**", StatusId = 1, Username = "******", UserInfoId = userInfoId3, Password = "******" }; Point point1_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 10, Points = 5 }; Point point2_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 11, Points = 25 }; Point point3_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 12, Points = 55 }; Point point4_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 13, Points = 5 }; Point point5_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 14, Points = 25 }; Point point6_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 15, Points = 55 }; Point point7_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 16, Points = 5 }; Point point8_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 17, Points = 25 }; Point point9_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 18, Points = 55 }; Point point10_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 19, Points = 5 }; Point point11_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 20, Points = 25 }; Point point12_3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId3, PointsId = 21, Points = 55 }; course.UserInfoes.Add(user3); course.Points.Add(point1_3); course.Points.Add(point2_3); course.Points.Add(point3_3); course.Points.Add(point4_3); course.Points.Add(point5_3); course.Points.Add(point6_3); course.Points.Add(point7_3); course.Points.Add(point8_3); course.Points.Add(point9_3); course.Points.Add(point10_3); course.Points.Add(point11_3); course.Points.Add(point12_3); user3.Points.Add(point1_3); user3.Points.Add(point2_3); user3.Points.Add(point3_3); user3.Points.Add(point4_3); user3.Points.Add(point5_3); user3.Points.Add(point6_3); user3.Points.Add(point7_3); user3.Points.Add(point8_3); user3.Points.Add(point9_3); user3.Points.Add(point10_3); user3.Points.Add(point11_3); user3.Points.Add(point12_3); userData.AddObject(user3); pointData.AddObject(point1_3); pointData.AddObject(point2_3); pointData.AddObject(point3_3); pointData.AddObject(point4_3); pointData.AddObject(point5_3); pointData.AddObject(point6_3); pointData.AddObject(point7_3); pointData.AddObject(point8_3); pointData.AddObject(point9_3); pointData.AddObject(point10_3); pointData.AddObject(point11_3); pointData.AddObject(point12_3); #endregion _mockRepository.Expect(x => x.UserInfoes).Return(userData); _mockRepository.Expect(x => x.Courses).Return(courseData); _mockRepository.Expect(x => x.Points).Return(pointData); var topTen = _gameService.GetTopTenList(courseId); var expectedUser1 = topTen.Select(x => x.UserInfo).Where(d => d.UserInfoId == userInfoId1).FirstOrDefault(); var expectedUser2 = topTen.Select(x => x.UserInfo).Where(d => d.UserInfoId == userInfoId2).FirstOrDefault(); var expectedUser3 = topTen.Select(x => x.UserInfo).Where(d => d.UserInfoId == userInfoId3).FirstOrDefault(); Assert.IsTrue(user1.Points.Select(x => x.Points).FirstOrDefault() > 0); Assert.IsTrue(user2.Points.Select(x => x.Points).FirstOrDefault() > 0); Assert.IsTrue(user3.Points.Select(x => x.Points).FirstOrDefault() > 0); Assert.IsNotNull(expectedUser1.Points); Assert.IsNotNull(expectedUser2.Points); Assert.IsNotNull(expectedUser3.Points); Assert.IsNotNull(course); Assert.IsNotNull(course.Points); Assert.IsNotNull(course.UserInfoes); Assert.IsNotNull(user1.Points); Assert.IsNotNull(user1.Points); Assert.IsNotNull(user1.Points); Assert.AreSame(expectedUser1, user1); Assert.AreSame(expectedUser2, user2); Assert.AreSame(expectedUser3, user3); Assert.AreNotSame(expectedUser1,user3); Assert.AreEqual(expectedUser1.Username,user1.Username); Assert.AreEqual(expectedUser2.Username, user3.Username); Assert.AreEqual(expectedUser3.Username, user3.Username); }
public void GetTopTenList_UserInfoCoursePoint_IEnumerableTupleIntUserInfo1() { var userData = new FakeObjectSet<UserInfo>(); var courseData = new FakeObjectSet<Course>(); var pointData = new FakeObjectSet<Point>(); var userInfoId = 1; var courseId = 1; var departmentId = 1; var levelId = 1; #region data UserInfo user = new UserInfo { Fullname = "Davíð Einarsson", Email = "*****@*****.**", StatusId = 1, Username = "******", UserInfoId = 1, Password = "******" }; Course course = new Course { CourseId = courseId, Name = "Vefforritun I", CreateDateTime = DateTime.Now, Identifier = "VEFF", Start = DateTime.Now, Stop = DateTime.Now.AddDays(28), DepartmentId = departmentId, CreditAmount = 6, Description = "Lýsing á veff" }; Point point1 = new Point { CourseId = courseId, Description = "Þú fékkst stig", LevelId = levelId, UserInfoId = userInfoId, PointsId = 1, Points = 5 }; Point point2 = new Point { CourseId = courseId, Description = "Þú fékkst stig 2", LevelId = levelId, UserInfoId = userInfoId, PointsId = 2, Points = 25 }; Point point3 = new Point { CourseId = courseId, Description = "Þú fékkst stig 3", LevelId = levelId, UserInfoId = userInfoId, PointsId = 3, Points = 55 }; course.UserInfoes.Add(user); course.Points.Add(point1); course.Points.Add(point2); course.Points.Add(point3); user.Points.Add(point1); user.Points.Add(point2); user.Points.Add(point3); userData.AddObject(user); courseData.AddObject(course); pointData.AddObject(point1); pointData.AddObject(point2); pointData.AddObject(point3); #endregion _mockRepository.Expect(x => x.UserInfoes).Return(userData); _mockRepository.Expect(x => x.Courses).Return(courseData); _mockRepository.Expect(x => x.Points).Return(pointData); var topTen = _gameService.GetTopTenList(courseId); var actualUser = topTen.Select(x => x.UserInfo).FirstOrDefault(); Assert.AreSame(actualUser, user); Assert.AreEqual(actualUser.Points, user.Points); Assert.AreEqual(course.Name, user.Courses.Select(x => x.Name).FirstOrDefault()); Assert.AreEqual(user.Username, actualUser.Username); }