using Workflow.Application.BuildFlow.Common.Services;
namespace BuildFlow.Workflow.Tests.Performance;
/// 在导出写入阶段触发取消或指定异常,并记录实际输出路径。
public sealed class CancellingExportExcelService(
CancellationTokenSource? cancellation = null,
Exception? exception = null) : IFormSchemaExcelService
{
/// handler 传入的临时文件路径。
public string? OutputPath { get; private set; }
public byte[] BuildTemplate(string schemaJson, string formName) => [];
public IEnumerable Parse(
string schemaJson,
Stream xlsxStream,
int maxRows,
int maxCellTextLength) => [];
/// 记录路径后触发测试指定的失败。
public Task WriteExportAsync(
string schemaJson,
string formName,
IAsyncEnumerable dataJsonRows,
Stream output,
CancellationToken ct)
{
OutputPath = (output as FileStream)?.Name;
if (cancellation is not null)
{
cancellation.Cancel();
ct.ThrowIfCancellationRequested();
}
throw exception ?? new InvalidOperationException("测试导出写入失败");
}
}