mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 为 ContextAware 功能添加全面的单元测试覆盖 - 增加对枚举扩展生成器的快照测试验证 - 实现环境管理器的完整测试用例集 - 添加事件总线功能的核心测试验证 - 为游戏上下文管理添加架构测试 - 扩展注销列表扩展方法的测试覆盖 - 增加注销机制的全面单元测试验证 - [skip ci]
159 lines
5.1 KiB
C#
159 lines
5.1 KiB
C#
using GFramework.SourceGenerators.logging;
|
|
using GFramework.SourceGenerators.Tests.core;
|
|
using NUnit.Framework;
|
|
|
|
namespace GFramework.SourceGenerators.Tests.logging;
|
|
|
|
[TestFixture]
|
|
public class LoggerGeneratorSnapshotTests
|
|
{
|
|
[Test]
|
|
public async Task Snapshot_DefaultConfiguration_Class()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log]
|
|
public partial class MyService
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"DefaultConfiguration_Class"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Snapshot_CustomName_Class()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log(Name = "CustomLogger")]
|
|
public partial class MyService
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"CustomName_Class"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Snapshot_CustomFieldName_Class()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log(FieldName = "MyLogger")]
|
|
public partial class MyService
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"CustomFieldName_Class"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Snapshot_InstanceField_Class()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log(IsStatic = false)]
|
|
public partial class MyService
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"InstanceField_Class"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Snapshot_PublicField_Class()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log(AccessModifier = "public")]
|
|
public partial class MyService
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"PublicField_Class"));
|
|
}
|
|
|
|
[Test]
|
|
public async Task Snapshot_GenericClass()
|
|
{
|
|
const string source = """
|
|
using GFramework.SourceGenerators.Abstractions.logging;
|
|
|
|
namespace TestApp
|
|
{
|
|
[Log]
|
|
public partial class MyService<T>
|
|
{
|
|
}
|
|
}
|
|
""";
|
|
|
|
await GeneratorSnapshotTest<LoggerGenerator>.RunAsync(
|
|
source,
|
|
Path.Combine(
|
|
TestContext.CurrentContext.TestDirectory,
|
|
"logging",
|
|
"snapshots",
|
|
"LoggerGenerator",
|
|
"GenericClass"));
|
|
}
|
|
} |