GFramework/GFramework.Godot.Tests/Architectures/AbstractArchitectureModuleInstallationTests.cs
gewuyou 6ff07ad3d9 fix(godot): 清理 Godot 模块与测试项目告警
- 优化 GodotYamlConfigEnvironment 目录枚举逻辑,拆分 helper 以消除 MA0051

- 修复 Godot 生命周期 await 的上下文声明,显式保留主线程同步上下文

- 更新 Godot.Tests 异步断言与字符串 comparer,用例项目构建收敛到 0 warning(s)

- 补充 analyzer-warning-reduction 跟踪与 trace,记录 RP-053 的批次结果与验证
2026-04-24 17:04:53 +08:00

65 lines
1.9 KiB
C#

using GFramework.Core.Abstractions.Architectures;
using GFramework.Godot.Architectures;
namespace GFramework.Godot.Tests.Architectures;
/// <summary>
/// 验证 Godot 架构在模块安装前会先检查锚点状态,避免未绑定场景树时留下半安装副作用。
/// </summary>
[TestFixture]
public sealed class AbstractArchitectureModuleInstallationTests
{
/// <summary>
/// 验证当锚点尚未初始化时,安装流程会直接失败,且不会执行模块安装逻辑。
/// </summary>
/// <returns>表示异步断言完成的任务。</returns>
[Test]
public async Task InstallGodotModuleAsync_ShouldThrowBeforeInvokingModuleInstall_WhenAnchorIsMissing()
{
var architecture = new TestArchitecture();
var module = new RecordingGodotModule();
var exception = Assert.ThrowsAsync<InvalidOperationException>(async () =>
await architecture.InstallGodotModuleForTestAsync(module).ConfigureAwait(false));
Assert.Multiple(() =>
{
Assert.That(exception, Is.Not.Null);
Assert.That(exception!.Message, Is.EqualTo("Anchor not initialized"));
Assert.That(module.InstallCalled, Is.False);
});
}
private sealed class TestArchitecture : AbstractArchitecture
{
protected override void InstallModules()
{
}
public Task InstallGodotModuleForTestAsync(RecordingGodotModule module)
{
return InstallGodotModule(module);
}
}
private sealed class RecordingGodotModule : IGodotModule
{
public bool InstallCalled { get; private set; }
public global::Godot.Node Node => null!;
public void Install(IArchitecture architecture)
{
InstallCalled = true;
}
public void OnAttach(GFramework.Core.Architectures.Architecture architecture)
{
}
public void OnDetach()
{
}
}
}