mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(architecture): 优化架构上下文清理机制
- 将测试专用的 ResetForTests 方法重命名为 Clear 并改为公共方法 - 在测试初始化时添加上下文清理确保测试环境纯净 - 在测试清理时使用 try-finally 确保架构正确销毁和上下文清理 - 修复了架构对象可能未正确清理的潜在问题
This commit is contained in:
parent
8a01178cc4
commit
f022f25ae6
@ -15,14 +15,22 @@ public class ArchitectureInitializationTests
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
GameContext.Clear();
|
||||
_architecture = new TestArchitecture();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_architecture!.Destroy();
|
||||
_architecture = null;
|
||||
try
|
||||
{
|
||||
_architecture?.Destroy();
|
||||
}
|
||||
finally
|
||||
{
|
||||
GameContext.Clear();
|
||||
_architecture = null;
|
||||
}
|
||||
}
|
||||
|
||||
private TestArchitecture? _architecture;
|
||||
|
||||
@ -102,11 +102,11 @@ public static class GameContext
|
||||
ArchitectureDictionary.TryRemove(architectureType, out _);
|
||||
}
|
||||
|
||||
// 测试专用
|
||||
|
||||
/// <summary>
|
||||
/// 为测试重置所有架构上下文(仅内部使用)
|
||||
/// 清空所有架构上下文绑定
|
||||
/// </summary>
|
||||
internal static void ResetForTests()
|
||||
public static void Clear()
|
||||
{
|
||||
ArchitectureDictionary.Clear();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user