public async Task AddStudsToEachCmTest() { // ARRANGE PlannerService service = new PlannerService(ctxDb); int cmId = AddCm(); int courseId = ctxDb.Course.Where(c => c.Vakcode == "MGP01A").FirstOrDefault().Id; ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.SaveChanges(); string user1Id = ctxDb.Users.Where(u => u.UserName == "r0000001").FirstOrDefault().Id; string user2Id = ctxDb.Users.Where(u => u.UserName == "r0000002").FirstOrDefault().Id; string user3Id = ctxDb.Users.Where(u => u.UserName == "r0000003").FirstOrDefault().Id; ctxDb.CourseUser.Add(new CourseUser { CourseId = courseId, ApplicationUserId = user1Id, GoedGekeurd = true, AfwijzingBeschr = null }); ctxDb.CourseUser.Add(new CourseUser { CourseId = courseId, ApplicationUserId = user2Id, GoedGekeurd = true, AfwijzingBeschr = null }); ctxDb.CourseUser.Add(new CourseUser { CourseId = courseId, ApplicationUserId = user3Id, GoedGekeurd = false, AfwijzingBeschr = null }); ctxDb.SaveChanges(); var list = service.GetStudsInEachCm(courseId); list[1].IsSelected = true; // ACT var result = await service.AddStudsToEachCm(list, courseId); // ASSERT Assert.IsTrue(ctxDb.CourseMomentUsers.Any()); Assert.AreEqual(user2Id, ctxDb.CourseMomentUsers.FirstOrDefault().ApplicationUserId); }
public async Task AddStudsToEachCmTest() { // ARRANGE PlannerService service = new PlannerService(ctxDb); PlannerController controller = SetupPlannerController(service).Result; ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.Users.Add(new ApplicationUser { UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true }); ctxDb.Course.Add(new Course { Vakcode = "AAA01A", Titel = "testvak 1", Studiepunten = 20 }); ctxDb.SaveChanges(); string user1Id = ctxDb.Users.Where(u => u.UserName == "r0000001").FirstOrDefault().Id; string user2Id = ctxDb.Users.Where(u => u.UserName == "r0000002").FirstOrDefault().Id; string user3Id = ctxDb.Users.Where(u => u.UserName == "r0000003").FirstOrDefault().Id; var roleId = ctxDb.Roles.Where(r => r.Name == "Student").FirstOrDefault().Id; ctxDb.UserRoles.Add(new IdentityUserRole <string> { UserId = user2Id, RoleId = roleId }); ctxDb.UserRoles.Add(new IdentityUserRole <string> { UserId = user3Id, RoleId = roleId }); ctxDb.SaveChanges(); int courseId = ctxDb.Course.Where(c => c.Vakcode == "AAA01A").FirstOrDefault().Id; ctxDb.CourseUser.Add(new CourseUser { ApplicationUserId = user1Id, CourseId = courseId, GoedGekeurd = true }); ctxDb.CourseUser.Add(new CourseUser { ApplicationUserId = user2Id, CourseId = courseId, GoedGekeurd = true }); ctxDb.CourseUser.Add(new CourseUser { ApplicationUserId = user3Id, CourseId = courseId, GoedGekeurd = true }); ctxDb.SaveChanges(); int cuId = AddTestPlanning(service); ctxDb.CourseMomentUsers.Add(new CourseMomentUsers { ApplicationUserId = user1Id, CoursMomentId = cuId }); ctxDb.CourseMomentUsers.Add(new CourseMomentUsers { ApplicationUserId = user3Id, CoursMomentId = cuId }); ctxDb.SaveChanges(); var model = service.GetStudsInEachCm(courseId); foreach (var user in model) { user.IsSelected = !user.IsSelected; } // ACT var res = await controller.AddStudsToEachCm(model, courseId); // ASSERT Assert.IsTrue(res is ActionResult); Assert.IsNotNull(ctxDb.CourseMomentUsers.Where(cmu => cmu.ApplicationUserId == user2Id).FirstOrDefault()); Assert.IsNull(ctxDb.CourseMomentUsers.Where(cmu => cmu.ApplicationUserId == user1Id).FirstOrDefault()); }