GFramework/GFramework.Core.Tests/tests/ArchitectureInitializationTests.cs
GwWuYou 8130cf7fb0 refactor(ioc): 重构依赖注入容器和模型上下文管理
- 将IocContainer的Init方法重命名为OnContextReady并设为protected override
- 重构AbstractModel中的Architecture字段为_context属性并实现IContextAware接口
- 移除GetArchitecture和SetArchitecture方法,添加GetContext和SetContext方法
- 为IModel接口添加IContextAware继承
- 添加TestArchitecture、TestModel和TestSystem测试类
- 创建ArchitectureInitializationTests测试用例验证组件初始化
- 更新项目文件添加NUnit包引用和测试项目配置
- 在解决方案文件中添加测试项目引用
2025-12-29 21:14:23 +08:00

47 lines
1.6 KiB
C#

using System.Reflection;
using GFramework.Core.Abstractions.enums;
using GFramework.Core.architecture;
using GFramework.Core.Tests.architecture;
using GFramework.Core.Tests.model;
using GFramework.Core.Tests.system;
using NUnit.Framework;
namespace GFramework.Core.Tests.tests;
[TestFixture]
public class ArchitectureInitializationTests
{
[Test]
public void Architecture_Should_Initialize_All_Components_Correctly()
{
// Arrange
var architecture = new TestArchitecture();
// Act
architecture.Initialize();
// Assert - Init() 被调用
Assert.That(architecture.InitCalled, Is.True, "Architecture.Init() should be called");
// Assert - Runtime 已创建
Assert.That(architecture.Runtime, Is.Not.Null, "ArchitectureRuntime should be created");
// Assert - Phase 已进入 Ready
var phaseProperty = typeof(Architecture)
.GetProperty("CurrentPhase", BindingFlags.Instance | BindingFlags.NonPublic);
var phase = (ArchitecturePhase)phaseProperty!.GetValue(architecture)!;
Assert.That(phase, Is.EqualTo(ArchitecturePhase.Ready), "Architecture should be in Ready phase");
// Assert - Model 初始化
var context = architecture.Context;
var model = context.GetModel<TestModel>();
Assert.That(model, Is.Not.Null);
Assert.That(model.Inited, Is.True, "Model should be initialized");
// Assert - System 初始化
var system = context.GetSystem<TestSystem>();
Assert.That(system, Is.Not.Null);
Assert.That(system.Inited, Is.True, "System should be initialized");
}
}