From 95a7daaf35c38a15cc4ec3fa804314ee01da2f69 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Thu, 23 Sep 2021 14:03:20 +0100 Subject: [PATCH] Minor bug fixes to settlement processing --- .../TransactionDomainEventHandler.cs | 4 ++++ .../Settlement/Settlement.feature.cs | 20 ++++++++++--------- .../PendingSettlementAggregateTests.cs | 12 +++++++++++ .../PendingSettlementAggregate.cs | 8 ++++---- TransactionProcessor.Testing/TestData.cs | 2 ++ 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs index 7eb977d9..090ea2be 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/TransactionDomainEventHandler.cs @@ -229,6 +229,10 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do await this.TransactionAggregateManager.AddFee(transactionAggregate.EstateId, transactionAggregate.AggregateId, calculatedFee, cancellationToken); } } + else if (merchant.SettlementSchedule == SettlementSchedule.NotSet) + { + throw new NotSupportedException($"Merchant {merchant.MerchantId} does not have a settlement schedule configured"); + } else { foreach (CalculatedFee calculatedFee in merchantFees) diff --git a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs index 2cdb9a57..f7bc6a91 100644 --- a/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs +++ b/TransactionProcessor.IntegrationTests/Settlement/Settlement.feature.cs @@ -247,12 +247,14 @@ void System.IDisposable.Dispose() [Xunit.SkippableFactAttribute(DisplayName="Settlement Processing")] [Xunit.TraitAttribute("FeatureTitle", "Settlement")] [Xunit.TraitAttribute("Description", "Settlement Processing")] + [Xunit.TraitAttribute("Category", "PRTest")] public virtual void SettlementProcessing() { - string[] tagsOfScenario = ((string[])(null)); + string[] tagsOfScenario = new string[] { + "PRTest"}; System.Collections.Specialized.OrderedDictionary argumentsOfScenario = new System.Collections.Specialized.OrderedDictionary(); TechTalk.SpecFlow.ScenarioInfo scenarioInfo = new TechTalk.SpecFlow.ScenarioInfo("Settlement Processing", null, tagsOfScenario, argumentsOfScenario); -#line 49 +#line 50 this.ScenarioInitialize(scenarioInfo); #line hidden bool isScenarioIgnored = default(bool); @@ -315,7 +317,7 @@ public virtual void SettlementProcessing() "testcontact3@merchant2.co.uk", "Test Estate 1", "Monthly"}); -#line 50 +#line 51 testRunner.Given("I create the following merchants", ((string)(null)), table71, "Given "); #line hidden TechTalk.SpecFlow.Table table72 = new TechTalk.SpecFlow.Table(new string[] { @@ -360,7 +362,7 @@ public virtual void SettlementProcessing() "00000003", "10000003", "Test Estate 1"}); -#line 56 +#line 57 testRunner.Given("I have assigned the following operator to the merchants", ((string)(null)), table72, "Given "); #line hidden TechTalk.SpecFlow.Table table73 = new TechTalk.SpecFlow.Table(new string[] { @@ -379,7 +381,7 @@ public virtual void SettlementProcessing() "123456782", "Test Merchant 3", "Test Estate 1"}); -#line 65 +#line 66 testRunner.Given("I have assigned the following devices to the merchants", ((string)(null)), table73, "Given "); #line hidden TechTalk.SpecFlow.Table table74 = new TechTalk.SpecFlow.Table(new string[] { @@ -406,7 +408,7 @@ public virtual void SettlementProcessing() "Today", "Test Merchant 3", "Test Estate 1"}); -#line 71 +#line 72 testRunner.Given("I make the following manual merchant deposits", ((string)(null)), table74, "Given "); #line hidden TechTalk.SpecFlow.Table table75 = new TechTalk.SpecFlow.Table(new string[] { @@ -544,7 +546,7 @@ public virtual void SettlementProcessing() "10 KES", "test@recipient.co.uk", ""}); -#line 77 +#line 78 testRunner.When("I perform the following transactions", ((string)(null)), table75, "When "); #line hidden TechTalk.SpecFlow.Table table76 = new TechTalk.SpecFlow.Table(new string[] { @@ -601,7 +603,7 @@ public virtual void SettlementProcessing() "8", "0000", "SUCCESS"}); -#line 88 +#line 89 testRunner.Then("transaction response should contain the following information", ((string)(null)), table76, "Then "); #line hidden TechTalk.SpecFlow.Table table77 = new TechTalk.SpecFlow.Table(new string[] { @@ -616,7 +618,7 @@ public virtual void SettlementProcessing() "NextMonth", "Test Estate 1", "1"}); -#line 99 +#line 100 testRunner.When("I get the pending settlements the following information should be returned", ((string)(null)), table77, "When "); #line hidden } diff --git a/TransactionProcessor.SettlementAggregates.Tests/PendingSettlementAggregateTests.cs b/TransactionProcessor.SettlementAggregates.Tests/PendingSettlementAggregateTests.cs index 8b5c4f03..48aa66ff 100644 --- a/TransactionProcessor.SettlementAggregates.Tests/PendingSettlementAggregateTests.cs +++ b/TransactionProcessor.SettlementAggregates.Tests/PendingSettlementAggregateTests.cs @@ -61,6 +61,18 @@ public void PendingSettlementAggregate_AddFee_TwoFeesAdded_FeesAreAdded() aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(2); } + [Fact] + public void PendingSettlementAggregate_AddFee_TwoFeesAdded_SameFeeIdDifferentTransaction_FeesAreAdded() + { + PendingSettlementAggregate aggregate = PendingSettlementAggregate.Create(TestData.PendingSettlementAggregateId); + aggregate.Create(TestData.EstateId, TestData.SettlementDate); + aggregate.AddFee(TestData.MerchantId, TestData.TransactionId, TestData.CalculatedFeeMerchantFee); + aggregate.AddFee(TestData.MerchantId, TestData.TransactionId2, TestData.CalculatedFeeMerchantFee); + + aggregate.AggregateId.ShouldBe(TestData.PendingSettlementAggregateId); + aggregate.GetNumberOfFeesPendingSettlement().ShouldBe(2); + } + [Fact] public void PendingSettlementAggregate_AddFee_AggregateNotCreated_ErrorThrown() { diff --git a/TransactionProcessor.SettlementAggregates/PendingSettlementAggregate.cs b/TransactionProcessor.SettlementAggregates/PendingSettlementAggregate.cs index b264d928..dda0150b 100644 --- a/TransactionProcessor.SettlementAggregates/PendingSettlementAggregate.cs +++ b/TransactionProcessor.SettlementAggregates/PendingSettlementAggregate.cs @@ -72,7 +72,7 @@ public void AddFee(Guid merchantId, } this.CheckHasBeenCreated(); - this.CheckFeeHasNotAlreadyBeenAdded(calculatedFee); + this.CheckFeeHasNotAlreadyBeenAdded(transactionId, calculatedFee); DomainEventRecord.DomainEvent @event = null; if (calculatedFee.FeeType == FeeType.Merchant) @@ -137,11 +137,11 @@ protected override Object GetMetadata() return null; } - private void CheckFeeHasNotAlreadyBeenAdded(CalculatedFee calculatedFee) + private void CheckFeeHasNotAlreadyBeenAdded(Guid transactionId, CalculatedFee calculatedFee) { - if (this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId)) + if (this.CalculatedFeesPendingSettlement.Any(c => c.calculatedFee.FeeId == calculatedFee.FeeId && c.transactionId == transactionId)) { - throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] has already been added to this days pending settlement"); + throw new InvalidOperationException($"Fee with Id [{calculatedFee.FeeId}] for Transaction Id [{transactionId}] has already been added to this days pending settlement"); } } diff --git a/TransactionProcessor.Testing/TestData.cs b/TransactionProcessor.Testing/TestData.cs index d29fd00b..49a2c382 100644 --- a/TransactionProcessor.Testing/TestData.cs +++ b/TransactionProcessor.Testing/TestData.cs @@ -72,6 +72,8 @@ public class TestData public static Guid TransactionId = Guid.Parse("AE89B2F6-307B-46F4-A8E7-CEF27097D766"); + public static Guid TransactionId2 = Guid.Parse("760E702C-682E-41B1-A582-3D4ECA0F38C3"); + public static Guid PendingSettlementAggregateId = Guid.Parse("BAEBA232-CD7F-46F5-AE2E-3204FE69A441"); public static String TransactionNumber = "0001";