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
1 change: 1 addition & 0 deletions .github/workflows/createrelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "EstateManagement.BusinessLogic.Tests\EstateManagement.BusinessLogic.Tests.csproj"
dotnet test "EstateManagement.EstateAggregate.Tests\EstateManagement.EstateAggregate.Tests.csproj"
dotnet test "EstateManagement.MerchantAggregate.Tests\EstateManagement.MerchantAggregate.Tests.csproj"
dotnet test "EstateManagement.Tests\EstateManagement.Tests.csproj"

- name: Build Docker Images
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/nightlybuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "EstateManagement.BusinessLogic.Tests\EstateManagement.BusinessLogic.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov1.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "EstateManagement.EstateAggregate.Tests\EstateManagement.EstateAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov2.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "EstateManagement.Tests\EstateManagement.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov3.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "EstateManagement.MerchantAggregate.Tests\EstateManagement.MerchantAggregate.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov3.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"
dotnet test "EstateManagement.Tests\EstateManagement.Tests.csproj" /p:CollectCoverage=true /p:Exclude="[xunit*]*" /p:ExcludeByAttribute="Obsolete" /p:ExcludeByAttribute="GeneratedCodeAttribute" /p:ExcludeByAttribute="CompilerGeneratedAttribute" /p:ExcludeByAttribute="ExcludeFromCodeCoverageAttribute" /p:CoverletOutput="../lcov4.info" /maxcpucount:1 /p:CoverletOutputFormat="lcov"

- name: Setup Node.js for use with actions
uses: actions/setup-node@v1.1.0
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pullrequest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}"
dotnet test "EstateManagement.BusinessLogic.Tests\EstateManagement.BusinessLogic.Tests.csproj"
dotnet test "EstateManagement.EstateAggregate.Tests\EstateManagement.EstateAggregate.Tests.csproj"
dotnet test "EstateManagement.MerchantAggregate.Tests\EstateManagement.MerchantAggregate.Tests.csproj"
dotnet test "EstateManagement.Tests\EstateManagement.Tests.csproj"

- name: Build Docker Image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using BusinessLogic.Commands;
using BusinessLogic.Services;
using CommandHandlers;
using Commands;
using EstateAggregate;
using MerchantAggregate;
using Moq;
using Services;
using Shared.DomainDrivenDesign.CommandHandling;
using Shared.DomainDrivenDesign.EventStore;
using Shouldly;
Expand All @@ -21,15 +25,50 @@ public void CommandRouter_CreateEstateCommand_IsRouted()
Mock<IAggregateRepository<EstateAggregate>> estateAggregateRepository = new Mock<IAggregateRepository<EstateAggregate>>();
estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new EstateAggregate());
estateAggregateRepository.Setup(e => e.SaveChanges(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);
ICommandRouter router = new CommandRouter(estateAggregateRepository.Object);

Mock<IMerchantDomainService> merchantDomainService = new Mock<IMerchantDomainService>();
ICommandRouter router = new CommandRouter(estateAggregateRepository.Object, merchantDomainService.Object);

CreateEstateCommand command = TestData.CreateEstateCommand;

Should.NotThrow(async () =>
{
await router.Route(command, CancellationToken.None);
});

}

