44 lines
1.4 KiB
C#
44 lines
1.4 KiB
C#
using ClosedXML.Excel;
|
|
using FluentAssertions;
|
|
using Workflow.Application.BuildFlow.Common.Services;
|
|
using Xunit;
|
|
|
|
namespace BuildFlow.Workflow.Tests.Performance;
|
|
|
|
/// <summary>
|
|
/// Excel 导入行惰性枚举契约测试。
|
|
/// </summary>
|
|
public class LazyExcelRowTests
|
|
{
|
|
[Fact]
|
|
public void ParseReturnsLazyEnumerableInsteadOfMaterializedList()
|
|
{
|
|
var service = new FormSchemaExcelService();
|
|
var template = service.BuildTemplate(Schema, "惰性导入");
|
|
using var input = new MemoryStream(template);
|
|
using var workbook = new XLWorkbook(input);
|
|
var worksheet = workbook.Worksheets.First();
|
|
worksheet.Cell(2, 1).Value = "first";
|
|
worksheet.Cell(3, 1).Value = "second";
|
|
worksheet.Cell(4, 1).Value = "third";
|
|
using var output = new MemoryStream();
|
|
workbook.SaveAs(output);
|
|
output.Position = 0;
|
|
|
|
var rows = service.Parse(Schema, output, 100, 32_767);
|
|
|
|
rows.Should().NotBeAssignableTo<IReadOnlyList<ExcelParsedRow>>();
|
|
rows.Take(1).Should().ContainSingle(x =>
|
|
x.RowNumber == 2 && x.JsonObject.Contains("first", StringComparison.Ordinal));
|
|
}
|
|
|
|
private const string Schema = """
|
|
{
|
|
"type": "object",
|
|
"properties": {
|
|
"name": { "type": "string", "title": "名称", "required": true, "x-component": "Input" }
|
|
}
|
|
}
|
|
""";
|
|
}
|