feat(openai): 导入对话开放平台项目

This commit is contained in:
Fu Diwei
2021-10-07 21:19:24 +08:00
parent 9aa017fdfe
commit 038d1d1293
16 changed files with 586 additions and 1 deletions

View File

@@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ModelSamples/**/*.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SKIT.FlurlHttpClient.Wechat.OpenAI\SKIT.FlurlHttpClient.Wechat.OpenAI.csproj" />
<ProjectReference Include="..\SKIT.FlurlHttpClient.Wechat.TestTools\SKIT.FlurlHttpClient.Wechat.TestTools.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,18 @@
using System;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
{
class TestClients
{
static TestClients()
{
Instance = new WechatOpenAIClient(new WechatOpenAIClientOptions()
{
ClientId = TestConfigs.WechatClientId,
ClientKey = TestConfigs.WechatClientKey
});
}
public static readonly WechatOpenAIClient Instance;
}
}

View File

@@ -0,0 +1,33 @@
using System;
using System.IO;
using System.Text.Json;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
{
class TestConfigs
{
static TestConfigs()
{
// NOTICE: 请在项目根目录下按照 appsettings.json 的格式填入测试参数。
// WARN: 敏感信息请不要提交到 git
using var stream = File.OpenRead("appsettings.json");
using var json = JsonDocument.Parse(stream);
var config = json.RootElement.GetProperty("WechatConfig");
WechatClientId = config.GetProperty("ClientId").GetString();
WechatClientKey = config.GetProperty("ClientKey").GetString();
WechatAccessToken = config.GetProperty("AccessToken").GetString();
ProjectSourceDirectory = json.RootElement.GetProperty("ProjectSourceDirectory").GetString();
ProjectTestDirectory = json.RootElement.GetProperty("ProjectTestDirectory").GetString();
}
public static readonly string WechatClientId;
public static readonly string WechatClientKey;
public static readonly string WechatAccessToken;
public static readonly string ProjectSourceDirectory;
public static readonly string ProjectTestDirectory;
}
}

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
{
public class WechatOpenAIDeclarationTests
{
private static readonly Assembly _assembly = Assembly.Load("SKIT.FlurlHttpClient.Wechat.OpenAI");
[Fact(DisplayName = "验证 API 模型命名")]
public void ApiModelsNamingTest()
{
CodeStyleUtil.VerifyApiModelsNaming(_assembly, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
[Fact(DisplayName = "验证 API 模型定义")]
public void ApiModelsDefinitionTest()
{
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir));
CodeStyleUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
[Fact(DisplayName = "验证 API 事件定义")]
public void ApiEventsDefinitionTest()
{
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples");
Assert.True(Directory.Exists(workdir));
CodeStyleUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
[Fact(DisplayName = "验证 API 接口命名")]
public void ApiExtensionsNamingTest()
{
CodeStyleUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
[Fact(DisplayName = "验证代码规范")]
public void CodeStyleTest()
{
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir));
CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
}
}

View File

@@ -0,0 +1,9 @@
{
"WechatConfig": {
"ClientId": "请在此填写用于测试的微信智能对话 ClientId",
"ClientKey": "请在此填写用于测试的微信智能对话 ClientKey",
"AccessToken": "请在此填写用于测试的微信智能对话 AccessToken"
},
"ProjectSourceDirectory": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.OpenAI\\",
"ProjectTestDirectory": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests\\"
}