Catalog/MaddoShared.Tests/Test1.cs

48 lines
1.3 KiB
C#

using ImageCatalog_2.Services;
using ImageCatalog_2.Models;
using Shouldly;
namespace MaddoShared.Tests;
[TestClass]
public sealed class AiExtractionServiceCsvTests
{
[TestMethod]
public void WriteCsvOutput_UsesLegacyCompatibleHeaderAndFilenameColumn()
{
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()
{
if (Directory.Exists(Path))
{
Directory.Delete(Path, recursive: true);
}
}
}
}