Skip to content

Commit 8a3693c

Browse files
Tighten merchant schedule validation
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
1 parent 14292c9 commit 8a3693c

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

TransactionProcessor.Aggregates.Tests/MerchantScheduleAggregateTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ public void MerchantScheduleAggregate_Create_WithInitialMonths_IsCreated()
5252
model.Months.Single().OpenDays.ShouldBe([4]);
5353
}
5454

55+
[Fact]
56+
public void MerchantScheduleAggregate_Create_InvalidYear_ErrorReturned()
57+
{
58+
MerchantScheduleAggregate aggregate = MerchantScheduleAggregate.Create(MerchantScheduleId);
59+
60+
Result result = aggregate.Create(EstateId, MerchantId, 1899, []);
61+
62+
result.IsFailed.ShouldBeTrue();
63+
result.Status.ShouldBe(ResultStatus.Invalid);
64+
result.Message.ShouldBe("A valid year must be provided when creating a merchant schedule");
65+
}
66+
5567
[Fact]
5668
public void MerchantScheduleAggregate_SetMonthSchedule_WhenChanged_EmitsMonthEvent()
5769
{

TransactionProcessor.Aggregates/MerchantScheduleAggregate.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ private static Result ValidateCreateArguments(MerchantScheduleAggregate aggregat
149149
if (merchantId == Guid.Empty)
150150
return Result.Invalid("Merchant id must be provided when creating a merchant schedule");
151151

152-
if (year < 1)
152+
if (year < 1900)
153153
return Result.Invalid("A valid year must be provided when creating a merchant schedule");
154154

155155
return Result.Success();
@@ -194,7 +194,7 @@ public MerchantScheduleAggregate()
194194
private MerchantScheduleAggregate(Guid aggregateId)
195195
{
196196
if (aggregateId == Guid.Empty)
197-
throw new ArgumentNullException(nameof(aggregateId));
197+
throw new ArgumentException("Value cannot be empty.", nameof(aggregateId));
198198

199199
this.AggregateId = aggregateId;
200200
this.Months = new Dictionary<Int32, MerchantScheduleMonthModel>();

0 commit comments

Comments
 (0)