// Copyright (c) 2025-2026 GeWuYou
// SPDX-License-Identifier: Apache-2.0
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 ?? throw new InvalidOperationException(
$"{nameof(SetContext)} must be called before {nameof(GetContext)}.");
}
///
/// 执行查询并生成复杂结果对象。
///
/// 包含名称、求和值和计数信息的测试结果。
public ComplexResult Do()
{
return new ComplexResult
{
ProcessedName = Name,
Sum = Values.Sum(),
Count = Values.Count
};
}
}