openai/openai-dotnet
Publicmirrored from https://github.com/openai/openai-dotnetAvailable
codegen/generator/test/common/Helpers.cs
40lines · modecode
| 1 | using System.IO; |
| 2 | using System.Linq; |
| 3 | using System.Runtime.CompilerServices; |
| 4 | |
| 5 | namespace OpenAILibraryPlugin.Tests.Common |
| 6 | { |
| 7 | /// <summary> |
| 8 | /// Helper methods for OpenAI plugin tests |
| 9 | /// </summary> |
| 10 | public static class Helpers |
| 11 | { |
| 12 | /// <summary> |
| 13 | /// Get expected content from file with naming convention |
| 14 | /// </summary> |
| 15 | /// <param name="parameters"></param> |
| 16 | /// <param name="method"></param> |
| 17 | /// <param name="filePath"></param> |
| 18 | /// <returns></returns> |
| 19 | public static string GetExpectedFromFile( |
| 20 | string? parameters = null, |
| 21 | [CallerMemberName] string method = "", |
| 22 | [CallerFilePath] string filePath = "") |
| 23 | { |
| 24 | return File.ReadAllText(GetAssetFileOrDirectoryPath(true, parameters, method, filePath)).Replace("\r\n", "\n"); |
| 25 | } |
| 26 | |
| 27 | private static string GetAssetFileOrDirectoryPath( |
| 28 | bool isFile, |
| 29 | string? parameters = null, |
| 30 | [CallerMemberName] string method = "", |
| 31 | [CallerFilePath] string filePath = "") |
| 32 | { |
| 33 | var callingClass = Path.GetFileName(filePath).Split('.').First(); |
| 34 | var paramString = parameters is null ? string.Empty : $"({parameters})"; |
| 35 | var extName = isFile ? ".cs" : string.Empty; |
| 36 | |
| 37 | return Path.Combine(Path.GetDirectoryName(filePath)!, "TestData", callingClass, $"{method}{paramString}{extName}"); |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |