mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-10 19:56:45 +08:00
test(coroutine): 拆分 QueryCoroutineExtensionsTests 查询辅助类型
- 拆分 QueryCoroutineExtensionsTests 末尾的 IntQuery、ComplexQuery 与 ComplexResult 到同目录独立文件 - 补充 提取类型的 XML 文档并保持查询测试行为不变
This commit is contained in:
parent
3843e5c1dd
commit
7b432c60c7
62
GFramework.Core.Tests/Coroutine/ComplexQuery.cs
Normal file
62
GFramework.Core.Tests/Coroutine/ComplexQuery.cs
Normal file
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// 为 <see cref="QueryCoroutineExtensionsTests" /> 提供复杂对象结果的查询测试替身。
|
||||
/// </summary>
|
||||
internal class ComplexQuery : IQuery<ComplexResult>
|
||||
{
|
||||
private IArchitectureContext? _context;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置测试查询使用的名称。
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置需要聚合的整数集合。
|
||||
/// </summary>
|
||||
public List<int> Values { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置附加元数据。
|
||||
/// </summary>
|
||||
public Dictionary<string, object> Metadata { get; set; } = new(StringComparer.Ordinal);
|
||||
|
||||
/// <summary>
|
||||
/// 绑定当前查询所属的架构上下文。
|
||||
/// </summary>
|
||||
/// <param name="context">测试期间由查询管线注入的上下文。</param>
|
||||
public void SetContext(IArchitectureContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前查询持有的架构上下文。
|
||||
/// </summary>
|
||||
/// <returns>此前通过 <see cref="SetContext" /> 绑定的上下文实例。</returns>
|
||||
public IArchitectureContext GetContext()
|
||||
{
|
||||
return _context!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询并生成复杂结果对象。
|
||||
/// </summary>
|
||||
/// <returns>包含名称、求和值和计数信息的测试结果。</returns>
|
||||
public ComplexResult Do()
|
||||
{
|
||||
return new ComplexResult
|
||||
{
|
||||
ProcessedName = Name,
|
||||
Sum = Values.Sum(),
|
||||
Count = Values.Count
|
||||
};
|
||||
}
|
||||
}
|
||||
22
GFramework.Core.Tests/Coroutine/ComplexResult.cs
Normal file
22
GFramework.Core.Tests/Coroutine/ComplexResult.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace GFramework.Core.Tests.Coroutine;
|
||||
|
||||
/// <summary>
|
||||
/// 为 <see cref="ComplexQuery" /> 提供复杂对象结果的测试载体。
|
||||
/// </summary>
|
||||
internal class ComplexResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置处理后的名称。
|
||||
/// </summary>
|
||||
public string ProcessedName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置整数集合的求和结果。
|
||||
/// </summary>
|
||||
public int Sum { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置整数集合中的元素数量。
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
}
|
||||
44
GFramework.Core.Tests/Coroutine/IntQuery.cs
Normal file
44
GFramework.Core.Tests/Coroutine/IntQuery.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using GFramework.Core.Abstractions.Architectures;
|
||||
using GFramework.Core.Abstractions.Query;
|
||||
|
||||
namespace GFramework.Core.Tests.Coroutine;
|
||||
|
||||
/// <summary>
|
||||
/// 为 <see cref="QueryCoroutineExtensionsTests" /> 提供布尔结果的整数查询测试替身。
|
||||
/// </summary>
|
||||
internal class IntQuery : IQuery<bool>
|
||||
{
|
||||
private IArchitectureContext? _context;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置参与查询计算的整数值。
|
||||
/// </summary>
|
||||
public int Value { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 绑定当前查询所属的架构上下文。
|
||||
/// </summary>
|
||||
/// <param name="context">测试期间由查询管线注入的上下文。</param>
|
||||
public void SetContext(IArchitectureContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前查询持有的架构上下文。
|
||||
/// </summary>
|
||||
/// <returns>此前通过 <see cref="SetContext" /> 绑定的上下文实例。</returns>
|
||||
public IArchitectureContext GetContext()
|
||||
{
|
||||
return _context!;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行查询并返回布尔结果。
|
||||
/// </summary>
|
||||
/// <returns>当 <see cref="Value" /> 大于零时返回 <see langword="true" />。</returns>
|
||||
public bool Do()
|
||||
{
|
||||
return Value > 0;
|
||||
}
|
||||
}
|
||||
@ -329,63 +329,3 @@ public class QueryCoroutineExtensionsTests
|
||||
Assert.That(receivedResult, Is.Null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于测试的整数查询类
|
||||
/// </summary>
|
||||
internal class IntQuery : IQuery<bool>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于测试的复杂查询类
|
||||
/// </summary>
|
||||
internal class ComplexQuery : IQuery<ComplexResult>
|
||||
{
|
||||
private IArchitectureContext? _context;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public List<int> Values { get; set; } = new();
|
||||
public Dictionary<string, object> 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 };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用于测试的复杂结果类
|
||||
/// </summary>
|
||||
internal class ComplexResult
|
||||
{
|
||||
public string ProcessedName { get; set; } = string.Empty;
|
||||
public int Sum { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user