PlotDirector/PlotLine.Tests/CalendarNavigationTests.cs

40 lines
2.7 KiB
C#

using PlotLine.Data;
using PlotLine.Models;
using PlotLine.Services;
internal static class CalendarNavigationTests
{
public static TimelineData Data() => new()
{
Project = new() { ProjectID = 7, ProjectName = "Calendar fixture" },
Books = [new() { BookID = 12, ProjectID = 7, BookTitle = "A long book title for checking ribbon width", BookNumber = 1 }, new() { BookID = 13, ProjectID = 7, BookTitle = "Second book", BookNumber = 2 }],
Chapters = [new() { ChapterID = 21, BookID = 12 }, new() { ChapterID = 22, BookID = 13 }],
Scenes = [new() { SceneID = 1, ChapterID = 21, BookID = 12, SceneTitle = "March", StartDateTime = new(1983, 3, 5) },
new() { SceneID = 2, ChapterID = 21, BookID = 12, SceneTitle = "May", StartDateTime = new(1983, 5, 7) },
new() { SceneID = 3, ChapterID = 22, BookID = 13, SceneTitle = "September", StartDateTime = new(1983, 9, 8) }],
ThreadEvents = [new() { ThreadEventID = 1, SceneID = 3, EventTitle = "Scene anchored event", CreatedDate = new(2026, 11, 2) }]
};
public static void Run()
{
var service = new StoryCalendarService(new FakeTimelineRepository(Data()));
var march = service.GetAsync(7, null, null, null).GetAwaiter().GetResult()!;
Check(march.MonthOptions.Select(o => o.Value).SequenceEqual(new[] { "1983-03", "1983-05", "1983-09" }), "Only populated months across books");
Check(march.NextMonth == new DateOnly(1983, 4, 1) && march.NextStoryMonth == new DateOnly(1983, 5, 1), "Chronological and story navigation differ");
var april = service.GetAsync(7, null, march.NextMonth, null).GetAwaiter().GetResult()!;
Check(april.MonthOptions.Single(o => o.Selected).Value == "1983-04", "Empty current month selected");
Check(april.Weeks.SelectMany(w => w.Days).All(d => d.Scenes.Count == 0), "Empty month renders normally");
Check(april.PreviousMonth == march.SelectedMonth && april.NextStoryMonth == march.NextStoryMonth, "Empty month navigation");
var firstBook = service.GetAsync(7, 12, null, null).GetAwaiter().GetResult()!;
Check(firstBook.MonthOptions.Select(o => o.Value).SequenceEqual(new[] { "1983-03", "1983-05" }), "Book scope excludes other book's event and scene month");
var secondBook = service.GetAsync(7, 13, null, null).GetAwaiter().GetResult()!;
Check(secondBook.MonthOptions.Single().Value == "1983-09", "Event owning scene supplies canonical month, not audit date");
Check(typeof(ThreadEvent).GetProperty("StartDateTime") is null, "Current events have no independent story date");
}
private static void Check(bool condition, string message)
{
if (!condition) throw new InvalidOperationException(message);
}
}