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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class MerchantStatementDomainEventHandlerTests : DomainEventHandlerTests
public MerchantStatementDomainEventHandlerTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
{
this.EventHandler = new MerchantStatementDomainEventHandler(this.Mediator.Object);
Logger.Initialise(new NullLogger());
}

[Fact]
Expand Down Expand Up @@ -64,6 +65,37 @@ public async Task MerchantStatementDomainEventHandler_Handle_MerchantFeeSettledE
result.IsSuccess.ShouldBeTrue();
}

[Fact]
public async Task MerchantStatementDomainEventHandler_Handle_MerchantFeeSettledEvent_WrongExpectedRetried_EventIsHandled()
{
List<String> errors = new() { "WrongExpectedVersion" };

this.Mediator.SetupSequence(m => m.Send(It.IsAny<IRequest<Result>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Success());

Result result = await this.EventHandler.Handle(TestData.DomainEvents.MerchantFeeSettledEvent, CancellationToken.None);
result.IsSuccess.ShouldBeTrue();
this.Mediator.Verify(m => m.Send(It.IsAny<IRequest<Result>>(), It.IsAny<CancellationToken>()), Times.Exactly(2));
}

[Fact]
public async Task MerchantStatementDomainEventHandler_Handle_MerchantFeeSettledEvent_WrongExpectedRetried_AllRetriesFailed()
{
List<String> errors = new() { "WrongExpectedVersion" };
this.Mediator.SetupSequence(m => m.Send(It.IsAny<IRequest<Result>>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Failure(errors))
.ReturnsAsync(Result.Failure(errors));

Result result = await this.EventHandler.Handle(TestData.DomainEvents.MerchantFeeSettledEvent, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
this.Mediator.Verify(m => m.Send(It.IsAny<IRequest<Result>>(), It.IsAny<CancellationToken>()), Times.Exactly(6));
}

[Fact]
public async Task MerchantStatementDomainEventHandler_Handle_StatementCreatedForDateEvent_EventIsHandled()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
using System;
using MediatR;
using MediatR;
using Polly;
using Prometheus;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shared.EventStore.EventHandling;
using Shared.Exceptions;
using Shared.Logger;
using Shared.ValueObjects;
using SimpleResults;
using System;
using System.Diagnostics;
using System.IO;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Prometheus;
using Shared.Logger;
using TransactionProcessor.BusinessLogic.Common;
using TransactionProcessor.BusinessLogic.Requests;
using TransactionProcessor.BusinessLogic.Services;
using TransactionProcessor.DomainEvents;
using Shared.EventStore.Aggregate;
using Shared.ValueObjects;

namespace TransactionProcessor.BusinessLogic.EventHandling
{
Expand Down Expand Up @@ -144,12 +145,32 @@
private async Task<Result> HandleSpecificDomainEvent(SettlementDomainEvents.MerchantFeeSettledEvent domainEvent,
CancellationToken cancellationToken)
{
MerchantStatementCommands.AddSettledFeeToMerchantStatementCommand command = new(domainEvent.EstateId, domainEvent.MerchantId, domainEvent.FeeCalculatedDateTime,
PositiveMoney.Create(Money.Create(domainEvent.CalculatedValue)), domainEvent.TransactionId, domainEvent.FeeId);
IAsyncPolicy<Result> retryPolicy = PolicyFactory.CreatePolicy(policyTag: "MerchantStatementDomainEventHandler - HandleSpecificDomainEvent<SettlementDomainEvents.MerchantFeeSettledEvent>");

try
{
return await PolicyFactory.ExecuteWithPolicyAsync(async () =>
{
MerchantStatementCommands.AddSettledFeeToMerchantStatementCommand command = new(domainEvent.EstateId, domainEvent.MerchantId, domainEvent.FeeCalculatedDateTime,
PositiveMoney.Create(Money.Create(domainEvent.CalculatedValue)), domainEvent.TransactionId, domainEvent.FeeId);

Result result = await this.Mediator.Send(command, cancellationToken);
return result;

}, retryPolicy, "MerchantStatementDomainEventHandler - HandleSpecificDomainEvent<SettlementDomainEvents.MerchantFeeSettledEvent>");
}
catch (Exception ex)
{
return Result.Failure(ex.GetExceptionMessages());
}
//MerchantStatementCommands.AddSettledFeeToMerchantStatementCommand command = new(domainEvent.EstateId, domainEvent.MerchantId, domainEvent.FeeCalculatedDateTime,
// PositiveMoney.Create(Money.Create(domainEvent.CalculatedValue)), domainEvent.TransactionId, domainEvent.FeeId);

Check notice on line 167 in TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessor.BusinessLogic/EventHandling/MerchantStatementDomainEventHandler.cs#L167

Remove this commented out code.

////return await this.Mediator.Send(command, cancellationToken);
//Result result = await this.Mediator.Send(command, cancellationToken);
//return result;


//return await this.Mediator.Send(command, cancellationToken);
Result result = await this.Mediator.Send(command, cancellationToken);
return result;
}

#endregion
Expand Down
Loading