diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 071f0167..6ae44e3e 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -36,19 +36,6 @@ jobs: - name: Run Integration Tests run: dotnet test "TransactionProcessor.IntegrationTests\TransactionProcessor.IntegrationTests.csproj" --filter Category=PRTest --logger "trx;LogFileName=test-results.trx" - - name: Extract Failed Tests (PowerShell) - if: ${{ failure() }} - run: | - $xml = [xml](Get-Content test-results.trx) - $failedTests = $xml.TestRun.Results.UnitTestResult | Where-Object { $_.outcome -eq "Failed" } - if ($failedTests) { - Write-Host "::error::Failed Tests:" - foreach ($test in $failedTests) { - Write-Host "::error::- $($test.testName)" - } - } - shell: pwsh - - uses: actions/upload-artifact@v4.4.0 if: ${{ failure() }} with: diff --git a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs index aa9b150f..9755d3f0 100644 --- a/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/DomainEventHandlers/TransactionDomainEventHandlerTests.cs @@ -21,63 +21,6 @@ namespace TransactionProcessor.BusinessLogic.Tests.DomainEventHandlers using Testing; using Xunit; - public class TestLogger : ILogger - { - private readonly ITestOutputHelper TestOutputHelper; - - public TestLogger(ITestOutputHelper testOutputHelper) { - this.TestOutputHelper = testOutputHelper; - } - public void LogCritical(string message) - { - this.TestOutputHelper.WriteLine(message); - } - - public void LogCritical(Exception exception) { - this.TestOutputHelper.WriteLine(exception.Message); - } - - public void LogCritical(String message, - Exception exception) { - this.TestOutputHelper.WriteLine(message); - this.TestOutputHelper.WriteLine(exception.Message); - } - - public void LogDebug(string message) - { - this.TestOutputHelper.WriteLine(message); - } - - public void LogError(Exception exception) { - this.TestOutputHelper.WriteLine(exception.Message); - } - - public void LogError(String message, - Exception exception) { - this.TestOutputHelper.WriteLine(message); - this.TestOutputHelper.WriteLine(exception.Message); - } - - public void LogError(string message) - { - this.TestOutputHelper.WriteLine(message); - } - public void LogInformation(string message) - { - this.TestOutputHelper.WriteLine(message); - } - public void LogTrace(string message) - { - this.TestOutputHelper.WriteLine(message); - } - public void LogWarning(string message) - { - this.TestOutputHelper.WriteLine(message); - } - - public Boolean IsInitialised { get; set; } - } - [Collection("Sequential")] public abstract class DomainEventHandlerTests { @@ -87,7 +30,6 @@ public DomainEventHandlerTests(ITestOutputHelper testOutputHelper) { this.Mediator = new Mock(); IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build(); ConfigurationReader.Initialise(configurationRoot); - Logger.Initialise(new TestLogger(testOutputHelper)); this.Mediator.Setup(s => s.Send(It.IsAny>(), It.IsAny())).ReturnsAsync(Result.Success()); } } diff --git a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs index ed9a5349..a7b2937b 100644 --- a/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs +++ b/TransactionProcessor.BusinessLogic.Tests/Services/MerchantDomainServiceTests.cs @@ -18,6 +18,7 @@ using TransactionProcessor.Aggregates; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.BusinessLogic.Services; +using TransactionProcessor.DomainEvents; using TransactionProcessor.Models.Contract; using TransactionProcessor.Models.Merchant; using TransactionProcessor.Testing; @@ -1057,4 +1058,12 @@ public async Task MerchantDomainService_RemoveContractFromMerchant_ValidationFai var result = await this.DomainService.RemoveContractFromMerchant(TestData.Commands.RemoveMerchantContractCommand, CancellationToken.None); result.IsFailed.ShouldBeTrue(); } + + [Fact] + public void Test1() { + var domainEvent = JsonConvert.DeserializeObject("{\r\n \"transactionId\": \"a4702780-03a3-4f9d-8ed0-5b5c88f276ba\",\r\n \"estateId\": \"435613ac-a468-47a3-ac4f-649d89764c22\",\r\n \"merchantId\": \"8bc8434d-41f9-4cc3-83bc-e73f20c02e1d\",\r\n \"calculatedValue\": 0.5,\r\n \"feeId\": \"957939ba-7bec-48b6-adb8-0277faf752ba\",\r\n \"feeValue\": 0.5,\r\n \"feeCalculatedDateTime\": \"2025-01-01T09:17:40\",\r\n \"settledDateTime\": \"2025-01-01T00:00:00\",\r\n \"settlementId\": \"0a4f96f9-0e58-9b43-2f0b-4bdca9367a3f\",\r\n \"transactionDateTime\": \"2025-01-01T09:17:40\",\t\t\t\r\n \"eventId\": \"435613ac-a468-47a3-ac4f-649d89764c22\"\r\n}"); + + var statementDate = MerchantStatementDomainService.CalculateStatementDate(domainEvent.FeeCalculatedDateTime); + statementDate.ShouldBe(new DateTime(2025,2,1)); + } } \ No newline at end of file diff --git a/TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs b/TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs index 98f948b3..44c902a9 100644 --- a/TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs +++ b/TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Prometheus; +using Shared.Logger; using TransactionProcessor.BusinessLogic.Common; using TransactionProcessor.BusinessLogic.Requests; using TransactionProcessor.BusinessLogic.Services; @@ -92,7 +93,13 @@ private async Task HandleSpecificDomainEvent(TransactionDomainEvents.Tra CancellationToken cancellationToken) { MerchantStatementCommands.AddTransactionToMerchantStatementCommand command = new(domainEvent.EstateId, domainEvent.MerchantId, domainEvent.CompletedDateTime, domainEvent.TransactionAmount, domainEvent.IsAuthorised, domainEvent.TransactionId); - return await this.Mediator.Send(command, cancellationToken); + //return await this.Mediator.Send(command, cancellationToken); + var result = await this.Mediator.Send(command, cancellationToken); + if (result.Status == ResultStatus.CriticalError) { + Logger.LogWarning($"Domain Events is {domainEvent}"); + return result; + } + return result; } private async Task HandleSpecificDomainEvent(SettlementDomainEvents.MerchantFeeSettledEvent domainEvent, @@ -100,7 +107,14 @@ private async Task HandleSpecificDomainEvent(SettlementDomainEvents.Merc { MerchantStatementCommands.AddSettledFeeToMerchantStatementCommand command = new(domainEvent.EstateId, domainEvent.MerchantId, domainEvent.FeeCalculatedDateTime, domainEvent.CalculatedValue, domainEvent.TransactionId, domainEvent.FeeId); - return await this.Mediator.Send(command, cancellationToken); + //return await this.Mediator.Send(command, cancellationToken); + var result = await this.Mediator.Send(command, cancellationToken); + if (result.Status == ResultStatus.CriticalError) + { + Logger.LogWarning($"Domain Events is {domainEvent}"); + return result; + } + return result; } #endregion diff --git a/TransactionProcessor.BusinessLogic/Services/MerchantStatementDomainService.cs b/TransactionProcessor.BusinessLogic/Services/MerchantStatementDomainService.cs index 519126da..aea5be07 100644 --- a/TransactionProcessor.BusinessLogic/Services/MerchantStatementDomainService.cs +++ b/TransactionProcessor.BusinessLogic/Services/MerchantStatementDomainService.cs @@ -14,6 +14,7 @@ using System.IO.Abstractions; using System.Threading; using System.Threading.Tasks; +using Google.Protobuf.Reflection; using TransactionProcessor.Aggregates; using TransactionProcessor.Aggregates.Models; using TransactionProcessor.BusinessLogic.Common; @@ -119,6 +120,10 @@ public async Task AddSettledFeeToStatement(MerchantStatementCommands.Add // Work out the next statement date DateTime nextStatementDate = CalculateStatementDate(command.SettledDateTime); + if (nextStatementDate.Year == 1) { + return Result.CriticalError($"Error in statement date generation Generated date is {nextStatementDate}"); + } + Guid merchantStatementId = IdGenerationService.GenerateMerchantStatementAggregateId(command.EstateId, command.MerchantId, nextStatementDate); Guid merchantStatementForDateId = IdGenerationService.GenerateMerchantStatementForDateAggregateId(command.EstateId, command.MerchantId, nextStatementDate, command.SettledDateTime); Guid settlementFeeId = GuidCalculator.Combine(command.TransactionId, command.SettledFeeId); @@ -254,7 +259,7 @@ public async Task RecordActivityDateOnMerchantStatement(MerchantStatemen merchantStatementAggregate.RecordActivityDateOnStatement(command.MerchantStatementId, command.StatementDate, command.EstateId, command.MerchantId, - command.MerchantStatementForDateId, command.StatementDate); + command.MerchantStatementForDateId, command.StatementActivityDate); return Result.Success(); }, command.MerchantStatementId, cancellationToken, false); @@ -277,6 +282,11 @@ public async Task AddTransactionToStatement(MerchantStatementCommands.Ad // Work out the next statement date DateTime nextStatementDate = CalculateStatementDate(command.TransactionDateTime); + if (nextStatementDate.Year == 1) + { + return Result.CriticalError($"Error in statement date generation Generated date is {nextStatementDate}"); + } + Guid merchantStatementId = IdGenerationService.GenerateMerchantStatementAggregateId(command.EstateId, command.MerchantId, nextStatementDate); Guid merchantStatementForDateId = IdGenerationService.GenerateMerchantStatementForDateAggregateId(command.EstateId, command.MerchantId, nextStatementDate, command.TransactionDateTime);