diff --git a/TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs b/TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs index c4473b6..0b4b0b6 100644 --- a/TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs +++ b/TransactionProcessor.Aggregates.Tests/FloatAggregateTests.cs @@ -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); + + } } } \ No newline at end of file diff --git a/TransactionProcessor.Aggregates/FloatAggregate.cs b/TransactionProcessor.Aggregates/FloatAggregate.cs index 3a20d0e..937be52 100644 --- a/TransactionProcessor.Aggregates/FloatAggregate.cs +++ b/TransactionProcessor.Aggregates/FloatAggregate.cs @@ -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 diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs index 8d5e616..9bbaa31 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/TransactionDomainServiceTests.cs @@ -333,7 +333,7 @@ public async Task TransactionDomainService_ProcessSaleTransaction_TransactionIsP this.AggregateService.Setup(t => t.Save(It.IsAny(), It.IsAny())) .ReturnsAsync(Result.Success()); - this.AggregateService.Setup(f => f.GetLatest(It.IsAny(), It.IsAny())).ReturnsAsync(floatAggregate); + this.AggregateService.Setup(f => f.GetLatest(It.IsAny(), It.IsAny())).ReturnsAsync(Result.Success(floatAggregate)); this.TransactionValidationService.Setup(t => t.ValidateSaleTransaction(It.IsAny(), It.IsAny(), diff --git a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs index cc4d1b8..3595245 100644 --- a/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/TransactionDomainService.cs @@ -232,10 +232,9 @@ public async Task> 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);