[Fact]
public void CommandRouter_CreateMerchantCommand_IsRouted()
{
Mock<IAggregateRepository<EstateAggregate>> estateAggregateRepository = new Mock<IAggregateRepository<EstateAggregate>>();
estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new EstateAggregate());
estateAggregateRepository.Setup(e => e.SaveChanges(It.IsAny<EstateAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

Mock<IMerchantDomainService> merchantDomainService = new Mock<IMerchantDomainService>();
merchantDomainService.Setup(e => e.CreateMerchant(It.IsAny<Guid>(), It.IsAny<Guid>(), It.IsAny<String>(), It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<Guid>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<String>(),
It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

ICommandRouter router = new CommandRouter(estateAggregateRepository.Object, merchantDomainService.Object);

CreateMerchantCommand command = TestData.CreateMerchantCommand;

Should.NotThrow(async () =>
{
await router.Route(command, CancellationToken.None);
});

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using BusinessLogic.Commands;
using CommandHandlers;
using Commands;
using EstateAggregate;
Expand All @@ -16,7 +17,7 @@
public class EstateCommandHandlerTests
{
[Fact]
public void CommandRouter_CreateEstateCommand_IsRouted()
public void EstateCommandHandler_CreateEstateCommand_IsHandled()
{
Mock<IAggregateRepository<EstateAggregate>> estateAggregateRepository = new Mock<IAggregateRepository<EstateAggregate>>();
estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new EstateAggregate());
Expand Down
54 changes: 54 additions & 0 deletions EstateManagement.BusinessLogic.Tests/Commands/CommandsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EstateManagement.BusinessLogic.Tests.Commands
{
using BusinessLogic.Commands;
using Shouldly;
using Testing;
using Xunit;

public class CommandsTests
{
[Fact]
public void CreateEstateCommand_CanBeCreated_IsCreated()
{
CreateEstateCommand createEstateCommand = CreateEstateCommand.Create(TestData.EstateId, TestData.EstateName);

createEstateCommand.ShouldNotBeNull();
createEstateCommand.CommandId.ShouldNotBe(Guid.Empty);
createEstateCommand.EstateId.ShouldBe(TestData.EstateId);
createEstateCommand.Name.ShouldBe(TestData.EstateName);
}

[Fact]
public void CreateMerchantCommand_CanBeCreated_IsCreated()
{
CreateMerchantCommand createMerchantCommand = CreateMerchantCommand.Create(TestData.EstateId,TestData.MerchantId,
TestData.MerchantName, TestData.MerchantAddressLine1,
TestData.MerchantAddressLine2, TestData.MerchantAddressLine3,
TestData.MerchantAddressLine4, TestData.MerchantTown,
TestData.MerchantRegion, TestData.MerchantPostalCode, TestData.MerchantCountry,
TestData.MerchantContactName, TestData.MerchantContactPhoneNumber,
TestData.MerchantContactEmailAddress);

createMerchantCommand.ShouldNotBeNull();
createMerchantCommand.CommandId.ShouldNotBe(Guid.Empty);
createMerchantCommand.EstateId.ShouldBe(TestData.EstateId);
createMerchantCommand.MerchantId.ShouldBe(TestData.MerchantId);
createMerchantCommand.Name.ShouldBe(TestData.MerchantName);
createMerchantCommand.AddressLine1.ShouldBe(TestData.MerchantAddressLine1);
createMerchantCommand.AddressLine2.ShouldBe(TestData.MerchantAddressLine2);
createMerchantCommand.AddressLine3.ShouldBe(TestData.MerchantAddressLine3);
createMerchantCommand.AddressLine4.ShouldBe(TestData.MerchantAddressLine4);
createMerchantCommand.Town.ShouldBe(TestData.MerchantTown);
createMerchantCommand.Region.ShouldBe(TestData.MerchantRegion);
createMerchantCommand.PostalCode.ShouldBe(TestData.MerchantPostalCode);
createMerchantCommand.Country.ShouldBe(TestData.MerchantCountry);
createMerchantCommand.ContactName.ShouldBe(TestData.MerchantContactName);
createMerchantCommand.ContactPhoneNumber.ShouldBe(TestData.MerchantContactPhoneNumber);
createMerchantCommand.ContactEmailAddress.ShouldBe(TestData.MerchantContactEmailAddress);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace EstateManagement.BusinessLogic.Tests.Services
{
using System.Threading;
using System.Threading.Tasks;
using BusinessLogic.Services;
using EstateAggregate;
using MerchantAggregate;
using Moq;
using Shared.DomainDrivenDesign.EventStore;
using Shouldly;
using Testing;
using Xunit;

public class MerchantDomainServiceTests
{
[Fact]
public async Task MerchantDomainService_CreateMerchant_MerchantIsCreated()
{
Mock<IAggregateRepository<MerchantAggregate>> merchantAggregateRepository = new Mock<IAggregateRepository<MerchantAggregate>>();
Mock<IAggregateRepository<EstateAggregate>> estateAggregateRepository = new Mock<IAggregateRepository<EstateAggregate>>();

merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new MerchantAggregate());
merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny<MerchantAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.CreatedEstateAggregate);
MerchantDomainService domainService = new MerchantDomainService(merchantAggregateRepository.Object, estateAggregateRepository.Object);

Should.NotThrow( async () =>
{
await domainService.CreateMerchant(TestData.EstateId,
TestData.MerchantId,
TestData.MerchantName,
TestData.MerchantAddressId,
TestData.MerchantAddressLine1,
TestData.MerchantAddressLine2,
TestData.MerchantAddressLine3,
TestData.MerchantAddressLine4,
TestData.MerchantTown,
TestData.MerchantRegion,
TestData.MerchantPostalCode,
TestData.MerchantCountry,
TestData.MerchantContactId,
TestData.MerchantContactName,
TestData.MerchantContactPhoneNumber,
TestData.MerchantContactEmailAddress,
CancellationToken.None);
});
}

[Fact]
public void MerchantDomainService_CreateMerchant_EstateNotFound_ErrorThrown()
{
Mock<IAggregateRepository<MerchantAggregate>> merchantAggregateRepository = new Mock<IAggregateRepository<MerchantAggregate>>();
Mock<IAggregateRepository<EstateAggregate>> estateAggregateRepository = new Mock<IAggregateRepository<EstateAggregate>>();

merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(new MerchantAggregate());
merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny<MerchantAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

estateAggregateRepository.Setup(e => e.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.EmptyEstateAggregate);
MerchantDomainService domainService = new MerchantDomainService(merchantAggregateRepository.Object, estateAggregateRepository.Object);

Should.Throw<InvalidOperationException>(async () =>
{
await domainService.CreateMerchant(TestData.EstateId,
TestData.MerchantId,
TestData.MerchantName,
TestData.MerchantAddressId,
TestData.MerchantAddressLine1,
TestData.MerchantAddressLine2,
TestData.MerchantAddressLine3,
TestData.MerchantAddressLine4,
TestData.MerchantTown,
TestData.MerchantRegion,
TestData.MerchantPostalCode,
TestData.MerchantCountry,
TestData.MerchantContactId,
TestData.MerchantContactName,
TestData.MerchantContactPhoneNumber,
TestData.MerchantContactEmailAddress,
CancellationToken.None);
});
}
}
}
35 changes: 33 additions & 2 deletions EstateManagement.BusinessLogic/CommandHandlers/CommandRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Commands;
using EstateAggregate;
using Services;
using Shared.DomainDrivenDesign.CommandHandling;
using Shared.DomainDrivenDesign.EventStore;

Expand All @@ -13,20 +14,38 @@
/// <seealso cref="Shared.DomainDrivenDesign.CommandHandling.ICommandRouter" />
public class CommandRouter : ICommandRouter
{
#region Fields

/// <summary>
/// The estate aggregate repository
/// </summary>
private readonly IAggregateRepository<EstateAggregate> EstateAggregateRepository;

/// <summary>
/// The merchant domain service
/// </summary>
private readonly IMerchantDomainService MerchantDomainService;

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="CommandRouter" /> class.
/// </summary>
/// <param name="estateAggregateRepository">The estate aggregate repository.</param>
public CommandRouter(IAggregateRepository<EstateAggregate> estateAggregateRepository)
/// <param name="merchantDomainService">The merchant domain service.</param>
public CommandRouter(IAggregateRepository<EstateAggregate> estateAggregateRepository,
IMerchantDomainService merchantDomainService)
{
this.EstateAggregateRepository = estateAggregateRepository;
this.MerchantDomainService = merchantDomainService;
}

#endregion

#region Methods

/// <summary>
/// Routes the specified command.
/// </summary>
Expand All @@ -49,5 +68,17 @@ private ICommandHandler CreateHandler(CreateEstateCommand command)
{
return new EstateCommandHandler(this.EstateAggregateRepository);
}

/// <summary>
/// Creates the handler.
/// </summary>
/// <param name="command">The command.</param>
/// <returns></returns>
private ICommandHandler CreateHandler(CreateMerchantCommand command)
{
return new MerchantCommandHandler(this.MerchantDomainService);
}

#endregion
}
}
}
Loading