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 @@ -23,12 +23,13 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services
using Shared.Logger;
using Shouldly;
using Testing;
using TransactionProcessor.BusinessLogic.Common;
using TransactionProcessor.BusinessLogic.Services;
using Xunit;

public class FloatDomainServiceTests
{
private readonly Mock<IEstateClient> EstateClient;
private readonly Mock<IIntermediateEstateClient> EstateClient;
private readonly Mock<ISecurityServiceClient> SecurityServiceClient;
private readonly Mock<IAggregateRepository<FloatAggregate, DomainEvent>> FloatAggregateRepository;
private readonly Mock<IAggregateRepository<FloatActivityAggregate, DomainEvent>> FloatActivityAggregateRepository;
Expand All @@ -43,7 +44,7 @@ public FloatDomainServiceTests(){

Logger.Initialise(NullLogger.Instance);

this.EstateClient = new Mock<IEstateClient>();
this.EstateClient = new Mock<IIntermediateEstateClient>();
this.SecurityServiceClient = new Mock<ISecurityServiceClient>();
this.FloatAggregateRepository = new Mock<IAggregateRepository<FloatAggregate, DomainEvent>>();
this.FloatActivityAggregateRepository = new Mock<IAggregateRepository<FloatActivityAggregate, DomainEvent>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Shouldly;
using Testing;
using TransactionAggregate;
using TransactionProcessor.BusinessLogic.Common;
using Xunit;

public class SettlementDomainServiceTests
Expand All @@ -31,7 +32,7 @@

private Mock<ISecurityServiceClient> securityServiceClient;

private Mock<IEstateClient> estateClient;
private Mock<IIntermediateEstateClient> estateClient;

Check warning on line 35 in TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

TransactionProcessor.BusinessLogic.Tests/Services/SettlementDomainServiceTests.cs#L35

Make 'estateClient' 'readonly'.

private SettlementDomainService settlementDomainService;

Expand All @@ -41,7 +42,7 @@
this.settlementAggregateRepository =
new Mock<IAggregateRepository<SettlementAggregate, DomainEvent>>();
this.securityServiceClient = new Mock<ISecurityServiceClient>();
this.estateClient = new Mock<IEstateClient>();
this.estateClient = new Mock<IIntermediateEstateClient>();

this.settlementDomainService =
new SettlementDomainService(this.transactionAggregateRepository.Object, settlementAggregateRepository.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services{
public class TransactionDomainServiceTests{
#region Fields

private readonly Mock<IEstateClient> EstateClient;
private readonly Mock<IIntermediateEstateClient> EstateClient;

private readonly Mock<IOperatorProxy> OperatorProxy;

Expand Down Expand Up @@ -67,7 +67,7 @@ public TransactionDomainServiceTests(){
Logger.Initialise(NullLogger.Instance);

this.TransactionAggregateRepository = new Mock<IAggregateRepository<TransactionAggregate, DomainEvent>>();
this.EstateClient = new Mock<IEstateClient>();
this.EstateClient = new Mock<IIntermediateEstateClient>();
this.SecurityServiceClient = new Mock<ISecurityServiceClient>();
this.OperatorProxy = new Mock<IOperatorProxy>();
this.ReconciliationAggregateRepository = new Mock<IAggregateRepository<ReconciliationAggregate, DomainEvent>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ namespace TransactionProcessor.BusinessLogic.Tests.Services;
using Shared.Logger;
using Shouldly;
using Testing;
using TransactionProcessor.BusinessLogic.Common;
using Xunit;

public class TransactionValidationServiceTests {
private readonly TransactionValidationService TransactionValidationService;
private readonly Mock<ISecurityServiceClient> SecurityServiceClient;

private readonly Mock<IProjectionStateRepository<MerchantBalanceState>> StateRepository;
private readonly Mock<IEstateClient> EstateClient;
private readonly Mock<IIntermediateEstateClient> EstateClient;
private readonly Mock<IEventStoreContext> EventStoreContext;
public TransactionValidationServiceTests() {
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);

Logger.Initialise(NullLogger.Instance);

this.EstateClient = new Mock<IEstateClient>();
this.EstateClient = new Mock<IIntermediateEstateClient>();
this.SecurityServiceClient = new Mock<ISecurityServiceClient>();
this.StateRepository = new Mock<IProjectionStateRepository<MerchantBalanceState>>();
this.EventStoreContext = new Mock<IEventStoreContext>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SimpleResults;
using TransactionProcessor.BusinessLogic.Common;

namespace TransactionProcessor.BusinessLogic.Tests.Services
{
Expand Down Expand Up @@ -37,7 +38,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithEmptyOperators_Err

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new VoucherAggregate());
Expand Down Expand Up @@ -74,7 +75,7 @@ public async Task VoucherDomainService_IssueVoucher_EstateWithNullOperators_Erro

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new VoucherAggregate());
Expand Down Expand Up @@ -111,7 +112,7 @@ public async Task VoucherDomainService_IssueVoucher_InvalidEstate_ErrorThrown()

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new VoucherAggregate());
Expand Down Expand Up @@ -149,7 +150,7 @@ public async Task VoucherDomainService_IssueVoucher_OperatorNotSupportedByEstate

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new VoucherAggregate());
Expand Down Expand Up @@ -186,7 +187,7 @@ public async Task VoucherDomainService_IssueVoucher_VoucherIssued() {

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new VoucherAggregate());
Expand Down Expand Up @@ -226,7 +227,7 @@ public async Task VoucherDomainService_RedeemVoucher_InvalidEstate_ErrorThrown()

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -264,7 +265,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherRedeemed() {

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
Expand Down Expand Up @@ -305,7 +306,7 @@ public async Task VoucherDomainService_RedeemVoucher_VoucherNotFound_ErrorThrown

Logger.Initialise(NullLogger.Instance);

Mock<IEstateClient> estateClient = new Mock<IEstateClient>();
Mock<IIntermediateEstateClient> estateClient = new Mock<IIntermediateEstateClient>();
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
Mock<IAggregateRepository<VoucherAggregate, DomainEvent>> voucherAggregateRepository = new Mock<IAggregateRepository<VoucherAggregate, DomainEvent>>();
voucherAggregateRepository.Setup(v => v.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
Expand Down
111 changes: 111 additions & 0 deletions TransactionProcessor.BusinessLogic/Common/IIntermediateEstateClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EstateManagement.Client;
using EstateManagement.DataTransferObjects.Requests.Merchant;
using EstateManagement.DataTransferObjects.Responses.Contract;
using EstateManagement.DataTransferObjects.Responses.Estate;
using EstateManagement.DataTransferObjects.Responses.Merchant;
using SimpleResults;

namespace TransactionProcessor.BusinessLogic.Common
{
public interface IIntermediateEstateClient
{
Task<Result<EstateResponse>> GetEstate(
string accessToken,
Guid estateId,
CancellationToken cancellationToken);

Task<Result<MerchantResponse>> GetMerchant(
string accessToken,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);

Task<Result<List<ContractProductTransactionFee>>> GetTransactionFeesForProduct(
string accessToken,
Guid estateId,
Guid merchantId,
Guid contractId,
Guid productId,
CancellationToken cancellationToken);

Task<Result<ContractResponse>> GetContract(
string accessToken,
Guid estateId,
Guid contractId,
CancellationToken cancellationToken);

Task<Result> AddDeviceToMerchant(
string accessToken,
Guid estateId,
Guid merchantId,
AddMerchantDeviceRequest request,
CancellationToken cancellationToken);

Task<Result<List<ContractResponse>>> GetMerchantContracts(
string accessToken,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken);

public IEstateClient EstateClient { get; }
}

public class IntermediateEstateClient : IIntermediateEstateClient {

public IntermediateEstateClient(IEstateClient estateClient) {
this.EstateClient = estateClient;
}

public async Task<Result<EstateResponse>> GetEstate(String accessToken,
Guid estateId,
CancellationToken cancellationToken) {
return await this.EstateClient.GetEstate(accessToken, estateId, cancellationToken);
}

public async Task<Result<MerchantResponse>> GetMerchant(String accessToken,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
return await this.EstateClient.GetMerchant(accessToken, estateId, merchantId, cancellationToken);
}

public async Task<Result<List<ContractProductTransactionFee>>> GetTransactionFeesForProduct(String accessToken,
Guid estateId,
Guid merchantId,
Guid contractId,
Guid productId,
CancellationToken cancellationToken) {
return await this.EstateClient.GetTransactionFeesForProduct(accessToken, estateId, merchantId, contractId, productId, cancellationToken);
}

public async Task<Result<ContractResponse>> GetContract(String accessToken,
Guid estateId,
Guid contractId,
CancellationToken cancellationToken) {
return await this.EstateClient.GetContract(accessToken, estateId, contractId, cancellationToken);
}

public async Task<Result> AddDeviceToMerchant(String accessToken,
Guid estateId,
Guid merchantId,
AddMerchantDeviceRequest request,
CancellationToken cancellationToken) {
return await this.EstateClient.AddDeviceToMerchant(accessToken, estateId, merchantId, request, cancellationToken);
}

public async Task<Result<List<ContractResponse>>> GetMerchantContracts(String accessToken,
Guid estateId,
Guid merchantId,
CancellationToken cancellationToken) {
return await this.EstateClient.GetMerchantContracts(accessToken, estateId, merchantId, cancellationToken);
}

public IEstateClient EstateClient { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class FloatDomainService : IFloatDomainService{
private readonly IAggregateRepository<FloatActivityAggregate, DomainEvent> FloatActivityAggregateRepository;
private readonly IAggregateRepository<TransactionAggregate.TransactionAggregate, DomainEvent> TransactionAggregateRepository;

private readonly IEstateClient EstateClient;
private readonly IIntermediateEstateClient EstateClient;
private readonly ISecurityServiceClient SecurityServiceClient;

public FloatDomainService(IAggregateRepository<FloatAggregate, DomainEvent> floatAggregateRepository,
IAggregateRepository<FloatActivityAggregate, DomainEvent> floatActivityAggregateRepository,
IAggregateRepository<TransactionAggregate.TransactionAggregate,DomainEvent> transactionAggregateRepository,
IEstateClient estateClient,
IIntermediateEstateClient estateClient,
ISecurityServiceClient securityServiceClient)
{
this.FloatAggregateRepository = floatAggregateRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SettlementDomainService : ISettlementDomainService

private readonly ISecurityServiceClient SecurityServiceClient;

private readonly IEstateClient EstateClient;
private readonly IIntermediateEstateClient EstateClient;

private async Task<Result> ApplySettlementUpdates(Func<SettlementAggregate, Task<Result>> action,
Guid settlementId,
Expand Down Expand Up @@ -233,7 +233,7 @@ public async Task<Result> AddSettledFeeToSettlement(SettlementCommands.AddSettle
public SettlementDomainService(IAggregateRepository<TransactionAggregate, DomainEvent> transactionAggregateRepository,
IAggregateRepository<SettlementAggregate, DomainEvent> settlementAggregateRepository,
ISecurityServiceClient securityServiceClient,
IEstateClient estateClient)
IIntermediateEstateClient estateClient)
{
this.TransactionAggregateRepository = transactionAggregateRepository;
this.SettlementAggregateRepository = settlementAggregateRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class TransactionDomainService : ITransactionDomainService{
/// <summary>
/// The estate client
/// </summary>
private readonly IEstateClient EstateClient;
private readonly IIntermediateEstateClient EstateClient;

/// <summary>
/// The operator proxy resolver
Expand Down Expand Up @@ -76,7 +76,7 @@ public class TransactionDomainService : ITransactionDomainService{
#region Constructors

public TransactionDomainService(IAggregateRepository<TransactionAggregate, DomainEvent> transactionAggregateRepository,
IEstateClient estateClient,
IIntermediateEstateClient estateClient,
Func<String, IOperatorProxy> operatorProxyResolver,
IAggregateRepository<ReconciliationAggregate, DomainEvent> reconciliationAggregateRepository,
ITransactionValidationService transactionValidationService,
Expand Down
Loading
Loading