Plain classes behind the Import and Archive screens: plan totals, session rows and the Show plan listing; duplicate and title choices without a new scan; folder and server destinations with the protocol client's chunked, hash-verified uploads; the after-import gate that allows deleting or formatting a card only after a verified archive import and a dry run; the archive tree, chart aggregation, mass rename/retag and maintenance reports. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
137 lines
6.8 KiB
C#
137 lines
6.8 KiB
C#
using System.Globalization;
|
|
using Titano.App.Import;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Localization;
|
|
using Titano.Testing;
|
|
using static Titano.App.Tests.Import.ImportTestData;
|
|
|
|
namespace Titano.App.Tests.Import;
|
|
|
|
public sealed class ImportPlansTests
|
|
{
|
|
public ImportPlansTests() => Loc.SetCulture(CultureInfo.GetCultureInfo("en"));
|
|
|
|
private static ImportPlan ThreeSessions(long? available = 200_000_000)
|
|
{
|
|
var duplicate = Guid.CreateVersion7();
|
|
return Plan(available, [new ImportProblem("DCIM/100CANON/IMG_0099.CR2", "Access denied")],
|
|
Session(1, "2026/2026-09-28 Canon EOS R5", Item(1, Start), Item(2, Start.AddSeconds(2)), Item(3, Start.AddSeconds(4)), Item(4, Start.AddSeconds(8))),
|
|
Session(2, "2026/2026-09-29 Canon EOS R5", Item(5, Start.AddDays(1)), Item(6, Start.AddDays(1).AddSeconds(120), action: ImportAction.SkipInArchive, existing: duplicate)),
|
|
Session(3, "2026/2026-09-30 Canon EOS R5", Item(7, Start.AddDays(2), action: ImportAction.SkipImported)));
|
|
}
|
|
|
|
[Test]
|
|
public void TotalsCountWhatIsCopiedSkippedAndDuplicated()
|
|
{
|
|
var totals = ImportPlans.Totals(ThreeSessions(), verify: true);
|
|
Assert.Equal(3, totals.Sessions);
|
|
Assert.Equal(7, totals.Photos);
|
|
Assert.Equal(5, totals.CopyCount);
|
|
Assert.Equal(5 * 24_000_000L, totals.CopyBytes);
|
|
Assert.Equal(1, totals.Duplicates);
|
|
Assert.Equal(1, totals.ImportedBefore);
|
|
Assert.Equal(1, totals.Problems);
|
|
Assert.Equal(80_000_000L, totals.FreeAfter);
|
|
Assert.True(totals.HasEnoughSpace);
|
|
Assert.Equal(TimeSpan.FromSeconds(3), totals.Estimate);
|
|
Assert.Equal("3 sessions · 7 photos · 120 MB · about 3 s", totals.Text);
|
|
Assert.Equal("1 duplicate", totals.DuplicatesText);
|
|
Assert.Equal("Import 5 photos", totals.ImportText);
|
|
Assert.Equal("80 MB free after import", totals.SpaceText);
|
|
}
|
|
|
|
[Test]
|
|
public void ASmallDestinationReportsTheMissingSpace()
|
|
{
|
|
var totals = ImportPlans.Totals(ThreeSessions(available: 100_000_000), verify: false);
|
|
Assert.False(totals.HasEnoughSpace);
|
|
Assert.Equal("20 MB missing", totals.SpaceText);
|
|
Assert.Equal(string.Empty, ImportPlans.Totals(ThreeSessions(available: null), verify: false).SpaceText);
|
|
Assert.Equal(TimeSpan.FromSeconds(2), ImportPlans.Totals(ThreeSessions(), verify: false).Estimate);
|
|
}
|
|
|
|
[Test]
|
|
public void TheDuplicateChoiceFlipsOnlyPhotosAlreadyInTheArchive()
|
|
{
|
|
var plan = ThreeSessions();
|
|
var again = ImportPlans.WithDuplicates(plan, DuplicatePolicy.ImportAgain);
|
|
Assert.Equal(6, again.CopyCount);
|
|
var duplicate = again.Sessions[1].Items[1];
|
|
Assert.Equal(ImportAction.Copy, duplicate.Action);
|
|
Assert.NotNull(duplicate.ExistingFrameId);
|
|
Assert.Equal(ImportAction.SkipImported, again.Sessions[2].Items[0].Action);
|
|
|
|
var skipped = ImportPlans.WithDuplicates(again, DuplicatePolicy.Skip);
|
|
Assert.Equal(ImportAction.SkipInArchive, skipped.Sessions[1].Items[1].Action);
|
|
Assert.Equal(plan.CopyCount, skipped.CopyCount);
|
|
Assert.Equal("Import again", ImportPlans.Details(again, ImportDestinationKind.Archive, true).Rows.Single(r => r.Source.EndsWith("0006.CR2", StringComparison.Ordinal)).ActionText);
|
|
}
|
|
|
|
[Test]
|
|
public void TypedTitlesNameTheirSessions()
|
|
{
|
|
var plan = ThreeSessions();
|
|
var titled = ImportPlans.WithTitles(plan, new Dictionary<string, string>
|
|
{
|
|
[plan.Sessions[0].SessionKey] = " Harbour sunset ",
|
|
[plan.Sessions[1].SessionKey] = " ",
|
|
["unknown"] = "ignored",
|
|
});
|
|
Assert.Equal("Harbour sunset", titled.Sessions[0].Title);
|
|
Assert.Null(titled.Sessions[1].Title);
|
|
Assert.Null(titled.Sessions[2].Title);
|
|
Assert.SequenceEqual(plan.Items.Select(i => i.FileName), titled.Items.Select(i => i.FileName));
|
|
}
|
|
|
|
[Test]
|
|
public void SessionRowsShowTimesIntervalsAndWhereTheyGo()
|
|
{
|
|
var plan = ThreeSessions();
|
|
var rows = ImportPlans.Sessions(plan, ImportDestinationKind.Archive, new HashSet<string>(["2026/2026-09-29 Canon EOS R5"], StringComparer.OrdinalIgnoreCase));
|
|
Assert.Equal(3, rows.Count);
|
|
Assert.Equal("4 · 2 s", rows[0].FramesText);
|
|
Assert.Equal("2 · 2 min", rows[1].FramesText);
|
|
Assert.Equal("1", rows[2].FramesText);
|
|
Assert.True(rows[0].IsNew);
|
|
Assert.Equal("New · 2026/2026-09-28 Canon EOS R5", rows[0].TargetText);
|
|
Assert.False(rows[1].IsNew);
|
|
Assert.Equal("Adds to · 2026/2026-09-29 Canon EOS R5", rows[1].TargetText);
|
|
Assert.Equal("2026-09-28 Canon EOS R5", rows[0].DefaultTitle);
|
|
Assert.Equal("Canon EOS R5", rows[0].CameraText);
|
|
Assert.Equal("96 MB", rows[0].SizeText);
|
|
Assert.Contains("6:02", rows[0].TimeText);
|
|
Assert.Equal("Server", ImportPlans.Sessions(plan, ImportDestinationKind.Server, new HashSet<string>())[0].TargetText);
|
|
}
|
|
|
|
[Test]
|
|
public void ShowPlanListsEveryFileItsDestinationAndTheConflicts()
|
|
{
|
|
var plan = ThreeSessions(available: 100_000_000);
|
|
var details = ImportPlans.Details(plan, ImportDestinationKind.Archive, verify: true);
|
|
Assert.Equal(plan.FileCount + plan.Sessions.Count, details.Rows.Count);
|
|
Assert.Equal(3, details.Rows.Count(r => r.Kind == PlanRowKind.Session));
|
|
var first = details.Rows[1];
|
|
Assert.Equal("DCIM/100CANON/IMG_0001.CR2", first.Source);
|
|
Assert.Equal("2026/2026-09-28 Canon EOS R5/originals/" + plan.Sessions[0].Items[0].FileName, first.Destination);
|
|
Assert.Equal("Copy", first.ActionText);
|
|
Assert.False(first.IsSkipped);
|
|
Assert.True(details.Rows.Single(r => r.Source.EndsWith("0007.CR2", StringComparison.Ordinal)).IsSkipped);
|
|
Assert.Equal(3, details.Conflicts.Count);
|
|
Assert.Contains("IMG_0099.CR2", details.Conflicts[0]);
|
|
Assert.Equal("7 files · copy 5 (120 MB) · 1 imported before · 1 duplicate", details.TotalsText);
|
|
|
|
var folder = ImportPlans.Details(plan, ImportDestinationKind.Folder, verify: true);
|
|
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, folder.Rows[1].Destination);
|
|
}
|
|
|
|
[Test]
|
|
public void TheNamePreviewIsTheFirstCopiedFile()
|
|
{
|
|
var plan = ThreeSessions();
|
|
Assert.Equal("2026/2026-09-28 Canon EOS R5/" + plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestination(plan, ImportDestinationKind.Archive));
|
|
Assert.Equal(plan.Sessions[0].Items[0].FileName, ImportPlans.FirstDestination(plan, ImportDestinationKind.Server));
|
|
var nothing = ImportPlans.WithDuplicates(Plan(null, null, Session(1, "x", Item(1, Start, action: ImportAction.SkipImported))), DuplicatePolicy.Skip);
|
|
Assert.Null(ImportPlans.FirstDestination(nothing, ImportDestinationKind.Archive));
|
|
}
|
|
}
|