2026-07-07 13:05:07 +05:30
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using PiiRedaction.Core.Configuration;
|
|
|
|
|
using PiiRedaction.Infrastructure.Onnx;
|
|
|
|
|
|
|
|
|
|
namespace PiiRedaction.Tests.Shared;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2026-07-07 17:12:38 +05:30
|
|
|
/// Reuses a single <see cref="EnglishOnnxNerRunner"/> per fixture for performance.
|
2026-07-07 13:05:07 +05:30
|
|
|
/// Skips all tests in the class when the ONNX model is missing or cannot be loaded.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class RealNerModelFixture
|
|
|
|
|
{
|
2026-07-07 17:12:38 +05:30
|
|
|
protected EnglishOnnxNerRunner Runner { get; private set; } = null!;
|
2026-07-07 13:05:07 +05:30
|
|
|
|
|
|
|
|
protected string ModelPath { get; private set; } = null!;
|
|
|
|
|
|
|
|
|
|
[OneTimeSetUp]
|
|
|
|
|
public void OneTimeSetUpRealModel()
|
|
|
|
|
{
|
|
|
|
|
ModelPath = RealNerModelPaths.ResolveRepoModelPath();
|
|
|
|
|
if (!File.Exists(ModelPath))
|
|
|
|
|
{
|
|
|
|
|
Assert.Ignore(RealNerModelPaths.ModelMissingMessage);
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 17:12:38 +05:30
|
|
|
var options = Options.Create(new PiiRedactionOptions
|
|
|
|
|
{
|
|
|
|
|
EnglishOnnxModelPath = ModelPath,
|
|
|
|
|
OnnxModelPath = ModelPath
|
|
|
|
|
});
|
|
|
|
|
Runner = new EnglishOnnxNerRunner(options, NullLogger<EnglishOnnxNerRunner>.Instance);
|
2026-07-07 13:05:07 +05:30
|
|
|
|
|
|
|
|
if (!Runner.IsModelAvailable)
|
|
|
|
|
{
|
|
|
|
|
Runner.Dispose();
|
|
|
|
|
Assert.Ignore(RealNerModelPaths.ModelMissingMessage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[OneTimeTearDown]
|
|
|
|
|
public void OneTimeTearDownRealModel()
|
|
|
|
|
{
|
|
|
|
|
Runner?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
}
|