2026-05-24 17:29:05 +02:00
|
|
|
|
using ImageCatalog_2.Services;
|
|
|
|
|
|
using ImageCatalog_2.Models;
|
|
|
|
|
|
using Shouldly;
|
|
|
|
|
|
|
|
|
|
|
|
namespace MaddoShared.Tests;
|
|
|
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public sealed class AiExtractionServiceCsvTests
|
2026-02-04 19:01:00 +01:00
|
|
|
|
{
|
2026-05-24 17:29:05 +02:00
|
|
|
|
[TestMethod]
|
|
|
|
|
|
public void WriteCsvOutput_UsesLegacyCompatibleHeaderAndFilenameColumn()
|
2026-02-04 19:01:00 +01:00
|
|
|
|
{
|
2026-05-24 17:29:05 +02:00
|
|
|
|
using var tempDir = new TempDirectory();
|
|
|
|
|
|
var csvPath = Path.Combine(tempDir.Path, "ocr.csv");
|
|
|
|
|
|
|
|
|
|
|
|
AiExtractionService.WriteCsvOutput(
|
|
|
|
|
|
csvPath,
|
|
|
|
|
|
[
|
|
|
|
|
|
new AiResultItem { Path = @"C:\images\IMG_7146.JPG", Text = "43,84,61" },
|
|
|
|
|
|
new AiResultItem { Path = @"C:\images\IMG_7207.JPG", Text = "a\"b" }
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
var lines = File.ReadAllLines(csvPath);
|
|
|
|
|
|
|
|
|
|
|
|
lines[0].ShouldBe("filename,text");
|
|
|
|
|
|
lines[1].ShouldBe("\"IMG_7146.JPG\",\"43,84,61\"");
|
|
|
|
|
|
lines[2].ShouldBe("\"IMG_7207.JPG\",\"a\"\"b\"");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private sealed class TempDirectory : IDisposable
|
|
|
|
|
|
{
|
|
|
|
|
|
public TempDirectory()
|
|
|
|
|
|
{
|
|
|
|
|
|
Path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), System.IO.Path.GetRandomFileName());
|
|
|
|
|
|
Directory.CreateDirectory(Path);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Path { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
2026-02-04 19:01:00 +01:00
|
|
|
|
{
|
2026-05-24 17:29:05 +02:00
|
|
|
|
if (Directory.Exists(Path))
|
|
|
|
|
|
{
|
|
|
|
|
|
Directory.Delete(Path, recursive: true);
|
|
|
|
|
|
}
|
2026-02-04 19:01:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|