Card scanning (DCIM and flat), session splitting with test-shot merging and user splits/merges, per-body import plans named by templates with archive duplicate detection, hash-verified resumable copy with per-file errors, a plain-folder destination and a verified card erase with dry run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
49 lines
2.4 KiB
C#
49 lines
2.4 KiB
C#
using Titano.Core.Import;
|
|
|
|
namespace Titano.Core.Tests.Import;
|
|
|
|
/// <summary>An <see cref="IImportLookup"/> answered from in-memory sets.</summary>
|
|
internal sealed class FakeLookup : IImportLookup
|
|
{
|
|
public HashSet<string> Imported { get; } = [];
|
|
public List<(long Size, DateTime Captured, ArchiveMatch Match)> Archive { get; } = [];
|
|
public Dictionary<string, string> SessionFolders { get; } = [];
|
|
public HashSet<string> TakenFolders { get; } = new(StringComparer.OrdinalIgnoreCase);
|
|
public int CandidateQueries { get; private set; }
|
|
|
|
public Task<bool> WasImportedAsync(CardFile file, CancellationToken cancellationToken) => Task.FromResult(Imported.Contains(file.RelativePath));
|
|
|
|
public Task<IReadOnlyList<ArchiveMatch>> FindCandidatesAsync(long size, DateTime capturedAt, CancellationToken cancellationToken)
|
|
{
|
|
CandidateQueries++;
|
|
return Task.FromResult<IReadOnlyList<ArchiveMatch>>(Archive.Where(a => a.Size == size && a.Captured == capturedAt).Select(a => a.Match).ToList());
|
|
}
|
|
|
|
public Task<string?> FindSessionFolderAsync(string sessionKey, CancellationToken cancellationToken) =>
|
|
Task.FromResult(SessionFolders.GetValueOrDefault(sessionKey));
|
|
|
|
public bool IsFolderTaken(string folder) => TakenFolders.Contains(folder);
|
|
}
|
|
|
|
internal static class ImportTestKit
|
|
{
|
|
public static readonly DateTime Start = new(2026, 9, 28, 18, 0, 0);
|
|
|
|
/// <summary>Plans an import of <paramref name="card"/> into <paramref name="destination"/>.</summary>
|
|
public static async Task<ImportPlan> PlanAsync(string card, string destination, ImportOptions? options = null, FakeLookup? lookup = null)
|
|
{
|
|
options ??= new ImportOptions();
|
|
var problems = new List<ImportProblem>();
|
|
var photos = CardScanner.ReadMetadata(card, CardScanner.Find(card, options.IncludeSubfolders), problems);
|
|
return await ImportPlanner.PlanAsync(card, destination, photos, problems, options, lookup ?? new FakeLookup());
|
|
}
|
|
|
|
/// <summary>Every file below <paramref name="root"/> (relative, forward slashes), excluding Titano's metadata folders.</summary>
|
|
public static List<string> Files(string root) =>
|
|
Directory.EnumerateFiles(root, "*", SearchOption.AllDirectories)
|
|
.Select(f => Path.GetRelativePath(root, f).Replace('\\', '/'))
|
|
.Where(f => !f.StartsWith(".titano/", StringComparison.Ordinal))
|
|
.Order(StringComparer.Ordinal)
|
|
.ToList();
|
|
}
|