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 @@ -11,7 +11,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="Shared.EventStore" Version="0.0.5.1" />
<PackageReference Include="Shouldly" Version="3.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,20 @@ public void MerchantRequestHandler_AssignOperatorToMerchantRequest_IsHandled()
});

}

[Fact]
public void MerchantRequestHandler_CreateMerchantUserRequest_IsHandled()
{
Mock<IMerchantDomainService> merchantDomainService = new Mock<IMerchantDomainService>();
MerchantRequestHandler handler = new MerchantRequestHandler(merchantDomainService.Object);

CreateMerchantUserRequest request = TestData.CreateMerchantUserRequest;

Should.NotThrow(async () =>
{
await handler.Handle(request, CancellationToken.None);
});

}
}
}
22 changes: 22 additions & 0 deletions EstateManagement.BusinessLogic.Tests/Requests/RequestsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,27 @@ public void CreateEstateUserRequest_CanBeCreated_IsCreated()
createEstateUserRequest.FamilyName.ShouldBe(TestData.EstateUserFamilyName);

}

[Fact]
public void CreateMerchantUserRequest_CanBeCreated_IsCreated()
{
CreateMerchantUserRequest createMerchantUserRequest = CreateMerchantUserRequest.Create(TestData.EstateId,
TestData.MerchantId,
TestData.EstateUserEmailAddress,
TestData.EstateUserPassword,
TestData.EstateUserGivenName,
TestData.EstateUserMiddleName,
TestData.EstateUserFamilyName);

createMerchantUserRequest.ShouldNotBeNull();
createMerchantUserRequest.EstateId.ShouldBe(TestData.EstateId);
createMerchantUserRequest.MerchantId.ShouldBe(TestData.MerchantId);
createMerchantUserRequest.EmailAddress.ShouldBe(TestData.EstateUserEmailAddress);
createMerchantUserRequest.Password.ShouldBe(TestData.EstateUserPassword);
createMerchantUserRequest.GivenName.ShouldBe(TestData.EstateUserGivenName);
createMerchantUserRequest.MiddleName.ShouldBe(TestData.EstateUserMiddleName);
createMerchantUserRequest.FamilyName.ShouldBe(TestData.EstateUserFamilyName);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace EstateManagement.BusinessLogic.Tests.Services
using EstateAggregate;
using MerchantAggregate;
using Moq;
using SecurityService.Client;
using SecurityService.DataTransferObjects;
using Shared.DomainDrivenDesign.EventStore;
using Shared.EventStore.EventStore;
using Shouldly;
Expand All @@ -32,7 +34,9 @@ public async Task MerchantDomainService_CreateMerchant_MerchantIsCreated()
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.NotThrow( async () =>
{
Expand Down Expand Up @@ -70,7 +74,10 @@ public void MerchantDomainService_CreateMerchant_EstateNotFound_ErrorThrown()
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new
MerchantDomainService(aggregateRepositoryManager.Object,securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand Down Expand Up @@ -108,7 +115,9 @@ public async Task MerchantDomainService_AssignOperatorToMerchant_OperatorAssigne
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

await domainService.AssignOperatorToMerchant(TestData.EstateId,
TestData.MerchantId,
Expand All @@ -132,7 +141,9 @@ public void MerchantDomainService_AssignOperatorToMerchant_MerchantNotCreated_Er
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand All @@ -159,7 +170,9 @@ public void MerchantDomainService_AssignOperatorToMerchant_EstateNotCreated_Erro
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand All @@ -186,7 +199,9 @@ public void MerchantDomainService_AssignOperatorToMerchant_OperatorNotFoundForEs
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand Down Expand Up @@ -215,7 +230,9 @@ public void MerchantDomainService_AssignOperatorToMerchant_OperatorRequiresMerch
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand Down Expand Up @@ -244,7 +261,9 @@ public void MerchantDomainService_AssignOperatorToMerchant_OperatorRequiresTermi
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<EstateAggregate>(It.IsAny<Guid>())).Returns(estateAggregateRepository.Object);
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object);
Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.Throw<InvalidOperationException>(async () =>
{
Expand All @@ -256,5 +275,36 @@ await domainService.AssignOperatorToMerchant(TestData.EstateId,
CancellationToken.None);
});
}

[Fact]
public async Task MerchantDomainService_CreateMerchantUser_MerchantUserIsCreated()
{
Mock<IAggregateRepository<MerchantAggregate>> merchantAggregateRepository = new Mock<IAggregateRepository<MerchantAggregate>>();
merchantAggregateRepository.Setup(m => m.GetLatestVersion(It.IsAny<Guid>(), It.IsAny<CancellationToken>())).ReturnsAsync(TestData.CreatedMerchantAggregate);
merchantAggregateRepository.Setup(m => m.SaveChanges(It.IsAny<MerchantAggregate>(), It.IsAny<CancellationToken>())).Returns(Task.CompletedTask);

Mock<IAggregateRepositoryManager> aggregateRepositoryManager = new Mock<IAggregateRepositoryManager>();
aggregateRepositoryManager.Setup(x => x.GetAggregateRepository<MerchantAggregate>(It.IsAny<Guid>())).Returns(merchantAggregateRepository.Object);

Mock<ISecurityServiceClient> securityServiceClient = new Mock<ISecurityServiceClient>();
securityServiceClient.Setup(s => s.CreateUser(It.IsAny<CreateUserRequest>(), It.IsAny<CancellationToken>())).ReturnsAsync(new CreateUserResponse
{
UserId = Guid.NewGuid()
});

MerchantDomainService domainService = new MerchantDomainService(aggregateRepositoryManager.Object, securityServiceClient.Object);

Should.NotThrow(async () =>
{
await domainService.CreateMerchantUser(TestData.EstateId,
TestData.MerchantId,
TestData.MerchantUserEmailAddress,
TestData.MerchantUserPassword,
TestData.MerchantUserGivenName,
TestData.MerchantUserMiddleName,
TestData.MerchantUserFamilyName,
CancellationToken.None);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
/// </summary>
/// <seealso cref="MediatR.IRequestHandler{EstateManagement.BusinessLogic.Requests.CreateMerchantRequest, System.String}" />
/// <seealso cref="MediatR.IRequestHandler{EstateManagement.BusinessLogic.Requests.AssignOperatorToMerchantRequest, System.String}" />
public class MerchantRequestHandler : IRequestHandler<CreateMerchantRequest, String>, IRequestHandler<AssignOperatorToMerchantRequest, String>
public class MerchantRequestHandler : IRequestHandler<CreateMerchantRequest, String>,
IRequestHandler<AssignOperatorToMerchantRequest, String>,
IRequestHandler<CreateMerchantUserRequest, Guid>
{
#region Fields

Expand Down Expand Up @@ -88,5 +90,20 @@ await this.MerchantDomainService.AssignOperatorToMerchant(request.EstateId,
}

#endregion

public async Task<Guid> Handle(CreateMerchantUserRequest request,
CancellationToken cancellationToken)
{
Guid userId = await this.MerchantDomainService.CreateMerchantUser(request.EstateId,
request.MerchantId,
request.EmailAddress,
request.Password,
request.GivenName,
request.MiddleName,
request.FamilyName,
cancellationToken);

return userId;
}
}
}
125 changes: 125 additions & 0 deletions EstateManagement.BusinessLogic/Requests/CreateMerchantUserRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
namespace EstateManagement.BusinessLogic.Requests
{
using System;
using MediatR;

public class CreateMerchantUserRequest : IRequest<Guid>
{
#region Constructors

/// <summary>
/// Initializes a new instance of the <see cref="CreateEstateUserRequest" /> class.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="emailAddress">The email address.</param>
/// <param name="password">The password.</param>
/// <param name="givenName">Name of the given.</param>
/// <param name="middleName">Name of the middle.</param>
/// <param name="familyName">Name of the family.</param>
private CreateMerchantUserRequest(Guid estateId,
Guid merchantId,
String emailAddress,
String password,
String givenName,
String middleName,
String familyName)
{
this.EstateId = estateId;
this.MerchantId = merchantId;
this.EmailAddress = emailAddress;
this.Password = password;
this.GivenName = givenName;
this.MiddleName = middleName;
this.FamilyName = familyName;
}

#endregion

#region Properties

/// <summary>
/// Gets the estate identifier.
/// </summary>
/// <value>
/// The estate identifier.
/// </value>
public Guid EstateId { get; }

/// <summary>
/// Gets the merchant identifier.
/// </summary>
/// <value>
/// The merchant identifier.
/// </value>
public Guid MerchantId { get; }

/// <summary>
/// Gets the email address.
/// </summary>
/// <value>
/// The email address.
/// </value>
public String EmailAddress { get; }

/// <summary>
/// Gets or sets the name of the family.
/// </summary>
/// <value>
/// The name of the family.
/// </value>
public String FamilyName { get; }

/// <summary>
/// Gets or sets the name of the given.
/// </summary>
/// <value>
/// The name of the given.
/// </value>
public String GivenName { get; }

/// <summary>
/// Gets or sets the name of the middle.
/// </summary>
/// <value>
/// The name of the middle.
/// </value>
public String MiddleName { get; }

/// <summary>
/// Gets or sets the password.
/// </summary>
/// <value>
/// The password.
/// </value>
public String Password { get; }

#endregion

#region Methods

/// <summary>
/// Creates the specified email address.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="merchantId">The merchant identifier.</param>
/// <param name="emailAddress">The email address.</param>
/// <param name="password">The password.</param>
/// <param name="givenName">Name of the given.</param>
/// <param name="middleName">Name of the middle.</param>
/// <param name="familyName">Name of the family.</param>
/// <returns></returns>
public static CreateMerchantUserRequest Create(Guid estateId,
Guid merchantId,
String emailAddress,
String password,
String givenName,
String middleName,
String familyName)
{
return new CreateMerchantUserRequest(estateId, merchantId, emailAddress, password, givenName, middleName, familyName);
}

#endregion
}
}
Loading