106 lines
3.7 KiB
C#
106 lines
3.7 KiB
C#
using FluentAssertions;
|
|
using Oms.Application.Shared;
|
|
|
|
namespace Oms.Tests;
|
|
|
|
public class PublishSnapshotCompareTests
|
|
{
|
|
private const string LegacyOnlineJson = """
|
|
{
|
|
"prices": [
|
|
{
|
|
"id": 1,
|
|
"status": 2,
|
|
"details": [
|
|
{
|
|
"id": 6,
|
|
"priceId": 1,
|
|
"calculatedValue": 0,
|
|
"factorValuesJson": { "分区": "3", "重量": "(0-0.5]" },
|
|
"calculationFormula": "total",
|
|
"customerGroupValues": { "普通客户": 11 }
|
|
}
|
|
],
|
|
"factors": [
|
|
{ "id": 7, "factor": "zone", "priceId": 1, "factorValues": ["3"], "serialNumber": 1 },
|
|
{ "id": 8, "factor": "weight", "priceId": 1, "factorValues": ["0.5"], "serialNumber": 2 },
|
|
{ "id": 9, "factor": "customer", "priceId": 1, "factorValues": ["0"], "serialNumber": 3 }
|
|
],
|
|
"costItem": "freight",
|
|
"costUnit": "kg",
|
|
"currency": "RMB",
|
|
"priceName": "运费",
|
|
"createTime": "0001-01-01T00:00:00",
|
|
"serialNumber": 1,
|
|
"serviceChannelId": 1,
|
|
"chargingCondition": "无"
|
|
}
|
|
],
|
|
"serviceChannelId": 1
|
|
}
|
|
""";
|
|
|
|
private const string PreviewJson = """
|
|
{
|
|
"serviceChannelId": 1,
|
|
"prices": [
|
|
{
|
|
"id": 1,
|
|
"serviceChannelId": 1,
|
|
"serialNumber": 1,
|
|
"status": 2,
|
|
"priceName": "运费",
|
|
"costItem": "freight",
|
|
"costUnit": "kg",
|
|
"currency": "RMB",
|
|
"chargingCondition": "无",
|
|
"factors": [
|
|
{ "id": 7, "priceId": 1, "serialNumber": 1, "factor": "zone", "factorValues": ["3"] },
|
|
{ "id": 8, "priceId": 1, "serialNumber": 2, "factor": "weight", "factorValues": ["0.5"] },
|
|
{ "id": 9, "priceId": 1, "serialNumber": 3, "factor": "customer", "factorValues": ["0"] }
|
|
],
|
|
"details": [
|
|
{
|
|
"id": 6,
|
|
"priceId": 1,
|
|
"factorValuesJson": { "分区": "3", "重量": "(0-0.5]" },
|
|
"calculationFormula": "total",
|
|
"calculatedValue": 0,
|
|
"customerGroupValues": { "普通客户": 11 }
|
|
}
|
|
],
|
|
"createTime": "0001-01-01 00:00:00",
|
|
"updateTime": null
|
|
}
|
|
]
|
|
}
|
|
""";
|
|
|
|
[Fact]
|
|
public void ParseChannelPricePublishContentForApi_ShouldMatchPreviewAfterLegacyAuditNoise()
|
|
{
|
|
var online = OmsDocHelper.ParseChannelPricePublishContentForApi(LegacyOnlineJson);
|
|
var preview = OmsDocHelper.ToSnapshotApiContent(OmsDocHelper.DeserializeChannelPriceSnapshot(PreviewJson));
|
|
|
|
var onlineJson = OmsDocHelper.SerializeSnapshotJson(online);
|
|
var previewJson = OmsDocHelper.SerializeSnapshotJson(preview);
|
|
|
|
onlineJson.Should().Be(previewJson);
|
|
}
|
|
|
|
[Fact]
|
|
public void ToSnapshotApiContent_ShouldRoundTripWithPublishSerializer()
|
|
{
|
|
var snapshot = OmsDocHelper.DeserializeChannelPriceSnapshot(PreviewJson);
|
|
snapshot.Should().NotBeNull();
|
|
|
|
var json = OmsDocHelper.SerializeSnapshotJson(snapshot);
|
|
json.Should().NotContain("createTime");
|
|
json.Should().NotContain("updateTime");
|
|
|
|
var apiContent = OmsDocHelper.ToSnapshotApiContent(snapshot);
|
|
var roundTripJson = OmsDocHelper.SerializeSnapshotJson(apiContent);
|
|
roundTripJson.Should().Be(json);
|
|
}
|
|
}
|