Skip to content

Commit f3ddc23

Browse files
Merge pull request #613 from TransactionProcessing/bug/#611_dont_throw_errors_on_float_duplicates
dont throw error on duplicate float credits
2 parents a39f150 + 7528d47 commit f3ddc23

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

TransactionProcessor.FloatAggregate.Tests/FloatAggregateTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ public void FloatAggregate_RecordCreditPurchase_MultipleCreditPurchases_AllCredi
9999
}
100100

101101
[Fact]
102-
public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_ErrorThrown()
102+
public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_NoErrorThrown()
103103
{
104104
FloatAggregate aggregate = FloatAggregate.Create(TestData.FloatAggregateId);
105105
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
106106
DateTime purchaseDateTime = DateTime.Now;
107107
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);
108108

109-
Should.Throw<InvalidOperationException>(() => {
110-
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);
111-
});
109+
Should.NotThrow(() => {
110+
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);
111+
});
112112
}
113113

114114
[Fact]

TransactionProcessor.FloatAggregate/FloatAggregate.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ public static void RecordCreditPurchase(this FloatAggregate aggregate, DateTime
5252
{
5353
aggregate.ValidateFloatIsAlreadyCreated();
5454

55-
aggregate.ValidateCreditIsNotADuplicate(creditPurchasedDate,amount,costPrice);
55+
Boolean isCreditADuplicate = aggregate.IsCreditADuplicate(creditPurchasedDate,amount,costPrice);
56+
if (isCreditADuplicate)
57+
return;
5658

5759
FloatCreditPurchasedEvent floatCreditPurchasedEvent = new FloatCreditPurchasedEvent(aggregate.AggregateId, aggregate.EstateId,
5860
creditPurchasedDate, amount, costPrice);
@@ -86,11 +88,9 @@ public static void ValidateFloatIsNotAlreadyCreated(this FloatAggregate aggregat
8688
}
8789
}
8890

89-
public static void ValidateCreditIsNotADuplicate(this FloatAggregate aggregate, DateTime creditPurchasedDate, Decimal amount, Decimal costPrice){
91+
public static Boolean IsCreditADuplicate(this FloatAggregate aggregate, DateTime creditPurchasedDate, Decimal amount, Decimal costPrice){
9092
Boolean isDuplicate = aggregate.Credits.Any(c => c.costPrice == costPrice && c.amount == amount && c.creditPurchasedDate == creditPurchasedDate);
91-
if (isDuplicate == true){
92-
throw new InvalidOperationException($"Float Aggregate Id {aggregate.AggregateId} already has a credit with this information recorded");
93-
}
93+
return isDuplicate;
9494
}
9595

9696
public static void ValidateTransactionIsNotADuplicate(this FloatAggregate aggregate, Guid transactionId)

0 commit comments

Comments
 (0)