GFramework/GFramework.Core.Tests/tests/ArchitectureTestsBase.cs
GeWuYou 56769cbf01 feat(architecture): 添加异步销毁功能支持
- 在 Architecture 中添加对 IAsyncDestroyable 接口的支持
- 将销毁集合类型从 IDestroyable 改为 object 以支持多种销毁接口
- 实现 DestroyAsync 方法提供异步销毁能力
- 保留旧的同步 Destroy 方法用于向后兼容
- 在 StateMachineSystem 中添加异步销毁状态的支持
- 添加 IAsyncDestroyable、IAsyncInitializable 和 IAsyncLifecycle 接口定义
- 更新测试代码以使用新的异步销毁方法
- 在架构销毁时清理依赖注入容器
2026-02-17 18:41:16 +08:00

64 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using GFramework.Core.Abstractions.enums;
using GFramework.Core.architecture;
using NUnit.Framework;
namespace GFramework.Core.Tests.tests;
/// <summary>
/// 架构测试基类,封装同步/异步共通测试逻辑
/// </summary>
/// <typeparam name="TArchitecture">架构类型必须继承自Architecture</typeparam>
public abstract class ArchitectureTestsBase<TArchitecture> where TArchitecture : Architecture
{
protected TArchitecture? Architecture;
/// <summary>
/// 子类必须实现创建具体架构实例
/// </summary>
/// <returns>创建的架构实例</returns>
protected abstract TArchitecture CreateArchitecture();
/// <summary>
/// 测试设置方法,在每个测试开始前执行
/// 清理游戏上下文并创建架构实例
/// </summary>
[SetUp]
public void SetUp()
{
GameContext.Clear();
Architecture = CreateArchitecture();
}
/// <summary>
/// 测试清理方法,在每个测试结束后执行
/// 销毁架构实例并清理游戏上下文
/// </summary>
[TearDown]
public async Task TearDown()
{
try
{
if (Architecture != null)
{
await Architecture.DestroyAsync();
}
}
finally
{
GameContext.Clear();
Architecture = null;
}
}
/// <summary>
/// 验证架构初始化失败的断言方法
/// 检查当前架构阶段是否为初始化失败状态
/// </summary>
protected void AssertInitializationFailed()
{
Assert.That(
Architecture!.CurrentPhase,
Is.EqualTo(ArchitecturePhase.FailedInitialization)
);
}
}