BRIEF §13 camera profiles: the settings saved last by another card of the same camera model; a card seen for the first time takes them once its first plan names the camera. Remembered cards without settings start from the archive's templates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
99 lines
4.5 KiB
C#
99 lines
4.5 KiB
C#
using System.Text.Json;
|
|
using System.Text.Json.Serialization;
|
|
using Titano.App.Import;
|
|
using Titano.Core.Import;
|
|
using Titano.Core.Model;
|
|
using Titano.Data.Archiving;
|
|
using Titano.Testing;
|
|
|
|
namespace Titano.App.Tests.Import;
|
|
|
|
public sealed class ImportChoicesTests
|
|
{
|
|
[Test]
|
|
public void ACardProfileRoundTripsThroughTheForm()
|
|
{
|
|
var profile = new CardProfile
|
|
{
|
|
FolderTemplate = "{year}/{title}",
|
|
FileTemplate = "{name}",
|
|
SessionGapMinutes = 30,
|
|
MinimumSessionFrames = 4,
|
|
IncludeSubfolders = false,
|
|
VerifyCopies = false,
|
|
Duplicates = DuplicatePolicy.ImportAgain,
|
|
AfterImport = AfterImport.DeleteImported,
|
|
Eject = false,
|
|
DeepAnalysis = false,
|
|
};
|
|
var choices = ImportChoices.FromProfile(profile);
|
|
Assert.True(choices.SplitSessions);
|
|
Assert.Equal(30, choices.GapMinutes);
|
|
Assert.Equal(profile, choices.ToProfile());
|
|
}
|
|
|
|
[Test]
|
|
public void SessionsOffIsRememberedAsAZeroGapAndNeverSplits()
|
|
{
|
|
var off = new ImportChoices { SplitSessions = false, GapMinutes = 20 };
|
|
Assert.Equal(0, off.ToProfile().SessionGapMinutes);
|
|
Assert.Equal(TimeSpan.MaxValue, off.ToOptions().SessionGap);
|
|
var back = ImportChoices.FromProfile(off.ToProfile());
|
|
Assert.False(back.SplitSessions);
|
|
Assert.Equal(new CardProfile().SessionGapMinutes, back.GapMinutes);
|
|
Assert.Equal(TimeSpan.FromMinutes(20), (off with { SplitSessions = true }).ToOptions().SessionGap);
|
|
}
|
|
|
|
[Test]
|
|
public void OptionsCarryTheFormAndTheTypedTitles()
|
|
{
|
|
var titles = new Dictionary<string, string> { ["k"] = "Harbour" };
|
|
var options = new ImportChoices { MinimumFrames = 0, Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false }.ToOptions(titles);
|
|
Assert.Equal(1, options.MinimumSessionFrames);
|
|
Assert.Equal(DuplicatePolicy.ImportAgain, options.Duplicates);
|
|
Assert.False(options.VerifyCopies);
|
|
Assert.Equal("Harbour", options.Titles["k"]);
|
|
}
|
|
|
|
[Test]
|
|
public void OnlyGroupingAndNamingChoicesNeedANewPlan()
|
|
{
|
|
var a = new ImportChoices();
|
|
Assert.False((a with { Duplicates = DuplicatePolicy.ImportAgain, VerifyCopies = false, Eject = false, AfterImport = AfterImport.FormatCard }).NeedsNewPlan(a));
|
|
Assert.False((a with { SplitSessions = false, GapMinutes = 5 }).NeedsNewPlan(a with { SplitSessions = false }));
|
|
Assert.True((a with { GapMinutes = 5 }).NeedsNewPlan(a));
|
|
Assert.True((a with { MinimumFrames = 2 }).NeedsNewPlan(a));
|
|
Assert.True((a with { FileTemplate = "{name}" }).NeedsNewPlan(a));
|
|
Assert.True((a with { Destination = ImportDestinationKind.Folder }).NeedsNewPlan(a));
|
|
Assert.True((a with { IncludeSubfolders = false }).NeedsNewPlan(a));
|
|
Assert.False(a.TitlesChangeNames);
|
|
Assert.True((a with { FolderTemplate = "{year}/{Title:upper}" }).TitlesChangeNames);
|
|
}
|
|
|
|
[Test]
|
|
public void ACardWithoutSettingsTakesTheLastSavedProfileOfItsCamera()
|
|
{
|
|
var older = Card("Canon", "Canon EOS R5", new CardProfile { SessionGapMinutes = 20 }, daysAgo: 30);
|
|
var newer = Card("Canon", "Canon EOS R5", new CardProfile { SessionGapMinutes = 90 }, daysAgo: 2);
|
|
var other = Card("SONY", "ILCE-7M4", new CardProfile { SessionGapMinutes = 5 }, daysAgo: 1);
|
|
var unsaved = Card("Canon", "Canon EOS R5", null, daysAgo: 0);
|
|
Assert.Equal(90, CameraProfiles.Find("Canon", "Canon EOS R5", [older, newer, other, unsaved])!.SessionGapMinutes);
|
|
Assert.Null(CameraProfiles.Find("Canon", "Canon EOS R6", [older, newer, other]));
|
|
Assert.Null(CameraProfiles.Find("Canon", null, [older, newer]));
|
|
Assert.Null(CameraProfiles.Find("Canon", "Canon EOS R5", [unsaved]), "only saved settings are shared");
|
|
}
|
|
|
|
private static MediaCard Card(string make, string model, CardProfile? profile, int daysAgo) => new()
|
|
{
|
|
Id = Guid.CreateVersion7(),
|
|
Identity = Guid.NewGuid().ToString("N"),
|
|
CameraMake = make,
|
|
CameraModel = model,
|
|
ProfileJson = profile is null ? null : JsonSerializer.Serialize(profile, StoredProfile),
|
|
LastSeen = DateTimeOffset.UtcNow.AddDays(-daysAgo),
|
|
};
|
|
|
|
/// <summary>How the card repository stores a profile (camel case, enum names).</summary>
|
|
private static readonly JsonSerializerOptions StoredProfile = new() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, Converters = { new JsonStringEnumConverter() } };
|
|
}
|