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 @@ -247,6 +247,46 @@ public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenComplet
pendingSettlementAggregate.GetNumberOfFeesSettled().ShouldBe(0);
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_SuccessfulSale_MerchantWithNotSetSettlementSchedule_ErrorThrown()
{
this.TransactionAggregateManager.Setup(t => t.GetAggregate(It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCompletedAuthorisedSaleTransactionAggregate);

this.FeeCalculationManager.Setup(f => f.CalculateFees(It.IsAny<List<TransactionFeeToCalculate>>(), It.IsAny<Decimal>())).Returns(new List<CalculatedFee>
{
TestData.CalculatedFeeMerchantFee(),
TestData.CalculatedFeeServiceProviderFee
});

this.EstateClient.Setup(e => e.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new MerchantResponse
{
SettlementSchedule = SettlementSchedule.NotSet,
});
this.EstateClient.Setup(e => e.GetTransactionFeesForProduct(It.IsAny<String>(),
It.IsAny<Guid>(),
It.IsAny<Guid>(),
It.IsAny<Guid>(),
It.IsAny<Guid>(),
It.IsAny<CancellationToken>())).ReturnsAsync(TestData.ContractProductTransactionFees);

this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.TokenResponse);


TransactionDomainEventHandler transactionDomainEventHandler = new TransactionDomainEventHandler(this.TransactionAggregateManager.Object,
this.FeeCalculationManager.Object,
this.EstateClient.Object,
this.SecurityServiceClient.Object,
this.TransactionReceiptBuilder.Object,
this.MessagingServiceClient.Object,
this.SettlementAggregateRepository.Object);
Should.Throw<NotSupportedException>(async () =>
{
await transactionDomainEventHandler.Handle(TestData.TransactionHasBeenCompletedEvent, CancellationToken.None);
});
}

[Fact]
public async Task TransactionDomainEventHandler_Handle_TransactionHasBeenCompletedEvent_UnsuccessfulSale_EventIsHandled()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public void TransactionRequestHandler_ProcessReconciliationRequest_IsHandled()
}
}

public class SettlementRequestHanslerTests
public class SettlementRequestHandlerTests
{
[Fact]
public void TransactionRequestHandler_ProcessLogonTransactionRequest_IsHandled()
{
Mock<ITransactionDomainService> transactionDomainService = new Mock<ITransactionDomainService>();
SettlementRequestHandler handler = new SettlementRequestHandler(transactionDomainService.Object);
Mock<ISettlementDomainService> settlementDomainService = new Mock<ISettlementDomainService>();
SettlementRequestHandler handler = new SettlementRequestHandler(settlementDomainService.Object);

ProcessSettlementRequest command = TestData.ProcessSettlementRequest;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
namespace TransactionProcessor.BusinessLogic.Tests.Services
{
using System;
using System.Threading;
using System.Threading.Tasks;
using BusinessLogic.Services;
using Microsoft.Extensions.Configuration;
using Models;
using Moq;
using SettlementAggregates;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shared.General;
using Shared.Logger;
using Shouldly;
using Testing;
using Xunit;

public class SettlementDomainServiceTests
{
[Fact]
public async Task TransactionDomainService_ProcessSettlement_SettlementIsProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

Mock<ITransactionAggregateManager> transactionAggregateManager = new Mock<ITransactionAggregateManager>();
Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>> settlementAggregateRepository =
new Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>>();
settlementAggregateRepository.Setup(s => s.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetSettlementAggregateWithPendingMerchantFees(10));

SettlementDomainService settlementDomainService=
new SettlementDomainService(transactionAggregateManager.Object, settlementAggregateRepository.Object);

ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate,
TestData.EstateId,
CancellationToken.None);

response.ShouldNotBeNull();
response.NumberOfFeesFailedToSettle.ShouldBe(0);
response.NumberOfFeesPendingSettlement.ShouldBe(0);
response.NumberOfFeesSuccessfullySettled.ShouldBe(10);
}

[Fact]
public async Task TransactionDomainService_ProcessSettlement_SettlementAggregateNotCreated_NothingProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

Mock<ITransactionAggregateManager> transactionAggregateManager = new Mock<ITransactionAggregateManager>();
Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>> settlementAggregateRepository =
new Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>>();
settlementAggregateRepository.Setup(s => s.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetEmptySettlementAggregate);

SettlementDomainService settlementDomainService =
new SettlementDomainService(transactionAggregateManager.Object,
settlementAggregateRepository.Object);

ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate,
TestData.EstateId,
CancellationToken.None);

response.ShouldNotBeNull();
response.NumberOfFeesFailedToSettle.ShouldBe(0);
response.NumberOfFeesPendingSettlement.ShouldBe(0);
response.NumberOfFeesSuccessfullySettled.ShouldBe(0);
}

[Fact]
public async Task TransactionDomainService_ProcessSettlement_SettlementAggregateNoFeesToSettles_NothingProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

Mock<ITransactionAggregateManager> transactionAggregateManager = new Mock<ITransactionAggregateManager>();
Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>> settlementAggregateRepository =
new Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>>();
settlementAggregateRepository.Setup(s => s.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetCreatedSettlementAggregate);

SettlementDomainService settlementDomainService =
new SettlementDomainService(transactionAggregateManager.Object,
settlementAggregateRepository.Object);

ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate,
TestData.EstateId,
CancellationToken.None);

response.ShouldNotBeNull();
response.NumberOfFeesFailedToSettle.ShouldBe(0);
response.NumberOfFeesPendingSettlement.ShouldBe(0);
response.NumberOfFeesSuccessfullySettled.ShouldBe(0);
}

[Fact]
public async Task TransactionDomainService_ProcessSettlement_AddSettledFeeThrownException_SettlementProcessed()
{
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

Mock<ITransactionAggregateManager> transactionAggregateManager = new Mock<ITransactionAggregateManager>();
transactionAggregateManager.Setup(t => t.AddSettledFee(It.IsAny<Guid>(),
It.IsAny<Guid>(),
It.IsAny<CalculatedFee>(),
It.IsAny<DateTime>(),
It.IsAny<DateTime>(),
It.IsAny<CancellationToken>())).ThrowsAsync(new Exception());

Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>> settlementAggregateRepository =
new Mock<IAggregateRepository<SettlementAggregate, DomainEventRecord.DomainEvent>>();
settlementAggregateRepository.Setup(s => s.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(TestData.GetSettlementAggregateWithPendingMerchantFees(10));

SettlementDomainService settlementDomainService =
new SettlementDomainService(transactionAggregateManager.Object,
settlementAggregateRepository.Object);

ProcessSettlementResponse response = await settlementDomainService.ProcessSettlement(TestData.SettlementDate,
TestData.EstateId,
CancellationToken.None);

response.ShouldNotBeNull();
response.NumberOfFeesFailedToSettle.ShouldBe(10);
response.NumberOfFeesPendingSettlement.ShouldBe(0);
response.NumberOfFeesSuccessfullySettled.ShouldBe(0);
}
}
}
Loading