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,16 +13,23 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
using var stream = File.OpenRead("appsettings.local.json");
using var json = JsonDocument.Parse(stream);
var config = json.RootElement.GetProperty("WechatConfig");
WechatAppId = config.GetProperty("AppId").GetString();
WechatAppSecret = config.GetProperty("AppSecret").GetString();
WechatAccessToken = config.GetProperty("AccessToken").GetString();
WechatOpenId = config.GetProperty("OpenId").GetString();
ProjectSourceDirectory = json.RootElement.GetProperty("ProjectSourceDirectory").GetString();
ProjectTestDirectory = json.RootElement.GetProperty("ProjectTestDirectory").GetString();
}
public static readonly string WechatAppId;
public static readonly string WechatAppSecret;
public static readonly string WechatAccessToken;
public static readonly string WechatOpenId;
public static readonly string ProjectSourceDirectory;
public static readonly string ProjectTestDirectory;
}
}

View File

@@ -27,7 +27,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.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.Api.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.Api.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

@@ -4,5 +4,7 @@
"AppSecret": "请在此填写用于测试的微信 AppSecret",
"AccessToken": "请在此填写用于测试的微信 AccessToken",
"OpenId": "请在此填写用于测试的微信用户唯一标识"
}
},
"ProjectSourceDirectory": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.Api\\",
"ProjectTestDirectory": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.Api.UnitTests\\"
}