Files
OpenNest.Test/TestData.cs
2026-03-09 21:07:04 -04:00

65 lines
1.6 KiB
C#

using OpenNest.IO;
namespace OpenNest.Test;
public static class TestData
{
private static readonly string? BasePath = ResolveBasePath();
public static bool IsAvailable => BasePath != null;
public static string SkipReason =>
"Test data not found. Fixture .zip files should be in the repo root.";
public static string GetPath(string filename)
{
if (BasePath == null)
throw new InvalidOperationException(SkipReason);
var path = Path.Combine(BasePath, filename);
if (!File.Exists(path))
throw new FileNotFoundException($"Test fixture not found: {path}");
return path;
}
public static Nest LoadNest(string filename)
{
var reader = new NestReader(GetPath(filename));
return reader.Read();
}
public static Plate CleanPlateFrom(Plate reference)
{
var plate = new Plate();
plate.Size = reference.Size;
plate.PartSpacing = reference.PartSpacing;
plate.EdgeSpacing = reference.EdgeSpacing;
plate.Quadrant = reference.Quadrant;
return plate;
}
private static string? ResolveBasePath()
{
// Walk up from bin/Debug/net8.0-windows to find the repo root
// (where the .zip fixture files live alongside the csproj).
var dir = AppContext.BaseDirectory;
for (var i = 0; i < 6; i++)
{
var parent = Directory.GetParent(dir);
if (parent == null)
break;
dir = parent.FullName;
if (File.Exists(Path.Combine(dir, "OpenNest.Test.csproj")))
return dir;
}
return null;
}
}