using System.IO; using System.Linq; using System.Runtime.CompilerServices; namespace OpenAILibraryPlugin.Tests.Common { /// /// Helper methods for OpenAI plugin tests /// public static class Helpers { /// /// Get expected content from file with naming convention /// /// /// /// /// public static string GetExpectedFromFile( string? parameters = null, [CallerMemberName] string method = "", [CallerFilePath] string filePath = "") { return File.ReadAllText(GetAssetFileOrDirectoryPath(true, parameters, method, filePath)).Replace("\r\n", "\n"); } private static string GetAssetFileOrDirectoryPath( bool isFile, string? parameters = null, [CallerMemberName] string method = "", [CallerFilePath] string filePath = "") { var callingClass = Path.GetFileName(filePath).Split('.').First(); var paramString = parameters is null ? string.Empty : $"({parameters})"; var extName = isFile ? ".cs" : string.Empty; return Path.Combine(Path.GetDirectoryName(filePath)!, "TestData", callingClass, $"{method}{paramString}{extName}"); } } }