private Command DeleteAll( ScheduleService service, Func <string, string> requestInput) => args => { var answer = requestInput("Это действие очистит БД\nПродолжить? (да/нет)"); if (answer.ToLower() != "да") { return; } DoWithHandleException(() => service.CleanDb(), "Не удалось очистить базу"); };
private Command CreateDemo( ScheduleService service, Func <string, string> requestInput, Action <string> writeln) => args => { writeln("Перед созданием демо-базы будет очищена существующая."); var answer = requestInput("Выполнить? (да/нет)"); if (answer.ToLower() != "да") { return; } DoWithHandleException(() => service.CleanDb(), "Не удалось очистить базу"); DoWithHandleException(() => service.CreateDemoBase(), "Не удалось создать демо-базу"); };
public void ScheduleTest() { service.Save(teacher); service.Save(teacher1); service.Save(lesson); service.Save(lesson1); service.Save(sClass); service.Save(sClass1); service.Save(student); service.Save(student1); service.AssignLessonToTeacher(lesson, teacher); service.AssignLessonToTeacher(lesson1, teacher1); service.AssignLessonToTeacher(lesson1, teacher); service.SaveExercises(exercise, exercise1, exercise2, exercise3); var expectedFullWeekSchedule = new WeekSchedule { ScheduleByDay = new Dictionary <DayOfWeek, DaySchedule> { [DayOfWeek.Monday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [1] = new List <Exercise> { exercise, exercise3 }, [2] = new List <Exercise> { exercise1 } } }, [DayOfWeek.Friday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [4] = new List <Exercise> { exercise2 } } } } }; var expectedClassWeekSchedule = new WeekSchedule { ScheduleByDay = new Dictionary <DayOfWeek, DaySchedule> { [DayOfWeek.Monday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [1] = new List <Exercise> { exercise }, [2] = new List <Exercise> { exercise1 } } }, [DayOfWeek.Friday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [4] = new List <Exercise> { exercise2 } } } } }; var expectedTeacherWeekSchedule = new WeekSchedule { ScheduleByDay = new Dictionary <DayOfWeek, DaySchedule> { [DayOfWeek.Monday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [1] = new List <Exercise> { exercise, exercise3 } } }, [DayOfWeek.Friday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [4] = new List <Exercise> { exercise2 } } } } }; var expectedStudentWeekSchedule = new WeekSchedule { ScheduleByDay = new Dictionary <DayOfWeek, DaySchedule> { [DayOfWeek.Monday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [1] = new List <Exercise> { exercise }, [2] = new List <Exercise> { exercise1 } } }, [DayOfWeek.Friday] = new DaySchedule { ExerciseByLessonNumber = new Dictionary <int, List <Exercise> > { [4] = new List <Exercise> { exercise2 } } } } }; var fullSchedule = service.GetFullWeekSchedule(); AssertWeekSchedulesEquals(fullSchedule, expectedFullWeekSchedule); var classSchedule = service.GetClassWeekSchedule(sClass.ClassNumber, sClass.Letter); AssertWeekSchedulesEquals(classSchedule, expectedClassWeekSchedule); var teacherSchedule = service.GetTeacherWeekSchedule(teacher.FirstName, teacher.MidName, teacher.LastName); AssertWeekSchedulesEquals(teacherSchedule, expectedTeacherWeekSchedule); var studentSchedule = service.GetStudentWeekSchedule(student.FirstName, student.MidName, student.LastName); AssertWeekSchedulesEquals(studentSchedule, expectedStudentWeekSchedule); service.CleanDb(); }