test: 优化 CodeStyle 测试流程

This commit is contained in:
Fu Diwei
2021-11-10 12:59:08 +08:00
parent 11ce0773a1
commit c8ee389674
20 changed files with 334 additions and 218 deletions

View File

@@ -2,20 +2,25 @@
<PropertyGroup>
<TargetFrameworks>netcoreapp3.1; net6.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<None Remove=".gitignore" />
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.json">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</Content>
<Content Include="appsettings.*.json" Condition="'$(Configuration)' == 'Debug'">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<Content Include="ModelSamples/**/*.json" />
<Content Include="EventSamples/**/*.xml" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>

View File

@@ -8,22 +8,29 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
{
static TestConfigs()
{
// NOTICE: 请在项目根目录下按照 appsettings.json 的格式填入测试参数。
// NOTICE: 请在项目根目录下按照 appsettings.json 的格式新建 appsettings.local.json 填入测试参数。
// WARN: 敏感信息请不要提交到 git
using var stream = File.OpenRead("appsettings.json");
using var json = JsonDocument.Parse(stream);
try
{
using var stream = File.OpenRead("appsettings.local.json");
using var jdoc = JsonDocument.Parse(stream);
var config = json.RootElement.GetProperty("WechatConfig");
WechatClientId = config.GetProperty("ClientId").GetString();
WechatClientKey = config.GetProperty("ClientKey").GetString();
WechatAppId = config.GetProperty("AppId").GetString();
WechatToken = config.GetProperty("Token").GetString();
WechatEncodingAESKey = config.GetProperty("EncodingAESKey").GetString();
WechatAccessToken = config.GetProperty("AccessToken").GetString();
var config = jdoc.RootElement.GetProperty("WechatConfig");
WechatClientId = config.GetProperty("ClientId").GetString();
WechatClientKey = config.GetProperty("ClientKey").GetString();
WechatAppId = config.GetProperty("AppId").GetString();
WechatToken = config.GetProperty("Token").GetString();
WechatEncodingAESKey = config.GetProperty("EncodingAESKey").GetString();
WechatAccessToken = config.GetProperty("AccessToken").GetString();
ProjectSourceDirectory = json.RootElement.GetProperty("ProjectSourceDirectory").GetString();
ProjectTestDirectory = json.RootElement.GetProperty("ProjectTestDirectory").GetString();
ProjectSourceDirectory = jdoc.RootElement.GetProperty("ProjectSourceDirectory").GetString();
ProjectTestDirectory = jdoc.RootElement.GetProperty("ProjectTestDirectory").GetString();
}
catch (Exception ex)
{
throw new Exception("加载配置文件 appsettings.local.json 失败", ex);
}
}
public static readonly string WechatClientId;

View File

@@ -28,8 +28,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
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)
@@ -42,8 +40,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
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)
@@ -67,8 +63,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
public void CodeStyleTest()
{
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir));
CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null)

View File

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