test: 修复检测工具的一处边界问题

This commit is contained in:
Fu Diwei 2021-08-16 15:25:06 +08:00
parent 5522bb49b7
commit 0076cacb0c
6 changed files with 25 additions and 24 deletions

View File

@ -27,8 +27,9 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3
if (client is null) throw new ArgumentNullException(nameof(client)); if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
// NOTICE: 注意 URL 结尾的反斜杠不能删除
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(request, HttpMethod.Post, "applyment4sub", "applyment/"); // NOTICE: 注意 URL 结尾的反斜杠不能删除 .CreateRequest(request, HttpMethod.Post, "applyment4sub", "applyment/");
return await client.SendRequestWithJsonAsync<Models.CreateApplyForSubMerchantApplymentResponse>(flurlReq, data: request, cancellationToken: cancellationToken); return await client.SendRequestWithJsonAsync<Models.CreateApplyForSubMerchantApplymentResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
} }

View File

@ -16,7 +16,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.UnitTests
[Fact(DisplayName = "验证 API 模型命名")] [Fact(DisplayName = "验证 API 模型命名")]
public void ApiModelsNamingTest() public void ApiModelsNamingTest()
{ {
TestAssertUtil.VerifyApiModelsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiModelsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -41,7 +41,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.UnitTests
[Fact(DisplayName = "验证 API 接口命名")] [Fact(DisplayName = "验证 API 接口命名")]
public void ApiExtensionsNamingTest() public void ApiExtensionsNamingTest()
{ {
TestAssertUtil.VerifyApiExtensionsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Ads.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory); string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifySourceCodeStyle(workdir, out var ex); CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;

View File

@ -16,7 +16,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
[Fact(DisplayName = "验证 API 模型命名")] [Fact(DisplayName = "验证 API 模型命名")]
public void ApiModelsNamingTest() public void ApiModelsNamingTest()
{ {
TestAssertUtil.VerifyApiModelsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiModelsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -44,7 +44,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
[Fact(DisplayName = "验证 API 接口命名")] [Fact(DisplayName = "验证 API 接口命名")]
public void ApiExtensionsNamingTest() public void ApiExtensionsNamingTest()
{ {
TestAssertUtil.VerifyApiExtensionsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -69,7 +69,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory); string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifySourceCodeStyle(workdir, out var ex); CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;

View File

@ -16,7 +16,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
[Fact(DisplayName = "验证 API 模型命名")] [Fact(DisplayName = "验证 API 模型命名")]
public void ApiModelsNamingTest() public void ApiModelsNamingTest()
{ {
TestAssertUtil.VerifyApiModelsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiModelsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -44,7 +44,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
[Fact(DisplayName = "验证 API 接口命名")] [Fact(DisplayName = "验证 API 接口命名")]
public void ApiExtensionsNamingTest() public void ApiExtensionsNamingTest()
{ {
TestAssertUtil.VerifyApiExtensionsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -69,7 +69,7 @@ namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory); string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifySourceCodeStyle(workdir, out var ex); CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;

View File

@ -9,7 +9,7 @@ using System.Xml.Serialization;
namespace SKIT.FlurlHttpClient.Wechat namespace SKIT.FlurlHttpClient.Wechat
{ {
public static class TestAssertUtil public static class CodeStyleUtil
{ {
private static bool TryJsonize(string json, Type type, out Exception exception) private static bool TryJsonize(string json, Type type, out Exception exception)
{ {
@ -400,8 +400,8 @@ namespace SKIT.FlurlHttpClient.Wechat
{ {
for (int urlSegmentIndex = 0; urlSegmentIndex < expectedUrlSegments.Length; urlSegmentIndex++) for (int urlSegmentIndex = 0; urlSegmentIndex < expectedUrlSegments.Length; urlSegmentIndex++)
{ {
string expectedUrlSegment = expectedUrlSegments[urlSegmentIndex]; string expectedUrlSegment = expectedUrlSegments[urlSegmentIndex].Trim('/');
string actualUrlSegment = actualUrlSegments[urlSegmentIndex]; string actualUrlSegment = actualUrlSegments[urlSegmentIndex].Trim('/');
if (expectedUrlSegment.Contains("{")) if (expectedUrlSegment.Contains("{"))
{ {
if (actualUrlSegment.StartsWith("\"")) if (actualUrlSegment.StartsWith("\""))
@ -412,7 +412,7 @@ namespace SKIT.FlurlHttpClient.Wechat
} }
else else
{ {
actualUrlSegment = actualUrlSegment.Replace("\"", string.Empty); actualUrlSegment = actualUrlSegment.Replace("\"", string.Empty).Trim('/');
if (!string.Equals(expectedUrlSegment, actualUrlSegment)) if (!string.Equals(expectedUrlSegment, actualUrlSegment))
{ {
lstError.Add(new Exception($"源代码 \"{extCodeFileName}\" 下第 {i + 1} 段文档注释有误,`[{expectedMethod}] {expectedUrl}` 与实际接口路由不一致。")); lstError.Add(new Exception($"源代码 \"{extCodeFileName}\" 下第 {i + 1} 段文档注释有误,`[{expectedMethod}] {expectedUrl}` 与实际接口路由不一致。"));

View File

@ -16,7 +16,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
[Fact(DisplayName = "验证 API 模型命名")] [Fact(DisplayName = "验证 API 模型命名")]
public void ApiModelsNamingTest() public void ApiModelsNamingTest()
{ {
TestAssertUtil.VerifyApiModelsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiModelsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "ModelSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiModelsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -44,7 +44,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples"); string workdir = Path.Combine(TestConfigs.ProjectTestDirectory, "EventSamples");
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex); CodeStyleUtil.VerifyApiEventsDefinition(_assembly, workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -55,7 +55,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
[Fact(DisplayName = "验证 API 接口命名")] [Fact(DisplayName = "验证 API 接口命名")]
public void ApiExtensionsNamingTest() public void ApiExtensionsNamingTest()
{ {
TestAssertUtil.VerifyApiExtensionsNaming(_assembly, out var ex); CodeStyleUtil.VerifyApiExtensionsNaming(_assembly, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;
@ -69,7 +69,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work.UnitTests
string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory); string workdir = Path.Combine(TestConfigs.ProjectSourceDirectory);
Assert.True(Directory.Exists(workdir)); Assert.True(Directory.Exists(workdir));
TestAssertUtil.VerifySourceCodeStyle(workdir, out var ex); CodeStyleUtil.VerifySourceCodeStyle(workdir, out var ex);
if (ex != null) if (ex != null)
throw ex; throw ex;