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
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageVersion Include="Reqnroll.Tools.MsBuild.Generation" Version="3.3.4" />
<PackageVersion Include="NUnit" Version="4.6.1" />
<PackageVersion Include="Lamar" Version="16.0.0" />
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="Imposter" Version="0.1.9" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.12" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.11" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
Expand Down Expand Up @@ -59,4 +59,4 @@
<PackageVersion Include="SecurityService.IntegrationTesting.Helpers" Version="2026.8.1" />
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text;
using MediatR;

Expand All @@ -8,28 +8,28 @@ namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
using BusinessLogic.Services.EmailServices;
using EmailMessageAggregate;
using EventHandling;
using Moq;
using Imposter.Abstractions;
using System.Threading.Tasks;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;
using Testing;
using Xunit;

public class EmailDomainEventHandlerTests {
private Mock<IMediator> Mediator;
private Mock<IEmailServiceProxy> EmailServiceProxy;
private IMediatorImposter Mediator;
private IEmailServiceProxyImposter EmailServiceProxy;
private EmailDomainEventHandler EmailDomainEventHandler;
public EmailDomainEventHandlerTests() {
this.Mediator = new Mock<IMediator>();
this.EmailServiceProxy = new Mock<IEmailServiceProxy>();
this.Mediator = new IMediatorImposter();
this.EmailServiceProxy = new IEmailServiceProxyImposter();
this.EmailDomainEventHandler =
new EmailDomainEventHandler(this.Mediator.Object, this.EmailServiceProxy.Object);
new EmailDomainEventHandler(this.Mediator.Instance(), this.EmailServiceProxy.Instance());
}

[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Delivered_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseDelivered);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand All @@ -38,7 +38,7 @@ public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEve
[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Failed_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseFailed);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand All @@ -47,7 +47,7 @@ public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEve
[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Rejected_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseRejected);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand All @@ -56,7 +56,7 @@ public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEve
[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Bounced_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseBounced);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand All @@ -65,7 +65,7 @@ public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEve
[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Spam_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseSpam);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand All @@ -74,7 +74,7 @@ public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEve
[Fact]
public async Task EmailDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Unknown_EventIsHandled()
{
this.EmailServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
this.EmailServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<DateTime>.Any(), Arg<DateTime>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.MessageStatusResponseUnknown);

await this.EmailDomainEventHandler.Handle(TestData.ResponseReceivedFromEmailProviderEvent, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Text;

namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
Expand All @@ -7,7 +7,7 @@ namespace MessagingService.BusinessLogic.Tests.DomainEventHanders
using BusinessLogic.Services.EmailServices;
using EmailMessageAggregate;
using EventHandling;
using Moq;
using Imposter.Abstractions;
using System.Threading.Tasks;
using BusinessLogic.Services.SMSServices;
using Shared.DomainDrivenDesign.EventSourcing;
Expand All @@ -19,21 +19,21 @@ namespace MessagingService.BusinessLogic.Tests.DomainEventHanders

public class SMSDomainEventHandlerTests
{
private Mock<IMediator> Mediator;
private Mock<ISMSServiceProxy> SMSServiceProxy;
private IMediatorImposter Mediator;
private ISMSServiceProxyImposter SMSServiceProxy;
private SMSDomainEventHandler SMSDomainEventHandler;
public SMSDomainEventHandlerTests()
{
this.Mediator = new Mock<IMediator>();
this.SMSServiceProxy = new Mock<ISMSServiceProxy>();
this.Mediator = new IMediatorImposter();
this.SMSServiceProxy = new ISMSServiceProxyImposter();
this.SMSDomainEventHandler =
new SMSDomainEventHandler(this.Mediator.Object, this.SMSServiceProxy.Object);
new SMSDomainEventHandler(this.Mediator.Instance(), this.SMSServiceProxy.Instance());
}

[Fact]
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Delivered_EventIsHandled()
{
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.SMSServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.SMSMessageStatusResponseDelivered);

await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
Expand All @@ -42,7 +42,7 @@ public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent
[Fact]
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Expired_EventIsHandled()
{
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.SMSServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.SMSMessageStatusResponseExpired);

await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
Expand All @@ -51,7 +51,7 @@ public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent
[Fact]
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Rejected_EventIsHandled()
{
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.SMSServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.SMSMessageStatusResponseRejected);

await SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
Expand All @@ -60,7 +60,7 @@ public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent
[Fact]
public async Task SMSDomainEventHandler_Handle_ResponseReceivedFromProviderEvent_Undelivered_EventIsHandled()
{
this.SMSServiceProxy.Setup(e => e.GetMessageStatus(It.IsAny<String>(), It.IsAny<CancellationToken>()))
this.SMSServiceProxy.GetMessageStatus(Arg<String>.Any(), Arg<CancellationToken>.Any())
.ReturnsAsync(TestData.SMSMessageStatusResponseUndelivered);

await this.SMSDomainEventHandler.Handle(TestData.ResponseReceivedFromSMSProviderEvent, CancellationToken.None);
Expand Down
13 changes: 13 additions & 0 deletions MessagingService.BusinessLogic.Tests/ImposterDeclarations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Imposter.Abstractions;
using MediatR;
using Microsoft.AspNetCore.Hosting;
using MessagingService.BusinessLogic.Services.EmailServices;
using MessagingService.BusinessLogic.Services.SMSServices;
using Shared.DomainDrivenDesign.EventSourcing;
using Shared.EventStore.Aggregate;

[assembly: GenerateImposter(typeof(IAggregateRepository<,>))]
[assembly: GenerateImposter(typeof(IEmailServiceProxy))]
[assembly: GenerateImposter(typeof(ISMSServiceProxy))]
[assembly: GenerateImposter(typeof(IMediator))]
[assembly: GenerateImposter(typeof(IWebHostEnvironment))]
16 changes: 8 additions & 8 deletions MessagingService.BusinessLogic.Tests/Mediator/MediatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using MediatR;
using MediatR;
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 @@ -34,16 +34,16 @@ 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());
Startup.Configuration = this.SetupMemoryConfiguration();

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

<ItemGroup>
<PackageReference Include="Lamar" />
<PackageReference Include="Moq" />
<PackageReference Include="Imposter" />
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading
Loading