2026-07-07 13:05:07 +05:30
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
|
|
|
|
using PiiRedaction.Core.Configuration;
|
|
|
|
|
using PiiRedaction.Core.Models;
|
|
|
|
|
using PiiRedaction.Infrastructure.Onnx;
|
|
|
|
|
|
|
|
|
|
namespace PiiRedaction.Infrastructure.Tests.Onnx;
|
|
|
|
|
|
|
|
|
|
[TestFixture]
|
|
|
|
|
public sealed class OnnxNerModelRunnerTests
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Constructor_MissingModel_IsModelUnavailable()
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(Path.GetTempPath(), $"missing-ner-{Guid.NewGuid():N}.onnx");
|
|
|
|
|
using var runner = CreateRunner(path);
|
|
|
|
|
|
|
|
|
|
runner.IsModelAvailable.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PredictEntities_WhenModelUnavailable_ReturnsEmpty()
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(Path.GetTempPath(), $"missing-ner-{Guid.NewGuid():N}.onnx");
|
|
|
|
|
using var runner = CreateRunner(path);
|
|
|
|
|
|
2026-07-08 12:18:27 +05:30
|
|
|
runner.PredictEntities("Customer Ravi Kumar").Entities.Should().BeEmpty();
|
2026-07-07 13:05:07 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void Constructor_InvalidModelFile_IsModelUnavailable()
|
|
|
|
|
{
|
|
|
|
|
var path = Path.Combine(Path.GetTempPath(), $"invalid-ner-{Guid.NewGuid():N}.onnx");
|
|
|
|
|
File.WriteAllText(path, "not-a-valid-onnx-model");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using var runner = CreateRunner(path);
|
|
|
|
|
runner.IsModelAvailable.Should().BeFalse();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
File.Delete(path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static OnnxNerModelRunner CreateRunner(string modelPath)
|
|
|
|
|
{
|
|
|
|
|
var options = Options.Create(new PiiRedactionOptions { OnnxModelPath = modelPath });
|
|
|
|
|
return new OnnxNerModelRunner(options, NullLogger<OnnxNerModelRunner>.Instance);
|
|
|
|
|
}
|
|
|
|
|
}
|