private Command CreateTeacherLesson( ScheduleService service, Func <string, string> requestInput) => args => { var teacherId = requestInput("Введите ID преподавателя"); var lessonId = requestInput("Введите ID предмета"); Save(() => service.AssignLessonToTeacher(new Lesson { Id = lessonId }, new Teacher { Id = teacherId })); };
public void TeacherLessonTest() { service.Save(teacher); service.Save(teacher1); service.Save(lesson); service.Save(lesson1); service.AssignLessonToTeacher(lesson, teacher); var teacherLesson = service.Find((TeacherLesson tl) => tl.LessonId == lesson.Id && tl.TeacherId == teacher.Id); Assert.IsNotNull(teacherLesson); var teacherWithLesson = service.Find((Teacher t) => t.Id == teacher.Id); var lessonWithTeacher = service.Find((Lesson l) => l.Id == lesson.Id); Assert.IsTrue(teacherWithLesson.Lessons.Count == 1); Assert.IsTrue(lessonWithTeacher.Teachers.Count == 1); AssertListsElementsAreEqual( teacherWithLesson.Lessons.ToList(), new List <Lesson> { lesson }, l => l.Id, (a, e) => AssertLessonsEquals(a, e)); AssertListsElementsAreEqual( lessonWithTeacher.Teachers.ToList(), new List <Teacher> { teacher }, t => t.Id, (a, e) => AssertTeachersEquals(a, e)); service.AssignLessonToTeacher(lesson1, teacher); service.AssignLessonToTeacher(lesson1, teacher1); teacherWithLesson = service.Find((Teacher t) => t.Id == teacher.Id); var teacher1WithLesson = service.Find((Teacher t) => t.Id == teacher1.Id); lessonWithTeacher = service.Find((Lesson l) => l.Id == lesson.Id); var lesson1WithTeacher = service.Find((Lesson l) => l.Id == lesson1.Id); AssertListsElementsAreEqual( teacherWithLesson.Lessons.ToList(), new List <Lesson> { lesson, lesson1 }, l => l.Id, (a, e) => AssertLessonsEquals(a, e)); AssertListsElementsAreEqual( teacher1WithLesson.Lessons.ToList(), new List <Lesson> { lesson1 }, l => l.Id, (a, e) => AssertLessonsEquals(a, e)); AssertListsElementsAreEqual( lesson1WithTeacher.Teachers.ToList(), new List <Teacher> { teacher, teacher1 }, t => t.Id, (a, e) => AssertTeachersEquals(a, e)); service.Delete(teacher1); Assert.IsNull(service.Find((TeacherLesson tl) => tl.LessonId == lesson.Id && tl.TeacherId == teacher1.Id)); service.Delete(new TeacherLesson { Teacher = teacher, Lesson = lesson }); teacherWithLesson = service.Find((Teacher t) => t.Id == teacher.Id); AssertListsElementsAreEqual( teacherWithLesson.Lessons.ToList(), new List <Lesson> { lesson1 }, l => l.Id, (a, e) => AssertLessonsEquals(a, e)); service.Delete(teacher); service.Delete(lesson); service.Delete(lesson1); }