GFramework/GFramework.Core.Tests/Architectures/TrackingPipelineBehavior.cs
gewuyou f0a36de07c test(core-tests): 批量拆分测试辅助类型以消减警告
- 拆分 GFramework.Core.Tests 中多组测试辅助类型到独立文件以消减 MA0048 warning

- 更新 analyzer-warning-reduction 的 tracking 与 trace 以记录批处理基线和下一恢复点

- 验证 GFramework.Core.Tests Release 构建清零并将仓库根权威 warning 基线压降到 288
2026-04-27 19:44:07 +08:00

34 lines
1.2 KiB
C#

using GFramework.Cqrs.Abstractions.Cqrs;
namespace GFramework.Core.Tests.Architectures;
/// <summary>
/// 记录请求通过管道次数的测试行为。
/// </summary>
/// <typeparam name="TRequest">请求类型。</typeparam>
/// <typeparam name="TResponse">响应类型。</typeparam>
public sealed class TrackingPipelineBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IRequest<TResponse>
{
/// <summary>
/// 获取当前测试进程中该请求类型对应的行为触发次数。
/// </summary>
public static int InvocationCount { get; set; }
/// <summary>
/// 记录一次行为执行,然后继续执行下一个处理器。
/// </summary>
/// <param name="message">当前请求消息。</param>
/// <param name="next">下一个处理委托。</param>
/// <param name="cancellationToken">取消令牌。</param>
/// <returns>下游处理器的响应结果。</returns>
public async ValueTask<TResponse> Handle(
TRequest message,
MessageHandlerDelegate<TRequest, TResponse> next,
CancellationToken cancellationToken)
{
InvocationCount++;
return await next(message, cancellationToken).ConfigureAwait(false);
}
}