-
Notifications
You must be signed in to change notification settings - Fork 3
Refactor/重构CQRS处理程序注册生成器以支持反射回退属性 #244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0b4946
test: 增强快照测试基础设施,添加安全验证和覆盖率改进
GeWuYou 35a1634
feat(cqrs): 添加 CQRS 处理器注册器源代码生成器
GeWuYou b19877f
feat(source-generators): 添加多个代码生成器功能
GeWuYou 9ec83fa
feat(source-generators): 添加CQRS处理器注册器和枚举扩展生成器
GeWuYou 57a006c
chore(build): 添加 C# 命名规范验证脚本
GeWuYou bcde9f6
feat(rule): 添加上下文感知基类和生成器实现
GeWuYou 263586b
Merge branch 'main' into refactor/cqrs-and-config-system
GeWuYou b7a4764
feat(cqrs): 为CQRS处理器注册生成器添加详细文档注释并改进测试验证
GeWuYou File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
299 changes: 70 additions & 229 deletions
299
GFramework.Cqrs.SourceGenerators/Cqrs/CqrsHandlerRegistryGenerator.cs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...tors.Tests/Bases/snapshots/PriorityGenerator/BasicPriority/TestApp_MySystem.Priority.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // <auto-generated/> | ||
| #nullable enable | ||
|
|
||
| namespace TestApp; | ||
|
|
||
| partial class MySystem : global::GFramework.Core.Abstractions.Bases.IPrioritized | ||
| { | ||
| /// <summary> | ||
| /// 获取优先级值: 10 | ||
| /// </summary> | ||
| public int Priority => 10; | ||
| } |
12 changes: 12 additions & 0 deletions
12
...sts/Bases/snapshots/PriorityGenerator/GenericClass/TestApp_GenericSystem_T_.Priority.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // <auto-generated/> | ||
| #nullable enable | ||
|
|
||
| namespace TestApp; | ||
|
|
||
| partial class GenericSystem<T> : global::GFramework.Core.Abstractions.Bases.IPrioritized | ||
| { | ||
| /// <summary> | ||
| /// 获取优先级值: 20 | ||
| /// </summary> | ||
| public int Priority => 20; | ||
| } |
12 changes: 12 additions & 0 deletions
12
...s/Bases/snapshots/PriorityGenerator/NegativePriority/TestApp_CriticalSystem.Priority.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // <auto-generated/> | ||
| #nullable enable | ||
|
|
||
| namespace TestApp; | ||
|
|
||
| partial class CriticalSystem : global::GFramework.Core.Abstractions.Bases.IPrioritized | ||
| { | ||
| /// <summary> | ||
| /// 获取优先级值: -100 | ||
| /// </summary> | ||
| public int Priority => -100; | ||
| } |
12 changes: 12 additions & 0 deletions
12
.../Bases/snapshots/PriorityGenerator/PriorityGroup/TestApp_HighPrioritySystem.Priority.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // <auto-generated/> | ||
| #nullable enable | ||
|
|
||
| namespace TestApp; | ||
|
|
||
| partial class HighPrioritySystem : global::GFramework.Core.Abstractions.Bases.IPrioritized | ||
| { | ||
| /// <summary> | ||
| /// 获取优先级值: -50 | ||
| /// </summary> | ||
| public int Priority => -50; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
GFramework.SourceGenerators.Tests/Core/GeneratorSnapshotTestSecurityTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| using System.IO; | ||
| using GFramework.Core.SourceGenerators.Enums; | ||
|
|
||
| namespace GFramework.SourceGenerators.Tests.Core; | ||
|
|
||
| /// <summary> | ||
| /// 验证快照测试辅助器对快照文件路径映射的安全约束。 | ||
| /// </summary> | ||
| [TestFixture] | ||
| public class GeneratorSnapshotTestSecurityTests | ||
| { | ||
| private const string EnumAttributeNamespace = "GFramework.Core.SourceGenerators.Abstractions.Enums"; | ||
|
|
||
| /// <summary> | ||
| /// 验证快照文件名映射返回绝对路径时,会在访问文件系统前被拒绝。 | ||
| /// </summary> | ||
| [Test] | ||
| public void RunAsync_SnapshotFileNameSelectorReturnsAbsolutePath_ThrowsInvalidOperationException() | ||
| { | ||
| var snapshotRoot = CreateSnapshotRoot(); | ||
| var source = BuildSource(); | ||
|
|
||
| Assert.ThrowsAsync<InvalidOperationException>(async () => | ||
| await GeneratorSnapshotTest<EnumExtensionsGenerator>.RunAsync( | ||
| source, | ||
| snapshotRoot, | ||
| _ => Path.Combine(snapshotRoot, "Status.EnumExtensions.g.cs"))); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 验证快照文件名映射尝试通过父级目录片段逃逸根目录时,会在访问文件系统前被拒绝。 | ||
| /// </summary> | ||
| [Test] | ||
| public void RunAsync_SnapshotFileNameSelectorEscapesSnapshotRoot_ThrowsInvalidOperationException() | ||
| { | ||
| var snapshotRoot = CreateSnapshotRoot(); | ||
| var source = BuildSource(); | ||
|
|
||
| Assert.ThrowsAsync<InvalidOperationException>(async () => | ||
| await GeneratorSnapshotTest<EnumExtensionsGenerator>.RunAsync( | ||
| source, | ||
| snapshotRoot, | ||
| _ => Path.Combine("..", "escaped", "Status.EnumExtensions.g.cs"))); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 为安全测试创建隔离的快照根目录路径,避免不同用例共享状态。 | ||
| /// </summary> | ||
| /// <returns>当前用例专属的快照根目录绝对路径。</returns> | ||
| private static string CreateSnapshotRoot() | ||
| { | ||
| return Path.Combine( | ||
| TestContext.CurrentContext.WorkDirectory, | ||
| "temp-snapshots", | ||
| TestContext.CurrentContext.Test.ID, | ||
| Guid.NewGuid().ToString("N")); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// 构造可稳定触发枚举扩展生成器输出的最小测试源码。 | ||
| /// </summary> | ||
| /// <returns>包含测试属性与目标枚举的完整源码。</returns> | ||
| private static string BuildSource() | ||
| { | ||
| return $$""" | ||
| using System; | ||
|
|
||
| namespace {{EnumAttributeNamespace}} | ||
| { | ||
| [AttributeUsage(AttributeTargets.Enum)] | ||
| public sealed class GenerateEnumExtensionsAttribute : Attribute | ||
| { | ||
| public bool GenerateIsMethods { get; set; } = true; | ||
| public bool GenerateIsInMethod { get; set; } = true; | ||
| } | ||
| } | ||
|
|
||
| namespace TestApp | ||
| { | ||
| using {{EnumAttributeNamespace}}; | ||
|
|
||
| [GenerateEnumExtensions] | ||
| public enum Status | ||
| { | ||
| Active, | ||
| Inactive | ||
| } | ||
| } | ||
| """; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...sGenerator/BasicEnum_IsMethods_DefaultSnapshotFileNameSelector/Status.EnumExtensions.g.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // <auto-generated /> | ||
| using System; | ||
| namespace TestApp | ||
| { | ||
| public static partial class StatusExtensions | ||
| { | ||
| /// <summary>是否为 Active</summary> | ||
| public static bool IsActive(this TestApp.Status value) => value == TestApp.Status.Active; | ||
|
|
||
| /// <summary>是否为 Inactive</summary> | ||
| public static bool IsInactive(this TestApp.Status value) => value == TestApp.Status.Inactive; | ||
|
|
||
| /// <summary>判断是否属于指定集合</summary> | ||
| public static bool IsIn(this TestApp.Status value, params TestApp.Status[] values) | ||
| { | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| if (values == null) return false; | ||
| foreach (var v in values) if (value == v) return true; | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.