FEAT-8c: loader tests (in-memory DB + fixture) + public test helpers

6 tests: dry-run categorisation (no writes), execute loads conflict-free + links
high-confidence + quarantines conflict/stub, idempotency, ComposeGenotype (caret strip
+ ?? fill), ParseDate. Added EF InMemory to the test project.
This commit is contained in:
2026-06-06 07:36:29 +02:00
parent ac5ab9d0ba
commit b7ee48401a
3 changed files with 176 additions and 6 deletions

View File

@@ -32,12 +32,20 @@ namespace GerbilManagerWebAPI.Import
private readonly string _sourceDir;
private readonly string _photoRoot;
public ImportService(ApplicationContext db, IConfiguration config, IWebHostEnvironment env)
/// <summary>Test-friendly constructor with explicit paths.</summary>
public ImportService(ApplicationContext db, string sourceDir, string photoRoot)
{
_db = db;
_sourceDir = config["Import:SourcePath"]
?? Path.GetFullPath(Path.Combine(env.ContentRootPath, "..", "tools", "import", "output"));
_photoRoot = config["Photos:RootPath"] ?? Path.Combine(env.ContentRootPath, "photo-storage");
_sourceDir = sourceDir;
_photoRoot = photoRoot;
}
public ImportService(ApplicationContext db, IConfiguration config, IWebHostEnvironment env)
: this(db,
config["Import:SourcePath"]
?? Path.GetFullPath(Path.Combine(env.ContentRootPath, "..", "tools", "import", "output")),
config["Photos:RootPath"] ?? Path.Combine(env.ContentRootPath, "photo-storage"))
{
}
public async Task<ImportReport> RunAsync(bool execute)
@@ -241,7 +249,7 @@ namespace GerbilManagerWebAPI.Import
return JsonSerializer.Deserialize<T>(fs, Json);
}
internal static string ComposeGenotype(SourceGenotype g)
public static string ComposeGenotype(SourceGenotype g)
{
var tokens = LocusOrder.Select(locus =>
{
@@ -263,7 +271,7 @@ namespace GerbilManagerWebAPI.Import
return Gender.unknown;
}
internal static DateOnly? ParseDate(string s)
public static DateOnly? ParseDate(string s)
{
if (string.IsNullOrWhiteSpace(s)) return null;
var m = Regex.Match(s, @"(\d{1,2})\.(\d{1,2})\.(\d{2,4})");