diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
index 49e3f79..bdd5418 100644
--- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
+++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
@@ -79,4 +79,72 @@ public class ContextAwareGeneratorTests
("MyRule.ContextAware.g.cs", expected)
);
}
+
+ [Test]
+ public async Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
+ {
+ const string source = """
+ using System;
+
+ namespace GFramework.SourceGenerators.Attributes.rule
+ {
+ [AttributeUsage(AttributeTargets.Class)]
+ public sealed class ContextAwareAttribute : Attribute
+ {
+ }
+ }
+
+ namespace TestApp
+ {
+ using GFramework.SourceGenerators.Attributes.rule;
+ using GFramework.Core.rule;
+
+ // 间接接口:继承自 IContextAware
+ public interface IMyRuleContextAware : IContextAware
+ {
+ }
+
+ [ContextAware]
+ public partial class MyRule : IMyRuleContextAware
+ {
+ }
+ }
+ """;
+
+ const string frameworkStub = """
+ namespace GFramework.Core.rule
+ {
+ public interface IContextAware
+ {
+ void SetContext(GFramework.Core.architecture.IArchitectureContext context);
+ }
+ }
+
+ namespace GFramework.Core.architecture
+ {
+ public interface IArchitectureContext {}
+ }
+ """;
+
+ const string expected = """
+ //
+ #nullable enable
+ namespace TestApp;
+
+ partial class MyRule
+ {
+ protected GFramework.Core.architecture.IArchitectureContext Context { get; private set; } = null!;
+ void GFramework.Core.rule.IContextAware.SetContext(
+ GFramework.Core.architecture.IArchitectureContext context)
+ {
+ Context = context;
+ }
+ }
+ """;
+
+ await GeneratorTest.RunAsync(
+ source + "\n" + frameworkStub,
+ ("MyRule.ContextAware.g.cs", expected)
+ );
+ }
}
\ No newline at end of file