test: 设计代码分析工具,以规避拼写错误导致的 API 定义问题

This commit is contained in:
Fu Diwei
2021-06-07 11:18:27 +08:00
parent d136eb3d09
commit 1b20769099
13 changed files with 219 additions and 34 deletions

View File

@@ -11,15 +11,9 @@
<Content Include="appsettings.local.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ModelSamples/**/*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="EventSamples/**/*.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="EventSamples/**/*.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="ModelSamples/**/*.json" />
<Content Include="EventSamples/**/*.json" />
<Content Include="EventSamples/**/*.xml" />
</ItemGroup>
<ItemGroup>

View File

@@ -13,14 +13,21 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
using var stream = File.OpenRead("appsettings.local.json");
using var json = JsonDocument.Parse(stream);
var config = json.RootElement.GetProperty("WechatConfig");
WechatCorpId = config.GetProperty("CorpId").GetString();
WechatAgentId = int.Parse(config.GetProperty("AgentId").GetString());
WechatAgentSecret = config.GetProperty("AgentSecret").GetString();
ProjectSourceDirectory = json.RootElement.GetProperty("ProjectSourceDirectory").GetString();
ProjectTestDirectory = json.RootElement.GetProperty("ProjectTestDirectory").GetString();
}
public static readonly string WechatCorpId;
public static readonly int WechatAgentId;
public static readonly string WechatAgentSecret;
public static readonly string ProjectSourceDirectory;
public static readonly string ProjectTestDirectory;
}
}

View File

@@ -27,7 +27,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
[Fact(DisplayName = "验证 API 模型定义")]
public void ApiModelsDefinitionTest()
{
string workdir = Path.Combine(Environment.CurrentDirectory, "ModelSamples");
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
@@ -41,7 +41,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
[Fact(DisplayName = "验证 API 事件定义")]
public void ApiEventsDefinitionTest()
{
string workdir = Path.Combine(Environment.CurrentDirectory, "EventSamples");
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples");
Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex);
@@ -62,5 +62,19 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
Assert.Null(ex);
}
[Fact(DisplayName = "验证 API 接口文档注释")]
public void ApiExtensionsDocumentationTest()
{
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory, "Extensions");
Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiExtensionsSourceCodeStyle(workdir, out var ex);
if (ex != null)
throw ex;
Assert.Null(ex);
}
}
}

View File

@@ -3,5 +3,7 @@
"CorpId": "请在此填写用于测试的企业微信 CorpId",
"AgentId": "请在此填写用于测试的企业微信 AgentId",
"AgentSecret": "请在此填写用于测试的企业微信 AgentSecret"
}
},
"ProjectSourceDirectory": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.Work\\",
"ProjectTestDirectory": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.TenpayV3.Work\\"
}