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
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
<PackageVersion Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="10.0.2" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Imposter" Version="0.1.9" />
<PackageVersion Include="NetBarcode" Version="1.8.3" />
<PackageVersion Include="NLog.Extensions.Logging" Version="6.2.0" />
<PackageVersion Include="NuGet.Packaging" Version="7.9.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Moq;
using TransactionProcessor.BusinessLogic.Tests;
using Imposter.Abstractions;
using Shared.Logger;
using Shared.Serialisation;
using Shouldly;
Expand All @@ -17,14 +18,14 @@ public class ContractDomainEventHandlerTests

#region Methods

private Mock<ITransactionProcessorReadModelRepository> EstateReportingRepository;
private ITransactionProcessorReadModelRepositoryImposter EstateReportingRepository;

private ReadModelDomainEventHandler DomainEventHandler;
public ContractDomainEventHandlerTests() {
Logger.Initialise(NullLogger.Instance);
StringSerialiser.Initialise(new Shared.Serialisation.SystemTextJsonSerializer(new System.Text.Json.JsonSerializerOptions()));
this.EstateReportingRepository= new Mock<ITransactionProcessorReadModelRepository>();
this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Object);
this.EstateReportingRepository= new ITransactionProcessorReadModelRepositoryImposter();
this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Instance());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using Imposter.Abstractions;
using Shared.Logger;
using Shared.Serialisation;
using Shouldly;
Expand All @@ -18,25 +18,24 @@ public class EstateDomainEventHandlerTests
{
#region Methods

private Mock<ITransactionProcessorReadModelRepository> EstateReportingRepository;
private ITransactionProcessorReadModelRepositoryImposter EstateReportingRepository;

private ReadModelDomainEventHandler DomainEventHandler;

public EstateDomainEventHandlerTests()
{
Logger.Initialise(NullLogger.Instance);
StringSerialiser.Initialise(new Shared.Serialisation.SystemTextJsonSerializer(new System.Text.Json.JsonSerializerOptions()));
this.EstateReportingRepository = new Mock<ITransactionProcessorReadModelRepository>();
this.EstateReportingRepository = new ITransactionProcessorReadModelRepositoryImposter();

this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Object);
this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Instance());
}
[Fact]
public void EstateDomainEventHandler_EstateCreatedEvent_EventIsHandled()
{
EstateDomainEvents.EstateCreatedEvent estateCreatedEvent = TestData.DomainEvents.EstateCreatedEvent;
this.EstateReportingRepository
.Setup(r => r.CreateReadModel(It.IsAny<EstateDomainEvents.EstateCreatedEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.EstateReportingRepository.CreateReadModel(Arg<EstateDomainEvents.EstateCreatedEvent>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Success());

Should.NotThrow(async () => { await this.DomainEventHandler.Handle(estateCreatedEvent, TestContext.Current.CancellationToken); });
}
Expand All @@ -45,9 +44,8 @@ public void EstateDomainEventHandler_EstateCreatedEvent_EventIsHandled()
public async Task EstateDomainEventHandler_EstateCreatedEvent_CreateReadModelFailed_EventIsHandled()
{
EstateDomainEvents.EstateCreatedEvent estateCreatedEvent = TestData.DomainEvents.EstateCreatedEvent;
this.EstateReportingRepository
.Setup(r => r.CreateReadModel(It.IsAny<EstateDomainEvents.EstateCreatedEvent>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);
this.EstateReportingRepository.CreateReadModel(Arg<EstateDomainEvents.EstateCreatedEvent>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Failure());

Result result = await this.DomainEventHandler.Handle(estateCreatedEvent, TestContext.Current.CancellationToken);
result.IsFailed.ShouldBeTrue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Imposter.Abstractions;
using MediatR;
using Moq;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shared.Logger;
Expand All @@ -22,22 +22,22 @@ namespace TransactionProcessor.BusinessLogic.Tests.DomainEventHandlers
{
public class MerchantDomainEventHandlerTests : DomainEventHandlerTests
{
private readonly Mock<ITransactionProcessorReadModelRepository> TransactionProcessorReadModelRepository;
private readonly ITransactionProcessorReadModelRepositoryImposter TransactionProcessorReadModelRepository;
private readonly MerchantDomainEventHandler DomainEventHandler;

public MerchantDomainEventHandlerTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) {
this.TransactionProcessorReadModelRepository = new Mock<ITransactionProcessorReadModelRepository>();
this.TransactionProcessorReadModelRepository = new ITransactionProcessorReadModelRepositoryImposter();

this.DomainEventHandler = new MerchantDomainEventHandler(this.TransactionProcessorReadModelRepository.Object,
this.Mediator.Object);
this.DomainEventHandler = new MerchantDomainEventHandler(this.TransactionProcessorReadModelRepository.Instance(),
this.Mediator.Instance());
}

[Fact]
public async Task MerchantDomainEventHandler_Handle_CallbackReceivedEnrichedEvent_Deposit_EventIsHandled()
{
this.TransactionProcessorReadModelRepository.Setup(e => e.GetMerchantFromReference(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.TransactionProcessorReadModelRepository.GetMerchantFromReference(Arg<Guid>.Any(), Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Success(TestData.MerchantModelWithAddressesContactsDevicesAndOperatorsAndContracts()));
this.Mediator.Setup(m => m.Send(It.IsAny<MerchantCommands.MakeMerchantDepositCommand>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success);
this.Mediator.Send<Result>(Arg<IRequest<Result>>.Any(), Arg<CancellationToken>.Any()).ReturnsAsync(Result.Success());
CallbackReceivedEnrichedEvent domainEvent = TestData.DomainEvents.CallbackReceivedEnrichedEventDeposit;

var result = await this.DomainEventHandler.Handle(domainEvent, TestContext.Current.CancellationToken);
Expand All @@ -57,7 +57,7 @@ public async Task MerchantDomainEventHandler_Handle_CallbackReceivedEnrichedEven
[Fact]
public async Task MerchantDomainEventHandler_Handle_CallbackReceivedEnrichedEvent_Deposit_GetMerchantFailed_ResultIsFailure()
{
this.TransactionProcessorReadModelRepository.Setup(e => e.GetMerchantFromReference(It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.TransactionProcessorReadModelRepository.GetMerchantFromReference(Arg<Guid>.Any(), Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Failure());

CallbackReceivedEnrichedEvent domainEvent = TestData.DomainEvents.CallbackReceivedEnrichedEventDeposit;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using Imposter.Abstractions;
using Shared.Logger;
using Shared.Serialisation;
using Shouldly;
Expand All @@ -16,43 +16,41 @@ namespace TransactionProcessor.BusinessLogic.Tests.DomainEventHandlers;

public class MerchantScheduleDomainEventHandlerTests
{
private readonly Mock<ITransactionProcessorReadModelRepository> EstateReportingRepository;
private readonly ITransactionProcessorReadModelRepositoryImposter EstateReportingRepository;
private readonly ReadModelDomainEventHandler DomainEventHandler;

public MerchantScheduleDomainEventHandlerTests()
{
Logger.Initialise(NullLogger.Instance);
StringSerialiser.Initialise(new SystemTextJsonSerializer(new JsonSerializerOptions()));
this.EstateReportingRepository = new Mock<ITransactionProcessorReadModelRepository>();
this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Object);
this.EstateReportingRepository = new ITransactionProcessorReadModelRepositoryImposter();
this.DomainEventHandler = new ReadModelDomainEventHandler(this.EstateReportingRepository.Instance());
}

[Fact]
public async Task MerchantScheduleDomainEventHandler_MerchantScheduleCreatedEvent_EventIsHandled()
{
MerchantScheduleDomainEvents.MerchantScheduleCreatedEvent domainEvent = TestData.DomainEvents.MerchantScheduleCreatedEvent;
this.EstateReportingRepository
.Setup(r => r.AddMerchantSchedule(domainEvent, It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.EstateReportingRepository.AddMerchantSchedule(domainEvent, Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Success());

Result result = await this.DomainEventHandler.Handle(domainEvent, TestContext.Current.CancellationToken);

result.IsSuccess.ShouldBeTrue();
this.EstateReportingRepository.Verify(r => r.AddMerchantSchedule(domainEvent, It.IsAny<CancellationToken>()), Times.Once);
this.EstateReportingRepository.AddMerchantSchedule(domainEvent, Arg<CancellationToken>.Any()).Called(Count.Once());
}

[Fact]
public async Task MerchantScheduleDomainEventHandler_MerchantScheduleMonthUpdatedEvent_EventIsHandled()
{
MerchantScheduleDomainEvents.MerchantScheduleMonthUpdatedEvent domainEvent = TestData.DomainEvents.MerchantScheduleMonthUpdatedEvent;
this.EstateReportingRepository
.Setup(r => r.UpdateMerchantSchedule(domainEvent, It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.EstateReportingRepository.UpdateMerchantSchedule(domainEvent, Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Success());

Result result = await this.DomainEventHandler.Handle(domainEvent, TestContext.Current.CancellationToken);

result.IsSuccess.ShouldBeTrue();
this.EstateReportingRepository.Verify(r => r.UpdateMerchantSchedule(domainEvent, It.IsAny<CancellationToken>()), Times.Once);
this.EstateReportingRepository.UpdateMerchantSchedule(domainEvent, Arg<CancellationToken>.Any()).Called(Count.Once());
}
}

Loading
Loading