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
6 changes: 6 additions & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ jobs:

- name: Run Integration Tests
run: dotnet test "TransactionProcessor.IntegrationTests\TransactionProcessor.IntegrationTests.csproj" --filter Category=PRTest

- uses: actions/upload-artifact@v2
if: ${{ failure() }}
with:
name: tracelogs
path: /home/txnproc/trace/
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,18 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do
foreach (CalculatedFee calculatedFee in merchantFees)
{
// Determine when the fee should be applied
Guid aggregateId = merchant.NextSettlementDueDate.ToGuid();
Logger.LogInformation($"Completed Date {domainEvent.CompletedDateTime}");
Logger.LogInformation($"SettlementSchedule {merchant.SettlementSchedule}");
DateTime settlementDate = CalculateSettlementDate(merchant.SettlementSchedule, domainEvent.CompletedDateTime);
Logger.LogInformation($"Settlement Date {settlementDate}");
Guid aggregateId = settlementDate.ToGuid();

// We need to add the fees to a pending settlement stream (for today)
SettlementAggregate aggregate = await this.SettlementAggregateRepository.GetLatestVersion(aggregateId, cancellationToken);

if (aggregate.IsCreated == false)
{
aggregate.Create(transactionAggregate.EstateId, merchant.NextSettlementDueDate);
aggregate.Create(transactionAggregate.EstateId, settlementDate);
}

aggregate.AddFee(transactionAggregate.MerchantId, transactionAggregate.AggregateId, calculatedFee);
Expand All @@ -255,6 +259,19 @@ private async Task HandleSpecificDomainEvent(TransactionHasBeenCompletedEvent do
}
}

private DateTime CalculateSettlementDate(SettlementSchedule merchantSettlementSchedule, DateTime completeDateTime)
{
switch(merchantSettlementSchedule)
{
case SettlementSchedule.Weekly:
return completeDateTime.Date.AddDays(7).Date;
case SettlementSchedule.Monthly:
return completeDateTime.Date.AddMonths(1).Date;
default:
throw new Exception("Invalid merchant settlement schedule");
}
}

/// <summary>
/// Handles the specific domain event.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Scenario: Get Pending Settlement
| Test Estate 1 | Test Merchant 3 | 8 | 0000 | SUCCESS |

When I get the pending settlements the following information should be returned
| NextSettlementDate | EstateName | NumberOfFees |
| NextWeek | Test Estate 1 | 1 |
| NextMonth | Test Estate 1 | 1 |
| SettlementDate | EstateName | NumberOfFees |
| NextWeek | Test Estate 1 | 1 |
| NextMonth | Test Estate 1 | 1 |

@PRTest
Scenario: Process Settlement
Expand Down Expand Up @@ -142,9 +142,9 @@ Scenario: Process Settlement
| Test Estate 1 | Test Merchant 2 | 6 | 0000 | SUCCESS |

When I get the pending settlements the following information should be returned
| NextSettlementDate | EstateName | NumberOfFees |
| NextWeek | Test Estate 1 | 1 |
| SettlementDate | EstateName | NumberOfFees |
| Yesterday | Test Estate 1 | 1 |

When I process the settlement for 'NextWeek' on Estate 'Test Estate 1' then 1 fees are marked as settled and the settlement is completed
When I process the settlement for 'Yesterday' on Estate 'Test Estate 1' then 1 fees are marked as settled and the settlement is completed


Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 27 additions & 11 deletions TransactionProcessor.IntegrationTests/Shared/SharedSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace TransactionProcessor.IntegrationTests.Shared
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using BusinessLogic.Common;
using Common;
using DataTransferObjects;
using EstateManagement.DataTransferObjects;
Expand Down Expand Up @@ -877,27 +878,37 @@ public async Task WhenIGetThePendingSettlementsTheFollowingInformationShouldBeRe
{
// Get the merchant name
EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow);
String nextSettlementDateString = SpecflowTableHelper.GetStringRowValue(tableRow, "NextSettlementDate");
String settlementDateString = SpecflowTableHelper.GetStringRowValue(tableRow, "SettlementDate");
Int32 numberOfFees = SpecflowTableHelper.GetIntValue(tableRow, "NumberOfFees");
DateTime nextSettlementDate = this.GetNextSettlementDate(DateTime.Now, nextSettlementDateString);

