mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 19:03:29 +08:00
- 在 ArchitectureServices 中添加 SetContext 和 GetContext 方法 - 为 IArchitectureServices 接口添加 IContextAware 继承 - 在架构初始化过程中设置服务上下文 - 将事件系统的 GetEvent 方法替换为 GetOrAddEvent 方法 - 重构测试类添加测试装置和拆卸逻辑 - 为测试类添加 NonParallelizable 特性确保测试隔离
57 lines
1.5 KiB
C#
57 lines
1.5 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]
|
|
[NonParallelizable]
|
|
public class ArchitectureInitializationTests
|
|
{
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_architecture = new TestArchitecture();
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
_architecture!.Destroy();
|
|
_architecture = null;
|
|
}
|
|
|
|
private TestArchitecture? _architecture;
|
|
|
|
[Test]
|
|
public void Architecture_Should_Initialize_All_Components_Correctly()
|
|
{
|
|
// Act
|
|
_architecture!.Initialize();
|
|
|
|
// Assert
|
|
Assert.That(_architecture.InitCalled, Is.True);
|
|
|
|
Assert.That(_architecture.Runtime, Is.Not.Null);
|
|
|
|
var phaseProperty = typeof(Architecture)
|
|
.GetProperty("CurrentPhase", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
var phase = (ArchitecturePhase)phaseProperty!.GetValue(_architecture)!;
|
|
Assert.That(phase, Is.EqualTo(ArchitecturePhase.Ready));
|
|
|
|
var context = _architecture.Context;
|
|
|
|
var model = context.GetModel<TestModel>();
|
|
Assert.That(model, Is.Not.Null);
|
|
Assert.That(model!.Inited, Is.True);
|
|
|
|
var system = context.GetSystem<TestSystem>();
|
|
Assert.That(system, Is.Not.Null);
|
|
Assert.That(system!.Inited, Is.True);
|
|
}
|
|
} |