Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ public void FloatAggregate_RecordCreditPurchase_MultipleCreditPurchases_AllCredi
}

[Fact]
public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_ErrorThrown()
public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_NoErrorThrown()
{
FloatAggregate aggregate = FloatAggregate.Create(TestData.FloatAggregateId);
aggregate.CreateFloat(TestData.EstateId, TestData.ContractId, TestData.ProductId, TestData.FloatCreatedDateTime);
DateTime purchaseDateTime = DateTime.Now;
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);

Should.Throw<InvalidOperationException>(() => {
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);
});
Should.NotThrow(() => {
aggregate.RecordCreditPurchase(purchaseDateTime, 1000, 900);
});
}

[Fact]
Expand Down
10 changes: 5 additions & 5 deletions TransactionProcessor.FloatAggregate/FloatAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public static void RecordCreditPurchase(this FloatAggregate aggregate, DateTime
{
aggregate.ValidateFloatIsAlreadyCreated();

aggregate.ValidateCreditIsNotADuplicate(creditPurchasedDate,amount,costPrice);
Boolean isCreditADuplicate = aggregate.IsCreditADuplicate(creditPurchasedDate,amount,costPrice);
if (isCreditADuplicate)
return;

FloatCreditPurchasedEvent floatCreditPurchasedEvent = new FloatCreditPurchasedEvent(aggregate.AggregateId, aggregate.EstateId,
creditPurchasedDate, amount, costPrice);
Expand Down Expand Up @@ -86,11 +88,9 @@ public static void ValidateFloatIsNotAlreadyCreated(this FloatAggregate aggregat
}
}

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

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