public void GetUserTest() { //Assign 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); int userId = 1; UserInfo actual = _userService.GetUser(userId); Assert.IsNotNull( actual); Assert.AreEqual(expected.Username, actual.Username); _mockRepository.VerifyAllExpectations(); // Make sure everything was correctly called. }
public void GetNotificationsTest() { var mockRepository = MockRepository.GenerateMock<IGameSchoolEntities>(); var notificationService = new NotificationService(); notificationService.SetDatasource(mockRepository); int userInfoId = 1; var list = CreateNotificationList(userInfoId, 20); var userData = new FakeObjectSet<UserInfo>(); var userInfo = new UserInfo(); userInfo.Fullname = "Davíð Einarsson"; userInfo.Email = "*****@*****.**"; userInfo.StatusId = 1; userInfo.Username = "******"; userInfo.UserInfoId = userInfoId; userInfo.Password = "******"; userData.AddObject(userInfo); mockRepository.Expect(x => x.UserInfoes).Return(userData); mockRepository.Expect(x => x.Notifications).Return(list); var actualList = notificationService.GetNotifications(userInfoId); Assert.AreEqual(list.Count(), actualList.Count()); mockRepository.VerifyAllExpectations(); }
private void FixupUserInfo(UserInfo previousValue) { if (previousValue != null && previousValue.UserLogs.Contains(this)) { previousValue.UserLogs.Remove(this); } if (UserInfo != null) { if (!UserInfo.UserLogs.Contains(this)) { UserInfo.UserLogs.Add(this); } if (UserInfoId != UserInfo.UserInfoId) { UserInfoId = UserInfo.UserInfoId; } } }
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); }
/// <summary> /// /// </summary> /// <param name="levelProjectResult"></param> /// <param name="user"></param> public void CreateUserLevelProjectResult(LevelProjectResult levelProjectResult, UserInfo user) { if (levelProjectResult != null && user != null) { user.LevelProjectResults.Add(levelProjectResult); Save(); } }
public ActionResult UserEdit(int? id) { ViewBag.Departments = CourseService.GetDepartments(); ViewBag.UserStatus = UserService.GetUserStatuses(); ViewBag.UserTypes = UserService.GetUserTypes(); ViewBag.Title = "Skráning notenda"; if (id.HasValue) { var user = UserService.GetUser((int)id); if (user != null) { var model = new UserInfo(); model.Username = user.Username; model.Email = user.Email; model.Fullname = user.Fullname; model.DepartmentId = user.DepartmentId; model.StatusId = user.StatusId; model.UserTypeId = user.UserTypeId; return View(model); } } return View(); }
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(); }
public ActionResult UserEdit(UserInfo model, int? id) { ViewBag.Departments = CourseService.GetDepartments(); ViewBag.UserStatus = UserService.GetUserStatuses(); ViewBag.UserTypes = UserService.GetUserTypes(); ViewBag.Title = "Breyta notenda"; ModelState.Remove("Password"); if (ModelState.IsValid) { //Update existing user if (id.HasValue) { var user = UserService.GetUser(id.Value); if (TryUpdateModel(user)) { UserService.UpdateUser(user); ViewBag.SuccessMessage = "Upplýsingar um notenda hafa verið uppfærðar"; } else { ViewBag.ErrorMessage = "Náði ekki að skrá/uppfæra upplýsingar! Lagfærðu villur og reyndur aftur."; } } else //Insert new user { return RedirectToAction("Index"); //UserService.CreateUser(model); //ViewBag.SuccessMessage = "Nýr notandi hefur verið skráður í kerfið. Mundu að skrá notendann í 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 UserCreate(UserInfo model, int? id) { ViewBag.Departments = CourseService.GetDepartments(); ViewBag.UserStatus = UserService.GetUserStatuses(); ViewBag.UserTypes = UserService.GetUserTypes(); ViewBag.Title = "Skrá notenda"; if (ModelState.IsValid) { UserService.CreateUser(model); ViewBag.SuccessMessage = "Nýr notandi hefur verið skráður í kerfið. Mundu að skrá notendann í námskeið."; return View("Search"); } else { ViewBag.ErrorMessage = "Náði ekki að skrá upplýsingar! Lagfærðu villur og reyndur aftur."; } return View(model); }
/// <summary> /// Gets a userinfo instance through a parameter of this function and if it isn't null persist it to the database. /// </summary> /// <param name="userInfo">Instance of a userinfo</param> public void CreateUser(UserInfo userInfo) { if (userInfo != null) { // Get user entered clear text password and hash it before storing in db var hashedPasswrd = PasswordUtilities.ComputeHash(userInfo.Password); userInfo.Password = hashedPasswrd; userInfo.CreateDateTime = DateTime.Now; GameSchoolEntities.UserInfoes.AddObject(userInfo); Save(); } }
private void FixupUserInfo(UserInfo previousValue) { if (previousValue != null && previousValue.Announcements.Contains(this)) { previousValue.Announcements.Remove(this); } if (UserInfo != null) { if (!UserInfo.Announcements.Contains(this)) { UserInfo.Announcements.Add(this); } if (CreatedByUserInfoId != UserInfo.UserInfoId) { CreatedByUserInfoId = UserInfo.UserInfoId; } } }
public void UpdateUserTest() { UserInfo userInfo = new UserInfo(); userInfo.Fullname = "Davíð Einarsson"; userInfo.Email = "*****@*****.**"; userInfo.StatusId = 1; userInfo.Username = "******"; userInfo.UserInfoId = 1; userInfo.Password = "******"; _mockRepository.Expect(x => x.SaveChanges()).Return(1); _userService.UpdateUser(userInfo); _mockRepository.VerifyAllExpectations(); // Make sure everything was called correctly. }
public static UserInfo GetUser(int userInfoId, UserType userType) { UserInfo userInfo = new UserInfo(); userInfo.Fullname = "Davíð Einarsson"; userInfo.Email = "*****@*****.**"; userInfo.StatusId = (int) userType; userInfo.Username = "******"; userInfo.UserInfoId = userInfoId; userInfo.Password = "******"; return userInfo; }
public void LoginTest() { var userData = new FakeObjectSet<UserInfo>(); string originalPassword = "******"; UserInfo expected = new UserInfo(); expected.Fullname = "Davíð Einarsson"; expected.Email = "*****@*****.**"; expected.StatusId = (int)UserStatus.Active; expected.Username = "******"; expected.UserInfoId = 1; expected.Password = PasswordUtilities.ComputeHash(originalPassword); userData.AddObject(expected); _mockRepository.Expect(x => x.UserInfoes).Return(userData); string userName = "******"; string password = "******"; UserInfo actual= _userService.Login(userName, password,"::1"); Assert.IsNull(actual); password = originalPassword; actual = _userService.Login(userName, password,"::1"); Assert.IsNotNull(actual); Assert.AreEqual(expected.Username, actual.Username); _mockRepository.VerifyAllExpectations(); // Make sure everything was called correctly. }
public void GetUsersTest() { var userData = new FakeObjectSet<UserInfo>(); UserInfo expected = new UserInfo(); expected.Fullname = "Davíð Einarsson"; expected.Email = "*****@*****.**"; expected.StatusId = 1; expected.Username = "******"; expected.UserInfoId = 1; expected.Password = "******"; userData.AddObject(expected); _mockRepository.Expect(x => x.UserInfoes).Return(userData); var users = _userService.GetUsers(); Assert.AreEqual(users.Count(), 1); _mockRepository.VerifyAllExpectations(); // Make sure everything was called correctly. }
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); }
/// <summary> /// Updates user info /// </summary> /// <param name="userInfo"></param> public void UpdateUser(UserInfo userInfo) { Save(); }