namespace Theriapolis.Tests;

/// <summary>Shared test utilities.</summary>
internal static class TestHelpers
{
    /// <summary>
    /// Resolves the Content/Data directory for tests.
    /// xUnit runs from the test output directory; the .csproj copies Data/* there.
    /// </summary>
    public static string DataDirectory
    {
        get
        {
            // First: "Data" next to the test assembly (copied by .csproj)
            string local = Path.Combine(AppContext.BaseDirectory, "Data");
            if (Directory.Exists(local)) return local;

            // Fallback: walk up from the assembly to find Content/Data
            string? dir = AppContext.BaseDirectory;
            for (int i = 0; i < 7; i++)
            {
                string candidate = Path.Combine(dir ?? "", "Content", "Data");
                if (Directory.Exists(candidate)) return candidate;
                dir = Path.GetDirectoryName(dir);
            }

            throw new DirectoryNotFoundException(
                "Cannot locate Content/Data directory. " +
                $"Searched from: {AppContext.BaseDirectory}");
        }
    }
}
