mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
test(rule): 更新 ContextAware 生成器测试方法
- 将测试方法的返回类型从 Task<int> 更改为 Task - 使用 Assert.DoesNotThrowAsync 包装生成器测试执行逻辑 - 在测试方法末尾添加 return Task.CompletedTask 返回已完成任务
This commit is contained in:
parent
383eceb36f
commit
eababa471a
@ -16,7 +16,7 @@ public class ContextAwareGeneratorTests
|
||||
/// </summary>
|
||||
/// <returns>异步任务</returns>
|
||||
[Test]
|
||||
public async Task Generates_ContextAware_Code()
|
||||
public Task Generates_ContextAware_Code()
|
||||
{
|
||||
// 定义输入源代码,包含使用[ContextAware]特性的部分类
|
||||
const string source = """
|
||||
@ -72,16 +72,19 @@ public class ContextAwareGeneratorTests
|
||||
}
|
||||
""";
|
||||
|
||||
|
||||
// 执行源代码生成器测试
|
||||
await GeneratorTest<ContextAwareGenerator>.RunAsync(
|
||||
source + "\n" + frameworkStub,
|
||||
("MyRule.ContextAware.g.cs", expected)
|
||||
);
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
// 执行源代码生成器测试
|
||||
await GeneratorTest<ContextAwareGenerator>.RunAsync(
|
||||
source + "\n" + frameworkStub,
|
||||
("MyRule.ContextAware.g.cs", expected)
|
||||
);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
|
||||
public Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware()
|
||||
{
|
||||
const string source = """
|
||||
using System;
|
||||
@ -141,10 +144,13 @@ public class ContextAwareGeneratorTests
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
await GeneratorTest<ContextAwareGenerator>.RunAsync(
|
||||
source + "\n" + frameworkStub,
|
||||
("MyRule.ContextAware.g.cs", expected)
|
||||
);
|
||||
Assert.DoesNotThrowAsync(async () =>
|
||||
{
|
||||
await GeneratorTest<ContextAwareGenerator>.RunAsync(
|
||||
source + "\n" + frameworkStub,
|
||||
("MyRule.ContextAware.g.cs", expected)
|
||||
);
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user