All checks were successful
Build and Deploy / deploy (push) Successful in 1m0s
进位区间改为左开右闭且禁止空洞,邮编 range 按数字/字母数字比较,查价仅国家时不再串用别国 zone。 Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
2.5 KiB
C#
98 lines
2.5 KiB
C#
using Fake.Application;
|
|
using FluentAssertions;
|
|
using Oms.Application.Shared;
|
|
using Oms.Domain.ChannelsAggregate.Entities;
|
|
|
|
namespace Oms.Tests;
|
|
|
|
public class WeightRoundingRangeGuardTests
|
|
{
|
|
[Fact]
|
|
public void AdjacentLeftOpenRightClosed_ShouldNotOverlap()
|
|
{
|
|
var existing = new[] { Range(1, 0, 30) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureNoOverlap(30, 60, existing);
|
|
|
|
act.Should().NotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void ContainedRange_ShouldOverlap()
|
|
{
|
|
var existing = new[] { Range(1, 0, 30) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureNoOverlap(5, 10, existing);
|
|
|
|
act.Should().Throw<BusinessException>().WithMessage("*重叠*");
|
|
}
|
|
|
|
[Fact]
|
|
public void CrossingRange_ShouldOverlap()
|
|
{
|
|
var existing = new[] { Range(1, 0, 30) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureNoOverlap(20, 40, existing);
|
|
|
|
act.Should().Throw<BusinessException>();
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateSameRow_ShouldIgnoreSelf()
|
|
{
|
|
var existing = new[] { Range(8, 0, 30), Range(9, 30, 60) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureNoOverlap(0, 30, existing, excludeId: 8);
|
|
|
|
act.Should().NotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void StartNotLessThanEnd_ShouldFail()
|
|
{
|
|
var act = () => WeightRoundingRangeGuard.EnsureNoOverlap(30, 30, []);
|
|
|
|
act.Should().Throw<BusinessException>().WithMessage("*起始值须小于截止值*");
|
|
}
|
|
|
|
[Fact]
|
|
public void HoleBetweenRanges_ShouldFail()
|
|
{
|
|
var existing = new[] { Range(1, 0, 10) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureContiguous(20, 30, existing);
|
|
|
|
act.Should().Throw<BusinessException>().WithMessage("*缺口*");
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjacentRanges_ShouldBeContiguous()
|
|
{
|
|
var existing = new[] { Range(1, 0, 10) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureContiguous(10, 25, existing);
|
|
|
|
act.Should().NotThrow();
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateSameRow_Contiguous_ShouldIgnoreSelf()
|
|
{
|
|
var existing = new[] { Range(8, 0, 30), Range(9, 30, 60) };
|
|
|
|
var act = () => WeightRoundingRangeGuard.EnsureContiguous(0, 30, existing, excludeId: 8);
|
|
|
|
act.Should().NotThrow();
|
|
}
|
|
|
|
private static WeightRoundingInfo Range(int id, decimal start, decimal end) =>
|
|
new()
|
|
{
|
|
Id = id,
|
|
RoundingId = 1,
|
|
StartValue = start,
|
|
EndValue = end,
|
|
Public = "0.5"
|
|
};
|
|
}
|