diff --git a/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs b/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
index fcce9a4..1baf59f 100644
--- a/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
+++ b/GFramework.Core.Tests/architecture/ArchitectureServicesTests.cs
@@ -5,6 +5,7 @@ using GFramework.Core.Abstractions.environment;
using GFramework.Core.Abstractions.events;
using GFramework.Core.Abstractions.ioc;
using GFramework.Core.Abstractions.model;
+using GFramework.Core.Abstractions.properties;
using GFramework.Core.Abstractions.query;
using GFramework.Core.Abstractions.system;
using GFramework.Core.Abstractions.utility;
@@ -46,16 +47,19 @@ public class ArchitectureServicesTests
private ArchitectureServices? _services;
private TestArchitectureContextV3? _context;
+ private void RegisterBuiltInServices()
+ {
+ var properties = new ArchitectureProperties();
+ _services!.ModuleManager.RegisterBuiltInModules(_services.Container, properties);
+ }
+
///
- /// 测试构造函数初始化所有服务
+ /// 测试构造函数初始化容器
///
[Test]
- public void Constructor_Should_Initialize_AllServices()
+ public void Constructor_Should_Initialize_Container()
{
Assert.That(_services!.Container, Is.Not.Null);
- Assert.That(_services.EventBus, Is.Not.Null);
- Assert.That(_services.CommandExecutor, Is.Not.Null);
- Assert.That(_services.QueryExecutor, Is.Not.Null);
}
[Test]
@@ -66,35 +70,62 @@ public class ArchitectureServicesTests
}
///
- /// 测试EventBus是EventBus的实例
+ /// 测试注册内置服务后EventBus可用
///
[Test]
- public void EventBus_Should_Be_Instance_Of_EventBus()
+ public void After_RegisterBuiltInModules_EventBus_Should_Be_Available()
{
+ RegisterBuiltInServices();
+
Assert.That(_services!.EventBus, Is.InstanceOf());
Assert.That(_services.EventBus, Is.InstanceOf());
}
///
- /// 测试CommandBus是CommandBus的实例
+ /// 测试注册内置服务后CommandExecutor可用
///
[Test]
- public void CommandBus_Should_Be_Instance_Of_CommandBus()
+ public void After_RegisterBuiltInModules_CommandExecutor_Should_Be_Available()
{
+ RegisterBuiltInServices();
+
Assert.That(_services!.CommandExecutor, Is.InstanceOf());
Assert.That(_services.CommandExecutor, Is.InstanceOf());
}
///
- /// 测试QueryBus是QueryBus的实例
+ /// 测试注册内置服务后QueryExecutor可用
///
[Test]
- public void QueryBus_Should_Be_Instance_Of_QueryBus()
+ public void After_RegisterBuiltInModules_QueryExecutor_Should_Be_Available()
{
+ RegisterBuiltInServices();
+
Assert.That(_services!.QueryExecutor, Is.InstanceOf());
Assert.That(_services.QueryExecutor, Is.InstanceOf());
}
+ ///
+ /// 测试注册内置服务后AsyncQueryExecutor可用
+ ///
+ [Test]
+ public void After_RegisterBuiltInModules_AsyncQueryExecutor_Should_Be_Available()
+ {
+ RegisterBuiltInServices();
+
+ Assert.That(_services!.AsyncQueryExecutor, Is.InstanceOf());
+ Assert.That(_services.AsyncQueryExecutor, Is.InstanceOf());
+ }
+
+ ///
+ /// 测试未注册服务时EventBus为null
+ ///
+ [Test]
+ public void Without_RegisterBuiltInModules_EventBus_Should_Be_Null()
+ {
+ Assert.That(_services!.EventBus, Is.Null);
+ }
+
///
/// 测试SetContext设置内部Context字段
///
@@ -186,8 +217,13 @@ public class ArchitectureServicesTests
[Test]
public void Multiple_Instances_Should_Have_Independent_EventBus()
{
+ var properties = new ArchitectureProperties();
+
var services1 = new ArchitectureServices();
+ services1.ModuleManager.RegisterBuiltInModules(services1.Container, properties);
+
var services2 = new ArchitectureServices();
+ services2.ModuleManager.RegisterBuiltInModules(services2.Container, properties);
Assert.That(services1.EventBus, Is.Not.SameAs(services2.EventBus));
}
@@ -198,8 +234,13 @@ public class ArchitectureServicesTests
[Test]
public void Multiple_Instances_Should_Have_Independent_CommandBus()
{
+ var properties = new ArchitectureProperties();
+
var services1 = new ArchitectureServices();
+ services1.ModuleManager.RegisterBuiltInModules(services1.Container, properties);
+
var services2 = new ArchitectureServices();
+ services2.ModuleManager.RegisterBuiltInModules(services2.Container, properties);
Assert.That(services1.CommandExecutor, Is.Not.SameAs(services2.CommandExecutor));
}
@@ -210,11 +251,46 @@ public class ArchitectureServicesTests
[Test]
public void Multiple_Instances_Should_Have_Independent_QueryBus()
{
+ var properties = new ArchitectureProperties();
+
var services1 = new ArchitectureServices();
+ services1.ModuleManager.RegisterBuiltInModules(services1.Container, properties);
+
var services2 = new ArchitectureServices();
+ services2.ModuleManager.RegisterBuiltInModules(services2.Container, properties);
Assert.That(services1.QueryExecutor, Is.Not.SameAs(services2.QueryExecutor));
}
+
+ ///
+ /// 测试ModuleManager属性不为空
+ ///
+ [Test]
+ public void ModuleManager_Should_Not_Be_Null()
+ {
+ Assert.That(_services!.ModuleManager, Is.Not.Null);
+ }
+
+ ///
+ /// 测试EnableEcs配置开关
+ ///
+ [Test]
+ public void EnableEcs_Should_Control_Ecs_Module_Registration()
+ {
+ var propertiesWithEcs = new ArchitectureProperties { EnableEcs = true };
+ var propertiesWithoutEcs = new ArchitectureProperties { EnableEcs = false };
+
+ var servicesWithEcs = new ArchitectureServices();
+ servicesWithEcs.ModuleManager.RegisterBuiltInModules(servicesWithEcs.Container, propertiesWithEcs);
+
+ var servicesWithoutEcs = new ArchitectureServices();
+ servicesWithoutEcs.ModuleManager.RegisterBuiltInModules(servicesWithoutEcs.Container, propertiesWithoutEcs);
+
+ var modulesWithEcs = servicesWithEcs.ModuleManager.GetModules();
+ var modulesWithoutEcs = servicesWithoutEcs.ModuleManager.GetModules();
+
+ Assert.That(modulesWithEcs.Count, Is.GreaterThan(modulesWithoutEcs.Count));
+ }
}
#region Test Classes
@@ -225,11 +301,6 @@ public class TestArchitectureContextV3 : IArchitectureContext
private readonly DefaultEnvironment _environment = new();
public int Id { get; init; }
- public IIocContainer Container => _container;
- public IEventBus EventBus => new EventBus();
- public ICommandExecutor CommandExecutor => new CommandExecutor();
- public IQueryExecutor QueryExecutor => new QueryExecutor();
-
public TService? GetService() where TService : class
{
return _container.Get();
diff --git a/GFramework.Core.Tests/ecs/EcsAdvancedTests.cs b/GFramework.Core.Tests/ecs/EcsAdvancedTests.cs
index 972df44..577f7e1 100644
--- a/GFramework.Core.Tests/ecs/EcsAdvancedTests.cs
+++ b/GFramework.Core.Tests/ecs/EcsAdvancedTests.cs
@@ -266,20 +266,24 @@ public class EcsAdvancedTests
[Test]
public void InitializeEcs_CalledTwice_Should_BeIdempotent()
{
- _context!.InitializeEcs();
- var ecsWorld1 = _context.GetEcsWorld();
-
- Assert.DoesNotThrow(() => _context.InitializeEcs());
+ _ecsWorld = new EcsWorld();
+ _container!.Register(_ecsWorld);
+ _container.Register(_ecsWorld);
+ var ecsWorld1 = _context!.GetEcsWorld();
var ecsWorld2 = _context.GetEcsWorld();
+
Assert.That(ecsWorld2, Is.SameAs(ecsWorld1), "Should return same world instance");
}
[Test]
public void GetEcsWorld_Should_ReturnIEcsWorld()
{
- _context!.InitializeEcs();
- var ecsWorld = _context.GetEcsWorld();
+ _ecsWorld = new EcsWorld();
+ _container!.Register(_ecsWorld);
+ _container.Register(_ecsWorld);
+
+ var ecsWorld = _context!.GetEcsWorld();
Assert.That(ecsWorld, Is.InstanceOf());
Assert.That(ecsWorld, Is.InstanceOf());
diff --git a/GFramework.Core.Tests/ecs/EcsBasicTests.cs b/GFramework.Core.Tests/ecs/EcsBasicTests.cs
index 6fd1dce..036345f 100644
--- a/GFramework.Core.Tests/ecs/EcsBasicTests.cs
+++ b/GFramework.Core.Tests/ecs/EcsBasicTests.cs
@@ -85,8 +85,11 @@ public class EcsBasicTests
[Experimental("GFrameworkECS")]
public void Test_01_InitializeEcs_Should_Create_EcsWorld()
{
- _context!.InitializeEcs();
- var ecsWorld = _context.GetEcsWorld();
+ _ecsWorld = new EcsWorld();
+ _container!.Register(_ecsWorld);
+ _container.Register(_ecsWorld);
+
+ var ecsWorld = _context!.GetEcsWorld();
Assert.That(ecsWorld, Is.Not.Null, "EcsWorld should be created");
Assert.That(ecsWorld.EntityCount, Is.EqualTo(0), "Initial entity count should be 0");
@@ -221,6 +224,6 @@ public class EcsBasicTests
public void Test_08_GetEcsWorld_Without_Initialize_Should_Throw()
{
Assert.Throws(() => { _context!.GetEcsWorld(); },
- "Getting EcsWorld without initialization should throw");
+ "ECS World not initialized. Enable ECS in configuration.");
}
}
\ No newline at end of file
diff --git a/GFramework.Core.Tests/ecs/EcsIntegrationTests.cs b/GFramework.Core.Tests/ecs/EcsIntegrationTests.cs
index 6a70b37..e670393 100644
--- a/GFramework.Core.Tests/ecs/EcsIntegrationTests.cs
+++ b/GFramework.Core.Tests/ecs/EcsIntegrationTests.cs
@@ -84,8 +84,11 @@ public class EcsIntegrationTests
[Test]
public void InitializeEcs_Should_Create_EcsWorld()
{
- _context!.InitializeEcs();
- var ecsWorld = _context.GetEcsWorld();
+ _ecsWorld = new EcsWorld();
+ _container!.Register(_ecsWorld);
+ _container.Register(_ecsWorld);
+
+ var ecsWorld = _context!.GetEcsWorld();
Assert.That(ecsWorld, Is.Not.Null);
Assert.That(ecsWorld.EntityCount, Is.EqualTo(0));
@@ -246,7 +249,8 @@ public class EcsIntegrationTests
[Test]
public void GetEcsWorld_Without_Initialize_Should_Throw()
{
- Assert.Throws(() => { _context!.GetEcsWorld(); });
+ Assert.Throws(() => { _context!.GetEcsWorld(); },
+ "ECS World not initialized. Enable ECS in configuration.");
}
///