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
14 changes: 14 additions & 0 deletions TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,19 @@ public void FloatAggregate_RecordCreditPurchase_DuplicateCreditPurchase_ErrorThr
result.Status.ShouldBe(ResultStatus.Invalid);

}

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

Decimal totalCost = aggregate.GetTotalCostPrice(10);

totalCost.ShouldBe(9);

}
}
}
5 changes: 5 additions & 0 deletions TransactionProcessor.Aggregates/FloatAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ public static Result ValidateCreditIsNotADuplicate(this FloatAggregate aggregate

return Result.Success();
}

public static Decimal GetTotalCostPrice(this FloatAggregate aggregate, Decimal transactionAmount)
{
return transactionAmount * aggregate.UnitCostPrice;
}
}

public record FloatAggregate : Aggregate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ public async Task TransactionDomainService_ProcessSaleTransaction_TransactionIsP
this.AggregateService.Setup(t => t.Save(It.IsAny<TransactionAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success());

this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(floatAggregate);
this.AggregateService.Setup(f => f.GetLatest<FloatAggregate>(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(floatAggregate));

this.TransactionValidationService.Setup(t => t.ValidateSaleTransaction(It.IsAny<Guid>(),
It.IsAny<Guid>(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ public async Task<Result<ProcessSaleTransactionResponse>> ProcessSaleTransaction
Decimal unitCost = 0;
Decimal totalCost = 0;
if (floatAggregateResult.IsSuccess) {
// TODO: Move calculation to float
FloatAggregate floatAggregate = floatAggregateResult.Data;
unitCost = floatAggregate.GetUnitCostPrice();
totalCost = transactionAmount.GetValueOrDefault() * unitCost;
totalCost = floatAggregate.GetTotalCostPrice(transactionAmount.GetValueOrDefault());
}

Result stateResult = transactionAggregate.StartTransaction(command.TransactionDateTime, command.TransactionNumber, transactionType, transactionReference, command.EstateId, command.MerchantId, command.DeviceIdentifier, transactionAmount);
Expand Down
Loading