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
13 changes: 0 additions & 13 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -87,7 +30,6 @@ public DomainEventHandlerTests(ITestOutputHelper testOutputHelper) {
this.Mediator = new Mock<IMediator>();
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);
Logger.Initialise(new TestLogger(testOutputHelper));
this.Mediator.Setup(s => s.Send(It.IsAny<IRequest<Result>>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SettlementDomainEvents.MerchantFeeSettledEvent>("{\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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,15 +93,28 @@
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);

Check warning on line 96 in TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs#L96

Remove this commented out code.
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<Result> HandleSpecificDomainEvent(SettlementDomainEvents.MerchantFeeSettledEvent domainEvent,
CancellationToken cancellationToken)
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -119,6 +120,10 @@ public async Task<Result> 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);
Expand Down Expand Up @@ -254,7 +259,7 @@ public async Task<Result> 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);
Expand All @@ -277,6 +282,11 @@ public async Task<Result> 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);

Expand Down
Loading