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,19 +2,24 @@
<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" />
</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,20 +8,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.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");
WechatAgencyId = config.GetProperty("AgencyId").GetString();
WechatAgencyAppId = config.GetProperty("AgencyAppId").GetString();
WechatAgencyApiKey = config.GetProperty("AgencyApiKey").GetString();
WechatAccessToken = config.GetProperty("AccessToken").GetString();
var config = jdoc.RootElement.GetProperty("WechatConfig");
WechatAgencyId = config.GetProperty("AgencyId").GetString();
WechatAgencyAppId = config.GetProperty("AgencyAppId").GetString();
WechatAgencyApiKey = config.GetProperty("AgencyApiKey").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 WechatAgencyId;

View File

@@ -28,8 +28,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.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)
@@ -53,8 +51,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.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

@@ -5,6 +5,6 @@
"AgencyApiKey": "请在此填写用于测试的微信广告 AgencyApiKey",
"AccessToken": "请在此填写用于测试的微信广告 AccessToken"
},
"ProjectSourceDirectory": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.Api\\",
"ProjectTestDirectory": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.Api.UnitTests\\"
"ProjectSourceDirectory": "请输入当前 SDK 项目所在的目录完整路径,如 C:\\Project\\src\\SKIT.FlurlHttpClient.Wechat.Ads\\",
"ProjectTestDirectory": "请输入当前测试项目所在的目录完整路径,如 C:\\Project\\test\\SKIT.FlurlHttpClient.Wechat.Ads.UnitTests\\"
}