All checks were successful
Build and Deploy / deploy (push) Successful in 1m13s
支持按 box/sku 模板生成 PDF;待支付前可改产品并自动重排货重算费。 Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
2.0 KiB
C#
60 lines
2.0 KiB
C#
using System.Text;
|
|
using FluentAssertions;
|
|
using Oms.Application.Labeling.Hiprint;
|
|
|
|
namespace Oms.Tests.Labeling;
|
|
|
|
public class QuestPdfLabelRendererTests
|
|
{
|
|
[Fact]
|
|
public async Task RenderAsync_SampleTemplate_ShouldProducePdfBytes()
|
|
{
|
|
var json = HiprintTemplateParserTests.LoadFixture("sample_100x150.json");
|
|
var printData = new Dictionary<string, object?>
|
|
{
|
|
["serviceNo"] = "S202607180001",
|
|
["recipientName"] = "John Lee",
|
|
["recipientAddressFull"] = "xxx Street, City, CA 90001",
|
|
["actualWeight"] = 1.25
|
|
};
|
|
|
|
var renderer = new QuestPdfLabelRenderer(new HiprintTemplateParser());
|
|
var bytes = await renderer.RenderAsync(json, printData);
|
|
|
|
bytes.Should().NotBeNullOrEmpty();
|
|
// %PDF
|
|
Encoding.ASCII.GetString(bytes.AsSpan(0, 4)).Should().Be("%PDF");
|
|
bytes.Length.Should().BeGreaterThan(500);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RenderManyAsync_TwoPages_ShouldProducePdfBytes()
|
|
{
|
|
var json = HiprintTemplateParserTests.LoadFixture("sample_100x150.json");
|
|
var pages = new List<IReadOnlyDictionary<string, object?>>
|
|
{
|
|
new Dictionary<string, object?>
|
|
{
|
|
["serviceNo"] = "S1",
|
|
["recipientName"] = "A",
|
|
["recipientAddressFull"] = "Addr A",
|
|
["actualWeight"] = 1
|
|
},
|
|
new Dictionary<string, object?>
|
|
{
|
|
["serviceNo"] = "S2",
|
|
["recipientName"] = "B",
|
|
["recipientAddressFull"] = "Addr B",
|
|
["actualWeight"] = 2
|
|
}
|
|
};
|
|
|
|
var renderer = new QuestPdfLabelRenderer(new HiprintTemplateParser());
|
|
var bytes = await renderer.RenderManyAsync(json, pages);
|
|
|
|
bytes.Should().NotBeNullOrEmpty();
|
|
Encoding.ASCII.GetString(bytes.AsSpan(0, 4)).Should().Be("%PDF");
|
|
bytes.Length.Should().BeGreaterThan(800);
|
|
}
|
|
}
|