Fix unit persistence before saving timetable lessons
CI / build-and-test (push) Canceled after 0s

This commit is contained in:
admin committed 2026-11-09 21:50:36 +01:00
1 parent cbcb739097
commit fb38b6bb04
5 files changed
+53 -1

No files matched your search

@@ -8,6 +8,43 @@ namespace LehrerApp.Desktop.Tests;
public sealed class LessonDialogViewModelTests
{
[Fact]
public void Save_PersistsParentBeforeLesson()
{
var lessons = new FakeLessons();
var unitId = Guid.NewGuid();
var vm = new LessonDialogViewModel(lessons, new FakeShorthandCodes([]),
new FakeAlternativeLessonPaths([]), new FakeTimetableSlots(), NewPeriodSchedule(),
new FakeAttachmentStorage(), unitId, Guid.NewGuid(), "10c", "Chemie", [], [], null);
vm.Topic = "Test";
vm.DateText = "09.11.2026";
var called = false;
vm.BeforeSave = () =>
{
Assert.Empty(lessons.GetByUnit(unitId));
called = true;
};
vm.SaveCommand.Execute(null);
Assert.True(called);
Assert.Equal(unitId, Assert.Single(lessons.GetByUnit(unitId)).UnitId);
}
[Fact]
public void Save_InvalidInputDoesNotPersistParent()
{
var vm = BuildVm(Guid.NewGuid(), Guid.NewGuid());
var called = false;
vm.BeforeSave = () => called = true;
vm.DateText = "invalid";
vm.SaveCommand.Execute(null);
Assert.False(called);
Assert.Null(vm.Result);
}
private static PeriodScheduleService NewPeriodSchedule()
{
var tempPath = System.IO.Path.Combine(