feat: Update package references and enhance AI extraction service with CSV output functionality

This commit is contained in:
Maddo 2026-05-24 17:29:05 +02:00
commit af74c90ce7
12 changed files with 400 additions and 153 deletions

View file

@ -0,0 +1,58 @@
using System;
using System.IO;
using ImageCatalog;
using ImageCatalog_2.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
namespace MaddoShared.Tests;
[TestClass]
public class PickerPreferenceServiceTests
{
[TestMethod]
public void RememberValue_PersistsExactFilePath()
{
using var tempDirectory = new TemporaryDirectory();
var preferencesFile = Path.Combine(tempDirectory.Path, "userprefs.xml");
var service = new PickerPreferenceService(new ParametriSetup(preferencesFile));
var settingsFile = Path.Combine(tempDirectory.Path, "nested", "settings.xml");
service.RememberValue(PickerPreferenceKeys.LastSettingsFile, settingsFile);
service.GetRememberedValue(PickerPreferenceKeys.LastSettingsFile).ShouldBe(settingsFile);
}
[TestMethod]
public void ForgetValue_RemovesStoredPreference()
{
using var tempDirectory = new TemporaryDirectory();
var preferencesFile = Path.Combine(tempDirectory.Path, "userprefs.xml");
var service = new PickerPreferenceService(new ParametriSetup(preferencesFile));
service.RememberValue(PickerPreferenceKeys.LastSettingsFile, Path.Combine(tempDirectory.Path, "settings.xml"));
service.ForgetValue(PickerPreferenceKeys.LastSettingsFile);
service.GetRememberedValue(PickerPreferenceKeys.LastSettingsFile).ShouldBeNull();
}
private sealed class TemporaryDirectory : IDisposable
{
public TemporaryDirectory()
{
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);
}
}
}
}

View file

@ -1,11 +1,48 @@
namespace MaddoShared.Tests
using ImageCatalog_2.Services;
using ImageCatalog_2.Models;
using Shouldly;
namespace MaddoShared.Tests;
[TestClass]
public sealed class AiExtractionServiceCsvTests
{
[TestClass]
public sealed class Test1
[TestMethod]
public void WriteCsvOutput_UsesLegacyCompatibleHeaderAndFilenameColumn()
{
[TestMethod]
public void TestMethod1()
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);
}
}
}
}