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 @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="Imposter" />
<PackageReference Include="Shared.EventStore" />
<PackageReference Include="Shouldly" />
<PackageReference Include="xunit.v3.mtp-v2" />
Expand Down
12 changes: 12 additions & 0 deletions CallbackHandler.BusinessLogic.Tests/ImposterGeneration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Imposter.Abstractions;
using Microsoft.AspNetCore.Hosting;
using SecurityService.Client;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using TransactionProcessor.Client;

[assembly: GenerateImposter(typeof(CallbackHandler.BusinessLogic.Services.ICallbackDomainService))]
[assembly: GenerateImposter(typeof(Shared.EventStore.Aggregate.IAggregateRepository<,>))]
[assembly: GenerateImposter(typeof(ISecurityServiceClient))]
[assembly: GenerateImposter(typeof(ITransactionProcessorClient))]
[assembly: GenerateImposter(typeof(IWebHostEnvironment))]
14 changes: 7 additions & 7 deletions CallbackHandler.BusinessLogic.Tests/Mediator/MediatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Moq;
using Imposter.Abstractions;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -32,19 +32,19 @@ public MediatorTests()
[Fact]
public async Task Mediator_Send_RequestHandled()
{
Mock<IWebHostEnvironment> hostingEnvironment = new();
hostingEnvironment.Setup(he => he.EnvironmentName).Returns("Development");
hostingEnvironment.Setup(he => he.ContentRootPath).Returns("/home");
hostingEnvironment.Setup(he => he.ApplicationName).Returns("Test Application");
IWebHostEnvironmentImposter hostingEnvironment = new();
hostingEnvironment.EnvironmentName.Getter().Returns("Development");
hostingEnvironment.ContentRootPath.Getter().Returns("/home");
hostingEnvironment.ApplicationName.Getter().Returns("Test Application");

ServiceRegistry services = new();
Startup s = new(hostingEnvironment.Object);
Startup s = new(hostingEnvironment.Instance());
IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
//ConfigurationReader.Initialise(configurationRoot);

Startup.Configuration = configurationRoot;

this.AddTestRegistrations(services, hostingEnvironment.Object);
this.AddTestRegistrations(services, hostingEnvironment.Instance());
s.ConfigureContainer(services);
Startup.Container.AssertConfigurationIsValid(AssertMode.Full);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CallbackHandler.BusinessLogic.Tests.RequestHandler;
using CallbackHandlers.Models;
using CallbackMessageAggregate;
using MediatR;
using Moq;
using Imposter.Abstractions;
using Services;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
Expand All @@ -23,12 +23,10 @@ public class CallbackHandlerRequestHandlerTests
[Fact]
public void CallbackHandlerRequestHandlerTests_RecordCallbackRequest_IsHandled()
{
Mock<ICallbackDomainService> domainService = new();
domainService.Setup(a => a.RecordCallback(It.IsAny<CallbackCommands.RecordCallbackCommand>(),
It.IsAny<CancellationToken>()));
Mock<IAggregateRepository<CallbackMessageAggregate, DomainEvent>> aggregateRepository = new();
ICallbackDomainServiceImposter domainService = new();
IAggregateRepositoryImposter<CallbackMessageAggregate, DomainEvent> aggregateRepository = new();

CallbackHandlerRequestHandler handler = new(domainService.Object, aggregateRepository.Object);
CallbackHandlerRequestHandler handler = new(domainService.Instance(), aggregateRepository.Instance());

CallbackCommands.RecordCallbackCommand request = TestData.RecordCallbackCommand;

Expand All @@ -38,17 +36,15 @@ public void CallbackHandlerRequestHandlerTests_RecordCallbackRequest_IsHandled()
[Fact]
public void CallbackHandlerRequestHandlerTests_GetCallbackQuery_IsHandled()
{
Mock<ICallbackDomainService> domainService =
ICallbackDomainServiceImposter domainService =
new();
//domainService.Setup(a => a.RecordCallback(It.IsAny<CallbackCommands.RecordCallbackCommand>(),
// It.IsAny<CancellationToken>()));
Mock<IAggregateRepository<CallbackMessageAggregate, DomainEvent>> aggregateRepository =
IAggregateRepositoryImposter<CallbackMessageAggregate, DomainEvent> aggregateRepository =
new();

aggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
aggregateRepository.GetLatestVersion(Arg<Guid>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.RecordedCallbackMessageAggregate());

CallbackHandlerRequestHandler handler = new(domainService.Object, aggregateRepository.Object);
CallbackHandlerRequestHandler handler = new(domainService.Instance(), aggregateRepository.Instance());

CallbackQueries.GetCallbackQuery query = TestData.GetCallbackQuery;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Threading.Tasks;
using Shared.Logger;
using TransactionProcessor.Client;
using Imposter.Abstractions;

namespace CallbackHandler.BusinessLogic.Tests.Services;

Expand All @@ -16,7 +17,6 @@ namespace CallbackHandler.BusinessLogic.Tests.Services;
using CallbackHandlers.Models;
using CallbackMessageAggregate;
using Microsoft.Extensions.Configuration;
using Moq;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Shouldly;
Expand All @@ -27,21 +27,21 @@ public class CallbackDomainServiceTests
{
private readonly ICallbackDomainService DomainService;

private readonly Mock<IAggregateRepository<CallbackMessageAggregate, DomainEvent>> AggregateRepository;
private readonly Mock<ISecurityServiceClient> SecurityServiceClient;
private readonly Mock<ITransactionProcessorClient> TransactionProcessorClient;
private readonly IAggregateRepositoryImposter<CallbackMessageAggregate, DomainEvent> AggregateRepository;
private readonly ISecurityServiceClientImposter SecurityServiceClient;
private readonly ITransactionProcessorClientImposter TransactionProcessorClient;
public CallbackDomainServiceTests() {
this.AggregateRepository = new Mock<IAggregateRepository<CallbackMessageAggregate, DomainEvent>>();
this.SecurityServiceClient = new Mock<ISecurityServiceClient>();
this.TransactionProcessorClient = new Mock<ITransactionProcessorClient>();
this.DomainService = new CallbackDomainService(this.AggregateRepository.Object, this.SecurityServiceClient.Object,
this.TransactionProcessorClient.Object);
this.AggregateRepository.Setup(a => a.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>()))
this.AggregateRepository = new();
this.SecurityServiceClient = new();
this.TransactionProcessorClient = new();
this.DomainService = new CallbackDomainService(this.AggregateRepository.Instance(), this.SecurityServiceClient.Instance(),
this.TransactionProcessorClient.Instance());
this.AggregateRepository.GetLatestVersion(Arg<Guid>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.EmptyCallbackMessageAggregate());
this.AggregateRepository.Setup(a => a.SaveChanges(It.IsAny<CallbackMessageAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Success);
this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success(TestData.TokenResponse()));
this.TransactionProcessorClient.Setup(t => t.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Success());
this.AggregateRepository.SaveChanges(Arg<CallbackMessageAggregate>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Success());
this.SecurityServiceClient.GetToken(Arg<String>.Any(), Arg<String>.Any(), Arg<CancellationToken>.Any()).ReturnsAsync(Result.Success(TestData.TokenResponse()));
this.TransactionProcessorClient.GetMerchant(Arg<String>.Any(), Arg<Guid>.Any(), Arg<Guid>.Any(), Arg<CancellationToken>.Any()).ReturnsAsync(Result.Success());

IConfigurationRoot configurationRoot = new ConfigurationBuilder().AddInMemoryCollection(TestData.DefaultAppSettings).Build();
ConfigurationReader.Initialise(configurationRoot);
Expand Down Expand Up @@ -85,7 +85,7 @@ public async Task CallbackDomainService_RecordCallback_MerchantIdNotValidGuid_Re
[Fact]
public async Task CallbackDomainService_RecordCallback_GetTokenFailed_ResultFailed()
{
this.SecurityServiceClient.Setup(s => s.GetToken(It.IsAny<String>(), It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.SecurityServiceClient.GetToken(Arg<String>.Any(), Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Failure());
Result result = await this.DomainService.RecordCallback(TestData.RecordCallbackCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
Expand All @@ -94,7 +94,7 @@ public async Task CallbackDomainService_RecordCallback_GetTokenFailed_ResultFail
[Fact]
public async Task CallbackDomainService_RecordCallback_GetMerchantFailed_ResultFailed()
{
this.TransactionProcessorClient.Setup(t => t.GetMerchant(It.IsAny<String>(), It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(Result.Failure());
this.TransactionProcessorClient.GetMerchant(Arg<String>.Any(), Arg<Guid>.Any(), Arg<Guid>.Any(), Arg<CancellationToken>.Any()).ReturnsAsync(Result.Failure());

Result result = await this.DomainService.RecordCallback(TestData.RecordCallbackCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
Expand All @@ -103,8 +103,8 @@ public async Task CallbackDomainService_RecordCallback_GetMerchantFailed_ResultF
[Fact]
public async Task CallbackDomainService_RecordCallback_SaveFailed_ResultFailed()
{
this.AggregateRepository.Setup(a => a.SaveChanges(It.IsAny<CallbackMessageAggregate>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Result.Failure);
this.AggregateRepository.SaveChanges(Arg<CallbackMessageAggregate>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(Result.Failure());
Result result = await this.DomainService.RecordCallback(TestData.RecordCallbackCommand, CancellationToken.None);
result.IsFailed.ShouldBeTrue();
}
Expand Down
14 changes: 7 additions & 7 deletions CallbackHandler.Tests/BootstrapperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ namespace CallbackHandler.Tests
using System.Collections.Generic;
using System.Diagnostics;
using Lamar;
using Imposter.Abstractions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Moq;

[Collection("TestCollection")]
public class BootstrapperTests
{
[Fact]
public void VerifyBootstrapperIsValid()
{
Mock<IWebHostEnvironment> hostingEnvironment = new();
hostingEnvironment.Setup(he => he.EnvironmentName).Returns("Development");
hostingEnvironment.Setup(he => he.ContentRootPath).Returns("/home");
hostingEnvironment.Setup(he => he.ApplicationName).Returns("Test Application");
IWebHostEnvironmentImposter hostingEnvironment = new();
hostingEnvironment.EnvironmentName.Getter().Returns("Development");
hostingEnvironment.ContentRootPath.Getter().Returns("/home");
hostingEnvironment.ApplicationName.Getter().Returns("Test Application");

ServiceRegistry services = new();
Startup s = new(hostingEnvironment.Object);
Startup s = new(hostingEnvironment.Instance());
Startup.Configuration = this.SetupMemoryConfiguration();

this.AddTestRegistrations(services, hostingEnvironment.Object);
this.AddTestRegistrations(services, hostingEnvironment.Instance());
s.ConfigureContainer(services);
Startup.Container.AssertConfigurationIsValid(AssertMode.Full);
}
Expand Down
2 changes: 1 addition & 1 deletion CallbackHandler.Tests/CallbackHandler.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="Imposter" />
<PackageReference Include="xunit.v3.mtp-v2" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
4 changes: 4 additions & 0 deletions CallbackHandler.Tests/ImposterGeneration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using Imposter.Abstractions;
using Microsoft.AspNetCore.Hosting;

[assembly: GenerateImposter(typeof(IWebHostEnvironment))]
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.11" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Imposter" Version="0.1.9" />
<PackageVersion Include="xunit.v3.mtp-v2" Version="4.0.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="4.0.0" />
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
Expand Down Expand Up @@ -44,4 +44,4 @@
<PackageVersion Include="Shouldly" Version="4.3.0" />
<PackageVersion Include="xunit.v3.extensibility.core" Version="4.0.0" />
</ItemGroup>
</Project>
</Project>
Loading