import 'package:hepan_everyday/data/snapshot_store.dart'; import 'package:hepan_everyday/domain/app_snapshot.dart'; import 'package:hepan_everyday/domain/app_settings.dart'; import 'package:hepan_everyday/domain/course_occurrence.dart'; import 'package:hepan_everyday/services/notification_service.dart'; import 'package:hepan_everyday/services/calendar_service.dart'; class MemoryStore extends SnapshotStore { MemoryStore([this.value]); AppSnapshot? value; bool failSave = false; @override Future load() async => value; @override Future save(AppSnapshot snapshot) async { if (failSave) throw StateError('磁盘写入失败'); value = snapshot; } } class FakeNotifications extends NotificationService { int reconciliations = 0, cancellations = 0; bool fail = false; @override Future reconcile( List occurrences, AppSettings settings, DateTime now, ) async { reconciliations++; if (fail) throw StateError('系统拒绝'); return ReminderResult( settings.remindersEnabled ? ReminderStatus.exact : ReminderStatus.off, scheduledCount: occurrences.length, ); } @override Future cancelOwned() async { cancellations++; } @override Future requestPermissions() async {} } class FakeCalendar extends CalendarService { bool access = true; int synchronizations = 0, deletions = 0; @override Future requestAccess() async => access; @override Future> listWritableCalendars() async => [ const DeviceCalendar('local', '测试日历'), ]; @override Future> sync( List occurrences, String calendarId, Map knownEventIds, ) async { synchronizations++; return { for (final e in occurrences) e.key: knownEventIds[e.key] ?? 'event-${e.key}', }; } @override Future deleteOwned(Map eventIds) async { deletions++; } }