DateTime settlementDate = this.GetSettlementDate(DateTime.Today, settlementDateString);
if (Environment.GetEnvironmentVariable("CI") == Boolean.TrueString.ToLower())
{
settlementDate = settlementDate.AddDays(1);
}

var aggregateid = settlementDate.ToGuid();
await Retry.For(async () =>
{
SettlementResponse settlements =
await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementByDate(this.TestingContext.AccessToken,
nextSettlementDate,
settlementDate,
estateDetails.EstateId,
CancellationToken.None);

settlements.NumberOfFeesPendingSettlement.ShouldBe(numberOfFees);
settlements.NumberOfFeesPendingSettlement.ShouldBe(numberOfFees, $"Settlment date {settlementDate}");
}, TimeSpan.FromMinutes(3));
}
}

[When(@"I process the settlement for '([^']*)' on Estate '([^']*)' then (.*) fees are marked as settled and the settlement is completed")]
public async Task WhenIProcessTheSettlementForOnEstateThenFeesAreMarkedAsSettledAndTheSettlementIsCompleted(String dateString, String estateName, Int32 numberOfFeesSettled)
{
var settlementDate = SpecflowTableHelper.GetDateForDateString(dateString, DateTime.Now);
DateTime settlementDate = this.GetSettlementDate(DateTime.Today, dateString);
if (Environment.GetEnvironmentVariable("CI") == Boolean.TrueString.ToLower())
{
settlementDate = settlementDate.AddDays(1);
}

EstateDetails estateDetails = this.TestingContext.GetEstateDetails(estateName);
await this.TestingContext.DockerHelper.TransactionProcessorClient.ProcessSettlement(this.TestingContext.AccessToken,
settlementDate,
Expand All @@ -915,23 +926,28 @@ await this.TestingContext.DockerHelper.TransactionProcessorClient.GetSettlementB
settlement.NumberOfFeesPendingSettlement.ShouldBe(0);
settlement.NumberOfFeesSettled.ShouldBe(numberOfFeesSettled);
settlement.SettlementCompleted.ShouldBeTrue();
});
}, TimeSpan.FromMinutes(2));
}

private DateTime GetNextSettlementDate(DateTime now,
private DateTime GetSettlementDate(DateTime now,
String nextSettlementDate)
{
if (nextSettlementDate == "Yesterday")
{
return now.AddDays(-1).Date;
}

if (nextSettlementDate == "NextWeek")
{
return now.AddDays(7);
return now.AddDays(7).Date;
}

if (nextSettlementDate == "NextMonth")
{
return now.AddMonths(1);
return now.AddMonths(1).Date;
}

return now;
return now.Date;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TransactionProcessor.BusinessLogic\TransactionProcessor.BusinessLogic.csproj" />
<ProjectReference Include="..\TransactionProcessor.Client\TransactionProcessor.Client.csproj" />
<ProjectReference Include="..\TransactionProcessor.DataTransferObjects\TransactionProcessor.DataTransferObjects.csproj" />
</ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions TransactionProcessor/Controllers/SettlementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace TransactionProcessor.Controllers
using SettlementAggregates;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shared.Logger;

[ExcludeFromCodeCoverage]
[Route(SettlementController.ControllerRoute)]
Expand Down Expand Up @@ -60,6 +61,8 @@ public async Task<IActionResult> GetPendingSettlement([FromRoute] DateTime settl
// Convert the date passed in to a guid
var aggregateId = settlementDate.Date.ToGuid();

Logger.LogInformation($"Settlement Aggregate Id {aggregateId}");

var settlementAggregate = await this.SettlmentAggregateRepository.GetLatestVersion(aggregateId, cancellationToken);

var settlementResponse = new SettlementResponse
Expand Down