mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 创建 AsyncTestArchitecture 类用于异步测试 - 添加 AsyncTestSystem 实现异步初始化系统 - 创建 ArchitectureTestsBase 基类统一同步异步测试逻辑 - 实现 AsyncArchitectureTests 异步架构测试用例 - 将同步测试重构为继承自 ArchitectureTestsBase - 移除重复的测试方法实现 - 重命名模型初始化状态属性为 Initialized
61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
using GFramework.Core.Abstractions.architecture;
|
||
using GFramework.Core.Abstractions.enums;
|
||
using GFramework.Core.Abstractions.model;
|
||
|
||
namespace GFramework.Core.Tests.model;
|
||
|
||
/// <summary>
|
||
/// 异步测试模型类,实现了IModel和IAsyncInitializable接口
|
||
/// </summary>
|
||
public sealed class AsyncTestModel : IModel, IAsyncInitializable
|
||
{
|
||
private IArchitectureContext _context = null!;
|
||
|
||
/// <summary>
|
||
/// 获取模型是否已初始化的标志
|
||
/// </summary>
|
||
public bool Initialized { get; private set; }
|
||
|
||
/// <summary>
|
||
/// 异步初始化方法,模拟异步初始化过程
|
||
/// </summary>
|
||
/// <returns>表示异步操作的Task</returns>
|
||
public async Task InitializeAsync()
|
||
{
|
||
await Task.Delay(10);
|
||
Initialized = true;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 同步初始化方法,该方法不应该被调用
|
||
/// </summary>
|
||
/// <exception cref="InvalidOperationException">当该方法被调用时抛出异常</exception>
|
||
public void Init()
|
||
{
|
||
// sync Init 不应该被调用
|
||
throw new InvalidOperationException("Sync Init should not be called");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置架构上下文
|
||
/// </summary>
|
||
/// <param name="context">架构上下文对象</param>
|
||
public void SetContext(IArchitectureContext context)
|
||
{
|
||
_context = context;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取架构上下文
|
||
/// </summary>
|
||
/// <returns>架构上下文对象</returns>
|
||
public IArchitectureContext GetContext() => _context;
|
||
|
||
/// <summary>
|
||
/// 处理架构阶段事件
|
||
/// </summary>
|
||
/// <param name="phase">架构阶段枚举值</param>
|
||
public void OnArchitecturePhase(ArchitecturePhase phase)
|
||
{
|
||
}
|
||
} |