public void DeleteByIdReturnsInactiveClass() { var teacher = new Mock <LearningPlusUser>(); teacher.Setup(t => t.Id).Returns("teacherId"); teacher.Setup(t => t.FirstName).Returns("TeacherFirst"); teacher.Setup(t => t.LastName).Returns("TeacherLast"); var model = new ClassesCreateViewModel { DayOfWeek = DaysOfWeek.Понеделник.ToString(), Discipline = Disciplines.Английски_език.ToString(), Room = Room.Стая_1.ToString(), TimeOfDay = "11:00 - 12:30", TeacherId = "teacherId", StudentIds = new List <string> { "studentId" } }; var options = new DbContextOptionsBuilder <LearningPlusDbContext>() .UseInMemoryDatabase(databaseName: "Delete_Classes_Database") // Give a Unique name to the DB .Options; var dbContext = new LearningPlusDbContext(options); dbContext.Users.Add(teacher.Object); var repository = new DbRepository <LearningPlusClass>(dbContext); var classesService = new ClassesService(null, null, repository, null); var createdModel = classesService.Create(model); var id = createdModel.Id.ToString(); var deletedClass = classesService.DeleteById(id); deletedClass.Active.ShouldBe(false); }
public void CreateReturnsClassInRepository() { var model = new ClassesCreateViewModel { DayOfWeek = DaysOfWeek.Понеделник.ToString(), Discipline = Disciplines.Английски_език.ToString(), Room = Room.Стая_1.ToString(), TimeOfDay = "11:00 - 12:30", TeacherId = "teacherId", StudentIds = new List <string> { "studentId" } }; var options = new DbContextOptionsBuilder <LearningPlusDbContext>() .UseInMemoryDatabase(databaseName: "Create_Classes_Database") // Give a Unique name to the DB .Options; var dbContext = new LearningPlusDbContext(options); var repository = new DbRepository <LearningPlusClass>(dbContext); var classesService = new ClassesService(null, null, repository, null); var createdModel = classesService.Create(model); repository.All().CountAsync().GetAwaiter().GetResult().ShouldBe(1); }
public void GetScheduleClassesReturnsCorrectClasses() { var student = new Mock <LearningPlusUser>(); student.Setup(t => t.Id).Returns("studentId"); student.Setup(t => t.FirstName).Returns("First"); student.Setup(t => t.LastName).Returns("Last"); var model = new ClassesCreateViewModel { DayOfWeek = DaysOfWeek.Понеделник.ToString(), Discipline = Disciplines.Английски_език.ToString(), Room = Room.Стая_1.ToString(), TimeOfDay = "11:00 - 12:30", TeacherId = "teacherId", StudentIds = new List <string> { "studentId" } }; var options = new DbContextOptionsBuilder <LearningPlusDbContext>() .UseInMemoryDatabase(databaseName: "Schedule_Classes_Database") // Give a Unique name to the DB .Options; var dbContext = new LearningPlusDbContext(options); dbContext.Users.Add(student.Object); var repository = new DbRepository <LearningPlusClass>(dbContext); var classesService = new ClassesService(null, null, repository, null); var createdModel = classesService.Create(model); var classes = classesService.GetScheduleClasses(); classes.Count.ShouldBe(1); }
public IActionResult Edit(ClassesCreateViewModel model) { //TODO: Implement editing CreateEditViewBag(); return(View(model)); }
public LearningPlusClass Create(ClassesCreateViewModel model) { var newClass = this.mapper.Map <LearningPlusClass>(model); this.classesRepo.AddAsync(newClass).GetAwaiter().GetResult(); this.classesRepo.SaveChangesAsync().GetAwaiter().GetResult(); return(newClass); }
public IActionResult Create(ClassesCreateViewModel model) { if (ModelState.IsValid) { this.classesService.Create(model); return(RedirectToAction("Schedule", "Classes")); } return(RedirectToAction("Schedule", "Classes")); }