public async Task <IHttpActionResult> GetSchedule(int id) { Schedule schedule = await _schedules.Find(id); if (schedule == null) { return(NotFound()); } return(Ok((ScheduleResultViewModel)schedule)); }
public void ShouldReturnEntityIfItExists() { var idToFind = 1; var entity = new Schedule(); repositoryMock.Setup(x => x.Find(idToFind)).Returns(entity); var result = service.Find(idToFind); Assert.AreEqual(entity, result); repositoryMock.Verify(x => x.Find(idToFind), Times.Once()); }
private Command CreateStudent( ScheduleService service, Func <string, string> requestInput) => args => { var firstName = requestInput("Введите имя"); var midName = requestInput("Введите отчество"); var lastName = requestInput("Введите фамилию"); var classId = requestInput("Введите ID класса"); SchoolClass schoolClass = null; if (classId != "") { schoolClass = service.Find((SchoolClass c) => c.Id == classId); if (schoolClass == null) { throw new CommandException($"Класс с Id={classId} не найден"); } } var student = new Student { Id = Guid.NewGuid().ToString(), FirstName = firstName, MidName = midName, LastName = lastName, SchoolClass = schoolClass }; Save(() => service.Save(student)); };
private Command CreateExercise( ScheduleService service, Func <string, string> requestInput) => args => { var dayStr = requestInput("Введите день недели (число)"); if (!int.TryParse(dayStr, out int day)) { throw new CommandException($"Неверный формат числа {dayStr}"); } var numberStr = requestInput("Введите номер занятия"); if (!int.TryParse(numberStr, out int number)) { throw new CommandException($"Неверный формат числа {numberStr}"); } var classId = requestInput("Введите ID класса"); SchoolClass schoolClass = null; if (classId != "") { schoolClass = service.Find((SchoolClass c) => c.Id == classId); if (schoolClass == null) { throw new CommandException($"Класс с Id={classId} не найден"); } } var auditoryStr = requestInput("Введите номер аудитории"); if (!int.TryParse(auditoryStr, out int auditory)) { throw new CommandException($"Неверный формат числа {auditoryStr}"); } var teacherId = requestInput("Введите ID преподавателя"); var lessonId = requestInput("Введите ID предмета"); var exercise = new Exercise { Id = Guid.NewGuid().ToString(), DayOfWeek = day, ExerciseNumber = number, SchoolClass = schoolClass, Auditory = auditory, TeacherId = teacherId, LessonId = lessonId }; Save(() => service.Save(exercise)); };
public void CrudTest() { service.Save(sClass); var savedClass = service.Find((SchoolClass c) => c.Id == sClass.Id); AssertClassesEquals(savedClass, sClass); service.Save(sClass1); var savedClass1 = service.Find((SchoolClass c) => c.Id == sClass1.Id); AssertClassesEquals(savedClass1, sClass1); service.Save(student); var savedStudent = service.Find((Student s) => s.Id == student.Id); AssertStudentsEquals(savedStudent, student); service.Save(student1); var savedStudent1 = service.Find((Student s) => s.Id == student1.Id); AssertStudentsEquals(savedStudent1, student1); service.Save(lesson); var savedLesson = service.Find((Lesson l) => l.Id == lesson.Id); AssertLessonsEquals(savedLesson, lesson); service.Save(lesson1); var savedLesson1 = service.Find((Lesson l) => l.Id == lesson1.Id); AssertLessonsEquals(savedLesson1, lesson1); service.Save(teacher); var savedTeacher = service.Find((Teacher t) => t.Id == teacher.Id); AssertTeachersEquals(savedTeacher, teacher); service.Save(teacher1); var savedTeacher1 = service.Find((Teacher t) => t.Id == teacher1.Id); AssertTeachersEquals(savedTeacher1, teacher1); service.Save(teacherLesson); var savedTeacherLesson = service.Find((TeacherLesson tl) => tl.LessonId == teacherLesson.Lesson.Id && tl.TeacherId == teacherLesson.Teacher.Id); AssertTeacherLessonEquals(savedTeacherLesson, teacherLesson); service.Save(exercise); var savedExercise = service.Find((Exercise e) => e.Id == exercise.Id); AssertExercisesEquals(savedExercise, exercise); sClass.ClassNumber = 4; service.Save(sClass); var savedChangedClass = service.Find((SchoolClass c) => c.Id == sClass.Id); AssertClassesEquals(savedChangedClass, sClass); student.LastName = "fdkjdkdfk"; student.SchoolClass = sClass1; service.Save(student); var savedChangedStudent = service.Find((Student s) => s.Id == student.Id); AssertStudentsEquals(savedChangedStudent, student); lesson.Name = "kdkdkdmeee"; service.Save(lesson); var savedChangedLesson = service.Find((Lesson l) => l.Id == lesson.Id); AssertLessonsEquals(savedChangedLesson, lesson); teacher.LastName = "Djldfsn"; service.Save(teacher); var savedChangedTeacher = service.Find((Teacher t) => t.Id == teacher.Id); AssertTeachersEquals(savedChangedTeacher, teacher); exercise.Auditory = 434; service.Save(exercise); var savedChangedExercise = service.Find((Exercise e) => e.Id == exercise.Id); AssertExercisesEquals(savedChangedExercise, exercise); service.Delete(student); Assert.IsNull(service.Find((Student s) => s.Id == student.Id)); Assert.IsNotNull(service.Find((SchoolClass c) => c.Id == sClass1.Id)); service.Delete(student1); Assert.IsNull(service.Find((Student s) => s.Id == student1.Id)); Assert.IsNotNull(service.Find((SchoolClass c) => c.Id == sClass.Id)); service.Delete(exercise); Assert.IsNull(service.Find((Exercise e) => e.Id == exercise.Id)); service.Delete(sClass); Assert.IsNull(service.Find((SchoolClass c) => c.Id == sClass.Id)); service.Delete(sClass1); Assert.IsNull(service.Find((SchoolClass c) => c.Id == sClass1.Id)); service.Delete(lesson); Assert.IsNull(service.Find((Lesson l) => l.Id == lesson.Id)); service.Delete(lesson1); Assert.IsNull(service.Find((Lesson l) => l.Id == lesson1.Id)); service.Delete(teacher); Assert.IsNull(service.Find((Teacher t) => t.Id == teacher.Id)); service.Delete(teacher1); Assert.IsNull(service.Find((Teacher t) => t.Id == teacher1.Id)); }