diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
index c1b5b37..dec09f2 100644
--- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
+++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs
@@ -30,17 +30,31 @@ public class ContextAwareGeneratorTests
}
}
- namespace TestApp;
-
- using GFramework.SourceGenerators.Attributes.rule;
-
- [ContextAware]
- public partial class MyRule
+ namespace TestApp
{
+ using GFramework.SourceGenerators.Attributes.rule;
+
+ [ContextAware]
+ public partial class MyRule
+ {
+ }
}
""";
+ 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 = """
//
@@ -61,7 +75,7 @@ public class ContextAwareGeneratorTests
// 执行源代码生成器测试
await GeneratorTest.RunAsync(
- source,
+ source + "\n" + frameworkStub,
("MyRule.ContextAware.g.cs", expected)
);
}
diff --git a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
index 2c2de4f..0f005c9 100644
--- a/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
+++ b/GFramework.SourceGenerators/rule/ContextAwareGenerator.cs
@@ -105,9 +105,8 @@ public sealed class ContextAwareGenerator : IIncrementalGenerator
sb.AppendLine(" Context = context;");
sb.AppendLine(" }");
-
sb.AppendLine("}");
- return sb.ToString();
+ return sb.ToString().TrimEnd();
}
}
\ No newline at end of file
diff --git a/GFramework.sln.DotSettings.user b/GFramework.sln.DotSettings.user
index 8865a13..51ff59d 100644
--- a/GFramework.sln.DotSettings.user
+++ b/GFramework.sln.DotSettings.user
@@ -1,6 +1,9 @@
+ ForceIncluded
ForceIncluded
ForceIncluded
+ ForceIncluded
+ ForceIncluded
<SessionState ContinuousTestingMode="0" IsActive="True" Name="Generates_ContextAware_Code" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
<TestAncestor>
<TestId>NUnit3x::BB047F43-6AA0-4EA0-8AE9-E6B9784D9E8E::net8.0::GFramework.SourceGenerators.Tests.rule.ContextAwareGeneratorTests</TestId>