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 @@ -88,18 +88,17 @@ public void SettlementAggregate_AddFee_AggregateNotCreated_ErrorThrown()
}

[Fact]
public void SettlementAggregate_AddFee_DuplicateFee_ErrorThrown()
public void SettlementAggregate_AddFee_DuplicateFee_NoErrorThrown()
{
SettlementAggregate aggregate = SettlementAggregate.Create(TestData.SettlementAggregateId);
aggregate.Create(TestData.EstateId, TestData.SettlementDate);
aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee());

Should.Throw<InvalidOperationException>(() =>
{
aggregate.AddFee(TestData.MerchantId,
TestData.TransactionId,
TestData.CalculatedFeeMerchantFee());
});
Should.NotThrow(() =>
{
aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee());
});
aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(1);
}

[Fact]
Expand Down
10 changes: 4 additions & 6 deletions TransactionProcessor.SettlementAggregates/SettlementAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public void AddFee(Guid merchantId,
Guard.ThrowIfNull(calculatedFee, nameof(calculatedFee));

this.CheckHasBeenCreated();
this.CheckFeeHasNotAlreadyBeenAdded(transactionId, calculatedFee);
if (this.HasFeeAlreadyBeenAdded(transactionId, calculatedFee))
return;

DomainEventRecord.DomainEvent @event = null;
if (calculatedFee.FeeType == FeeType.Merchant)
Expand Down Expand Up @@ -184,12 +185,9 @@ protected override Object GetMetadata()
return null;
}

private void CheckFeeHasNotAlreadyBeenAdded(Guid transactionId, CalculatedFee calculatedFee)
private Boolean HasFeeAlreadyBeenAdded(Guid transactionId, CalculatedFee calculatedFee)
{
if (this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId && c.transactionId == transactionId))
{
throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] for Transaction Id [{transactionId}] has already been added to this days pending settlement");
}
return this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId && c.transactionId == transactionId);
}

private void CheckHasBeenCreated()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ public void TransactionAggregate_AddFee_TransactionNotCompleted_ErrorThrown(Tran

[Theory]
[InlineData(TransactionType.Sale, FeeType.ServiceProvider)]
public void TransactionAggregate_AddFee_FeeAlreadyAdded_ErrorThrown(TransactionType transactionType, FeeType feeType)
public void TransactionAggregate_AddFee_FeeAlreadyAdded_NoErrorThrown(TransactionType transactionType, FeeType feeType)
{
TransactionAggregate transactionAggregate = TransactionAggregate.Create(TestData.TransactionId);
transactionAggregate.StartTransaction(TestData.TransactionDateTime, TestData.TransactionNumber, transactionType, TestData.TransactionReference, TestData.EstateId, TestData.MerchantId, TestData.DeviceIdentifier,
Expand All @@ -1111,10 +1111,11 @@ public void TransactionAggregate_AddFee_FeeAlreadyAdded_ErrorThrown(TransactionT
transactionAggregate.CompleteTransaction();
transactionAggregate.AddFee(this.GetCalculatedFeeToAdd(feeType));

Should.Throw<InvalidOperationException>(() =>
Should.NotThrow(() =>
{
transactionAggregate.AddFee(this.GetCalculatedFeeToAdd(feeType));
});
transactionAggregate.GetFees().Count.ShouldBe(1);
}

[Theory]
Expand Down Expand Up @@ -1239,7 +1240,7 @@ public void TransactionAggregate_AddSettledFee_TransactionNotCompleted_ErrorThro

[Theory]
[InlineData(TransactionType.Sale, FeeType.Merchant)]
public void TransactionAggregate_AddSettledFee_FeeAlreadyAdded_ErrorThrown(TransactionType transactionType, FeeType feeType)
public void TransactionAggregate_AddSettledFee_FeeAlreadyAdded_NoErrorThrown(TransactionType transactionType, FeeType feeType)
{
TransactionAggregate transactionAggregate = TransactionAggregate.Create(TestData.TransactionId);
transactionAggregate.StartTransaction(TestData.TransactionDateTime, TestData.TransactionNumber, transactionType, TestData.TransactionReference, TestData.EstateId, TestData.MerchantId, TestData.DeviceIdentifier,
Expand All @@ -1250,10 +1251,12 @@ public void TransactionAggregate_AddSettledFee_FeeAlreadyAdded_ErrorThrown(Trans
transactionAggregate.CompleteTransaction();
transactionAggregate.AddSettledFee(this.GetCalculatedFeeToAdd(feeType), TestData.TransactionFeeSettlementDueDate, TestData.SettlementDate);

Should.Throw<InvalidOperationException>(() =>
Should.NotThrow(() =>
{
transactionAggregate.AddSettledFee(this.GetCalculatedFeeToAdd(feeType), TestData.TransactionFeeSettlementDueDate, TestData.SettlementDate);
});

transactionAggregate.GetFees().Count.ShouldBe(1);
}

[Theory]
Expand Down
21 changes: 8 additions & 13 deletions TransactionProcessor.TransactionAgrgegate/TransactionAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@ public void AddFee(CalculatedFee calculatedFee)
{
Guard.ThrowIfNull(calculatedFee, nameof(calculatedFee));

this.CheckFeeHasNotAlreadyBeenAdded(calculatedFee);
if (HasFeeAlreadyBeenAdded(calculatedFee) == true)
return;

this.CheckTransactionHasBeenAuthorised();
this.CheckTransactionHasBeenCompleted();
this.CheckTransactionCanAttractFees();
Expand Down Expand Up @@ -317,7 +319,9 @@ public void AddSettledFee(CalculatedFee calculatedFee, DateTime settlementDueDat
throw new ArgumentNullException(nameof(calculatedFee));
}

this.CheckFeeHasNotAlreadyBeenAdded(calculatedFee);
if (this.HasFeeAlreadyBeenAdded(calculatedFee) == true)
return;

this.CheckTransactionHasBeenAuthorised();
this.CheckTransactionHasBeenCompleted();
this.CheckTransactionCanAttractFees();
Expand Down Expand Up @@ -689,18 +693,9 @@ private void CheckCustomerHasNotAlreadyRequestedEmailReceipt()
}
}

/// <summary>
/// Checks the fee has not already been added.
/// </summary>
/// <param name="calculatedFee">The calculated fee.</param>
/// <exception cref="System.InvalidOperationException">Fee with Id [{calculatedFee.FeeId}] has already been added to this transaction</exception>
/// <exception cref="InvalidOperationException">Fee with Id [{calculatedFee.FeeId}] has already been added to this transaction</exception>
private void CheckFeeHasNotAlreadyBeenAdded(CalculatedFee calculatedFee)
private Boolean HasFeeAlreadyBeenAdded(CalculatedFee calculatedFee)
{
if (this.CalculatedFees.Any(c => c.FeeId == calculatedFee.FeeId))
{
throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] has already been added to this transaction");
}
return this.CalculatedFees.Any(c => c.FeeId == calculatedFee.FeeId);
}

/// <summary>
Expand Down