openai/openai-dotnet

Public

mirrored from https://github.com/openai/openai-dotnetAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/customize-openairesponsescontext-attribute

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

codegen/generator/test/common/Helpers.cs

40lines · modecode

1using System.IO;
2using System.Linq;
3using System.Runtime.CompilerServices;
4
5namespace 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