Files
DotNetCore.SKIT.FlurlHttpCl…/test/SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests/IMPORTANT_CodeAnalyzeTests.cs

124 lines
6.9 KiB
C#
Raw Normal View History

2024-01-29 23:12:37 +08:00
using System;
using System.IO;
using System.Reflection;
using SKIT.FlurlHttpClient.Tools.CodeAnalyzer;
using Xunit;
namespace SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests
{
using SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global;
2024-01-29 23:12:37 +08:00
public class CodeAnalyzeTests
{
2024-02-07 15:55:41 +08:00
// NOTICE:
// 如果 Visual Studio 遇到 “缺少 SKIT.FlurlHttpClient.Tools.CodeAnalyzer 包” 的错误,
// 请参考此 Issuehttps://github.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient/issues/8
2024-01-29 23:12:37 +08:00
[Fact(DisplayName = "代码质量分析")]
public void CodeAnalyze()
{
Assert.Multiple(
CodeAnalyze_BaseSDK,
CodeAnalyze_ExtendedSDK_Global
);
}
private void CodeAnalyze_BaseSDK()
2024-01-29 23:12:37 +08:00
{
Assert.Null(Record.Exception(() =>
{
var options = new TypeDeclarationAnalyzerOptions()
{
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayClient))!,
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Models",
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Models",
SdkExecutingExtensionDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3",
SdkWebhookEventDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Events",
IgnoreExecutingExtensionTypes = static type => type.Namespace!.Contains(".ExtendedSDK."),
2024-01-29 23:12:37 +08:00
ThrowOnNotFoundRequestModelTypes = true,
ThrowOnNotFoundResponseModelTypes = true,
ThrowOnNotFoundExecutingExtensionTypes = true,
ThrowOnNotFoundWebhookEventTypes = true
};
new TypeDeclarationAnalyzer(options).AssertNoIssues();
}));
Assert.Null(Record.Exception(() =>
{
string workdir = Environment.CurrentDirectory;
string projdir = Path.Combine(workdir, "../../../../../");
var options = new SourceFileAnalyzerOptions()
{
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayClient))!,
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Models",
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Models",
SdkWebhookEventDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.Events",
ProjectSourceRootDirectory = Path.Combine(projdir, "./src/SKIT.FlurlHttpClient.Wechat.TenpayV3/"),
ProjectTestRootDirectory = Path.Combine(projdir, "./test/SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests/"),
ProjectTestRequestModelSerializationSampleSubDirectory = "ModelSamples/_/",
ProjectTestResponseModelSerializationSampleSubDirectory = "ModelSamples/_/",
ProjectTestWebhookEventSerializationSampleSubDirectory = "EventSamples/_/",
2024-01-29 23:12:37 +08:00
ThrowOnNotFoundRequestModelClassCodeFiles = true,
ThrowOnNotFoundResponseModelClassCodeFiles = true,
ThrowOnNotFoundExecutingExtensionClassCodeFiles = true,
ThrowOnNotFoundWebhookEventClassCodeFiles = true,
ThrowOnNotFoundRequestModelSerializationSampleFiles = true,
ThrowOnNotFoundResponseModelSerializationSampleFiles = true,
ThrowOnNotFoundWebhookEventSerializationSampleFiles = true
};
new SourceFileAnalyzer(options)
.SetFileScanner(SourceFileContentKinds.WebhookEventClassCode, (directory) => directory.GetAllFiles("*.cs"))
.SetFileScanner(SourceFileContentKinds.WebhookEventSerializationSample, (directory) => directory.GetAllFiles("*.json"))
.AssertNoIssues();
}));
}
private void CodeAnalyze_ExtendedSDK_Global()
{
Assert.Null(Record.Exception(() =>
{
var options = new TypeDeclarationAnalyzerOptions()
{
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayGlobalClient))!,
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global.Models",
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global.Models",
SdkExecutingExtensionDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global",
ThrowOnNotFoundRequestModelTypes = true,
ThrowOnNotFoundResponseModelTypes = true,
ThrowOnNotFoundExecutingExtensionTypes = true
};
new TypeDeclarationAnalyzer(options).AssertNoIssues();
}));
Assert.Null(Record.Exception(() =>
{
string workdir = Environment.CurrentDirectory;
string projdir = Path.Combine(workdir, "../../../../../");
var options = new SourceFileAnalyzerOptions()
{
SdkAssembly = Assembly.GetAssembly(typeof(WechatTenpayGlobalClient))!,
SdkRequestModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global.Models",
SdkResponseModelDeclarationNamespace = "SKIT.FlurlHttpClient.Wechat.TenpayV3.ExtendedSDK.Global.Models",
ProjectSourceRootDirectory = Path.Combine(projdir, "./src/SKIT.FlurlHttpClient.Wechat.TenpayV3/"),
ProjectSourceRequestModelClassCodeSubDirectory = "ExtendedSDK/Global/Models/",
ProjectSourceResponseModelClassCodeSubDirectory = "ExtendedSDK/Global/Models/",
ProjectSourceExecutingExtensionClassCodeSubDirectory = "ExtendedSDK/Global/Extensions/",
ProjectSourceWebhookEventClassCodeSubDirectory = "ExtendedSDK/Global/Events/",
ProjectTestRootDirectory = Path.Combine(projdir, "./test/SKIT.FlurlHttpClient.Wechat.TenpayV3.UnitTests/"),
ProjectTestRequestModelSerializationSampleSubDirectory = "ModelSamples/Global/",
ProjectTestResponseModelSerializationSampleSubDirectory = "ModelSamples/Global/",
ProjectTestWebhookEventSerializationSampleSubDirectory = "EventSamples/Global/",
ThrowOnNotFoundRequestModelClassCodeFiles = true,
ThrowOnNotFoundResponseModelClassCodeFiles = true,
ThrowOnNotFoundExecutingExtensionClassCodeFiles = true,
ThrowOnNotFoundRequestModelSerializationSampleFiles = true,
ThrowOnNotFoundResponseModelSerializationSampleFiles = true
};
new SourceFileAnalyzer(options).AssertNoIssues();
}));
}
2024-01-29 23:12:37 +08:00
}
}