using Titano.App.Library; using Titano.Core.Model; using Titano.Data.Repositories; using Titano.Testing; namespace Titano.App.Tests.Library; /// Mixed mode (BRIEF ยง4.4): the server's sequences without a copy here count in the Year and Camera choices and the timeline. public sealed class LibraryFacetsTests { private static readonly ArchiveStats Local = new(3, 6_000, 60_000, [new YearBucket(2026, 3, 6_000, 60_000)], [new MonthBucket(2026, 9, 2, 5_000), new MonthBucket(2026, 2, 1, 1_000)], [new CameraBucket("Canon", "Canon EOS R5", 2, 5_000, 50_000), new CameraBucket("NIKON CORPORATION", "NIKON Z 8", 1, 1_000, 10_000)], [], new ArchiveHealth(0, 0, 0, 0, 0, 0, 0)); private static Sequence Remote(DateTime? first, string? make, string? model, int frames) => new() { Id = Guid.CreateVersion7(), ArchiveId = Guid.Empty, Title = "Remote", Folder = string.Empty, Origin = SequenceOrigin.Server, SyncState = SyncState.RemoteOnly, FirstCapture = first, CameraMake = make, CameraModel = model, FrameCount = frames, TotalBytes = frames * 10L, }; [Test] public void RemoteCardsJoinTheYearsMonthsAndCameras() { Sequence[] remote = [ Remote(new DateTime(2024, 5, 3), "SONY", "ILCE-7M4", 2_000), Remote(new DateTime(2026, 9, 20), "Canon", "Canon EOS R5", 500), Remote(null, null, null, 10), ]; var stats = LibraryFacets.Of(Local, remote, OriginFilter.Any); Assert.SequenceEqual([2024, 2026], stats.ByYear.Select(y => y.Year)); Assert.Equal(new YearBucket(2024, 1, 2_000, 20_000), stats.ByYear[0]); Assert.Equal(new YearBucket(2026, 4, 6_500, 65_000), stats.ByYear[1]); Assert.SequenceEqual([(2024, 5), (2026, 2), (2026, 9)], stats.ByMonth.Select(m => (m.Year, m.Month))); Assert.Equal(new MonthBucket(2026, 9, 3, 5_500), stats.ByMonth[2]); Assert.Equal(3, stats.ByCamera.Single(c => c.Model == "Canon EOS R5").Sequences); Assert.Equal(1, stats.ByCamera.Single(c => c.Model == "ILCE-7M4").Sequences); Assert.Equal(1, stats.ByCamera.Single(c => c.Model is null).Sequences, "a card without camera counts under none"); Assert.Equal(Local.Sequences, stats.Sequences, "the totals stay the index's own"); var timeline = LibraryTimeline.From(stats, new DateTime(2026, 10, 6)); Assert.SequenceEqual([2026, 2025, 2024], timeline.Years, "a year only the server has gets its band"); Assert.Equal(2_000.0, timeline.Bands[2].Values[4]); } [Test] public void TheOriginFilterDecidesWhoCounts() { Sequence[] remote = [Remote(new DateTime(2024, 5, 3), "SONY", "ILCE-7M4", 2_000)]; var local = LibraryFacets.Of(Local, remote, OriginFilter.Local); Assert.SequenceEqual([2026], local.ByYear.Select(y => y.Year), "on this PC: the index alone"); Assert.False(local.ByCamera.Any(c => c.Model == "ILCE-7M4")); var server = LibraryFacets.Of(Local, remote, OriginFilter.Server); Assert.SequenceEqual([2024], server.ByYear.Select(y => y.Year), "only on server: the remote cards alone"); Assert.SequenceEqual(["ILCE-7M4"], server.ByCamera.Select(c => c.Model)); Assert.SequenceEqual([(2024, 5)], server.ByMonth.Select(m => (m.Year, m.Month))); Assert.SequenceEqual(Local.ByYear, LibraryFacets.Of(Local, [], OriginFilter.Any).ByYear, "signed out, nothing changes"); } }