From 7b432c60c70b8cea8ebf20a51c47db87a5989678 Mon Sep 17 00:00:00 2001 From: gewuyou <95328647+GeWuYou@users.noreply.github.com> Date: Mon, 27 Apr 2026 19:08:07 +0800 Subject: [PATCH] =?UTF-8?q?test(coroutine):=20=E6=8B=86=E5=88=86=20QueryCo?= =?UTF-8?q?routineExtensionsTests=20=E6=9F=A5=E8=AF=A2=E8=BE=85=E5=8A=A9?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 拆分 QueryCoroutineExtensionsTests 末尾的 IntQuery、ComplexQuery 与 ComplexResult 到同目录独立文件 - 补充 提取类型的 XML 文档并保持查询测试行为不变 --- .../Coroutine/ComplexQuery.cs | 62 +++++++++++++++++++ .../Coroutine/ComplexResult.cs | 22 +++++++ GFramework.Core.Tests/Coroutine/IntQuery.cs | 44 +++++++++++++ .../QueryCoroutineExtensionsTests.cs | 60 ------------------ 4 files changed, 128 insertions(+), 60 deletions(-) create mode 100644 GFramework.Core.Tests/Coroutine/ComplexQuery.cs create mode 100644 GFramework.Core.Tests/Coroutine/ComplexResult.cs create mode 100644 GFramework.Core.Tests/Coroutine/IntQuery.cs diff --git a/GFramework.Core.Tests/Coroutine/ComplexQuery.cs b/GFramework.Core.Tests/Coroutine/ComplexQuery.cs new file mode 100644 index 00000000..bb58ec3f --- /dev/null +++ b/GFramework.Core.Tests/Coroutine/ComplexQuery.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using GFramework.Core.Abstractions.Architectures; +using GFramework.Core.Abstractions.Query; + +namespace GFramework.Core.Tests.Coroutine; + +/// +/// 为 提供复杂对象结果的查询测试替身。 +/// +internal class ComplexQuery : IQuery +{ + private IArchitectureContext? _context; + + /// + /// 获取或设置测试查询使用的名称。 + /// + public string Name { get; set; } = string.Empty; + + /// + /// 获取或设置需要聚合的整数集合。 + /// + public List Values { get; set; } = new(); + + /// + /// 获取或设置附加元数据。 + /// + public Dictionary Metadata { get; set; } = new(StringComparer.Ordinal); + + /// + /// 绑定当前查询所属的架构上下文。 + /// + /// 测试期间由查询管线注入的上下文。 + public void SetContext(IArchitectureContext context) + { + _context = context; + } + + /// + /// 获取当前查询持有的架构上下文。 + /// + /// 此前通过 绑定的上下文实例。 + public IArchitectureContext GetContext() + { + return _context!; + } + + /// + /// 执行查询并生成复杂结果对象。 + /// + /// 包含名称、求和值和计数信息的测试结果。 + public ComplexResult Do() + { + return new ComplexResult + { + ProcessedName = Name, + Sum = Values.Sum(), + Count = Values.Count + }; + } +} diff --git a/GFramework.Core.Tests/Coroutine/ComplexResult.cs b/GFramework.Core.Tests/Coroutine/ComplexResult.cs new file mode 100644 index 00000000..c6501114 --- /dev/null +++ b/GFramework.Core.Tests/Coroutine/ComplexResult.cs @@ -0,0 +1,22 @@ +namespace GFramework.Core.Tests.Coroutine; + +/// +/// 为 提供复杂对象结果的测试载体。 +/// +internal class ComplexResult +{ + /// + /// 获取或设置处理后的名称。 + /// + public string ProcessedName { get; set; } = string.Empty; + + /// + /// 获取或设置整数集合的求和结果。 + /// + public int Sum { get; set; } + + /// + /// 获取或设置整数集合中的元素数量。 + /// + public int Count { get; set; } +} diff --git a/GFramework.Core.Tests/Coroutine/IntQuery.cs b/GFramework.Core.Tests/Coroutine/IntQuery.cs new file mode 100644 index 00000000..02b8826e --- /dev/null +++ b/GFramework.Core.Tests/Coroutine/IntQuery.cs @@ -0,0 +1,44 @@ +using GFramework.Core.Abstractions.Architectures; +using GFramework.Core.Abstractions.Query; + +namespace GFramework.Core.Tests.Coroutine; + +/// +/// 为 提供布尔结果的整数查询测试替身。 +/// +internal class IntQuery : IQuery +{ + private IArchitectureContext? _context; + + /// + /// 获取或设置参与查询计算的整数值。 + /// + public int Value { get; set; } + + /// + /// 绑定当前查询所属的架构上下文。 + /// + /// 测试期间由查询管线注入的上下文。 + public void SetContext(IArchitectureContext context) + { + _context = context; + } + + /// + /// 获取当前查询持有的架构上下文。 + /// + /// 此前通过 绑定的上下文实例。 + public IArchitectureContext GetContext() + { + return _context!; + } + + /// + /// 执行查询并返回布尔结果。 + /// + /// 大于零时返回 + public bool Do() + { + return Value > 0; + } +} diff --git a/GFramework.Core.Tests/Coroutine/QueryCoroutineExtensionsTests.cs b/GFramework.Core.Tests/Coroutine/QueryCoroutineExtensionsTests.cs index 78b97394..e608b660 100644 --- a/GFramework.Core.Tests/Coroutine/QueryCoroutineExtensionsTests.cs +++ b/GFramework.Core.Tests/Coroutine/QueryCoroutineExtensionsTests.cs @@ -329,63 +329,3 @@ public class QueryCoroutineExtensionsTests Assert.That(receivedResult, Is.Null); } } - -/// -/// 用于测试的整数查询类 -/// -internal class IntQuery : IQuery -{ - private IArchitectureContext? _context; - public int Value { get; set; } - - public void SetContext(IArchitectureContext context) - { - _context = context; - } - - public IArchitectureContext GetContext() - { - return _context!; - } - - public bool Do() - { - return Value > 0; - } -} - -/// -/// 用于测试的复杂查询类 -/// -internal class ComplexQuery : IQuery -{ - private IArchitectureContext? _context; - public string Name { get; set; } = string.Empty; - public List Values { get; set; } = new(); - public Dictionary Metadata { get; set; } = new(StringComparer.Ordinal); - - public void SetContext(IArchitectureContext context) - { - _context = context; - } - - public IArchitectureContext GetContext() - { - return _context!; - } - - public ComplexResult Do() - { - return new ComplexResult { ProcessedName = Name, Sum = Values.Sum(), Count = Values.Count }; - } -} - -/// -/// 用于测试的复杂结果类 -/// -internal class ComplexResult -{ - public string ProcessedName { get; set; } = string.Empty; - public int Sum { get; set; } - public int Count { get; set; } -}