From 2800ac3df38d65a5eb075f0cf65f7c70dc565d87 Mon Sep 17 00:00:00 2001 From: Thomas Jespersen Date: Sun, 12 Nov 2023 11:37:34 +0100 Subject: [PATCH] Remove static "parent" classes from commands and queries, use files as containers instead --- .../Api/Tenants/TenantEndpoints.cs | 8 +- .../Api/Users/UserEndpoints.cs | 10 +-- .../Application/Tenants/CreateTenant.cs | 87 +++++++++---------- .../Application/Tenants/DeleteTenant.cs | 52 +++++------ .../Application/Tenants/GetTenant.cs | 29 +++---- .../Application/Tenants/UpdateTenant.cs | 56 ++++++------ .../Application/Users/CreateUser.cs | 63 +++++++------- .../Application/Users/DeleteUser.cs | 34 +++----- .../Application/Users/GetUser.cs | 29 +++---- .../Application/Users/UpdateUser.cs | 56 ++++++------ .../Tests/Api/Tenants/TenantEndpointsTests.cs | 14 +-- .../Tests/Api/Users/UserEndpointsTests.cs | 14 +-- .../Tenants/CreateTenantValidationTests.cs | 4 +- .../Tenants/TenantCreatedEventHandlerTests.cs | 2 +- 14 files changed, 211 insertions(+), 247 deletions(-) diff --git a/application/account-management/Api/Tenants/TenantEndpoints.cs b/application/account-management/Api/Tenants/TenantEndpoints.cs index 207996b87..bf09a0974 100644 --- a/application/account-management/Api/Tenants/TenantEndpoints.cs +++ b/application/account-management/Api/Tenants/TenantEndpoints.cs @@ -12,15 +12,15 @@ public static void MapTenantEndpoints(this IEndpointRouteBuilder routes) var group = routes.MapGroup(RoutesPrefix); group.MapGet("/{id}", async Task> (TenantId id, ISender mediator) - => await mediator.Send(new GetTenant.Query(id))); + => await mediator.Send(new GetTenantQuery(id))); - group.MapPost("/", async Task (CreateTenant.Command command, ISender mediator) + group.MapPost("/", async Task (CreateTenantCommand command, ISender mediator) => (await mediator.Send(command)).AddResourceUri(RoutesPrefix)); - group.MapPut("/{id}", async Task (TenantId id, UpdateTenant.Command command, ISender mediator) + group.MapPut("/{id}", async Task (TenantId id, UpdateTenantCommand command, ISender mediator) => await mediator.Send(command with {Id = id})); group.MapDelete("/{id}", async Task (TenantId id, ISender mediator) - => await mediator.Send(new DeleteTenant.Command(id))); + => await mediator.Send(new DeleteTenantCommand(id))); } } \ No newline at end of file diff --git a/application/account-management/Api/Users/UserEndpoints.cs b/application/account-management/Api/Users/UserEndpoints.cs index a0a60016b..023a3d716 100644 --- a/application/account-management/Api/Users/UserEndpoints.cs +++ b/application/account-management/Api/Users/UserEndpoints.cs @@ -12,15 +12,15 @@ public static void MapUserEndpoints(this IEndpointRouteBuilder routes) var group = routes.MapGroup(RoutesPrefix); group.MapGet("/{id}", async Task> (UserId id, ISender mediator) - => await mediator.Send(new GetUser.Query(id))); + => await mediator.Send(new GetUserQuery(id))); - group.MapPost("/", async Task (CreateUser.Command command, ISender mediator) + group.MapPost("/", async Task (CreateUserCommand command, ISender mediator) => (await mediator.Send(command)).AddResourceUri(RoutesPrefix)); - group.MapPut("/{id}", async Task (UserId id, UpdateUser.Command command, ISender mediator) - => await mediator.Send(command with {Id = id})); + group.MapPut("/{id}", async Task (UserId id, UpdateUserCommand command, ISender mediator) + => await mediator.Send(command with { Id = id })); group.MapDelete("/{id}", async Task (UserId id, ISender mediator) - => await mediator.Send(new DeleteUser.Command(id))); + => await mediator.Send(new DeleteUserCommand(id))); } } \ No newline at end of file diff --git a/application/account-management/Application/Tenants/CreateTenant.cs b/application/account-management/Application/Tenants/CreateTenant.cs index 3ee958c0a..b0800f59f 100644 --- a/application/account-management/Application/Tenants/CreateTenant.cs +++ b/application/account-management/Application/Tenants/CreateTenant.cs @@ -5,56 +5,53 @@ namespace PlatformPlatform.AccountManagement.Application.Tenants; -public static class CreateTenant +public sealed record CreateTenantCommand(string Subdomain, string Name, string? Phone, string Email) + : ICommand, ITenantValidation, IRequest>; + +[UsedImplicitly] +public sealed class CreateTenantHandler : IRequestHandler> { - public sealed record Command(string Subdomain, string Name, string? Phone, string Email) - : ICommand, ITenantValidation, IRequest>; + private readonly ISender _mediator; + private readonly ITenantRepository _tenantRepository; + + public CreateTenantHandler(ITenantRepository tenantRepository, ISender mediator) + { + _tenantRepository = tenantRepository; + _mediator = mediator; + } + + public async Task> Handle(CreateTenantCommand command, CancellationToken cancellationToken) + { + var tenant = Tenant.Create(command.Subdomain, command.Name, command.Phone); + await _tenantRepository.AddAsync(tenant, cancellationToken); + + await CreateTenantOwnerAsync(tenant.Id, command.Email, cancellationToken); + return tenant.Id; + } - [UsedImplicitly] - public sealed class Handler : IRequestHandler> + private async Task CreateTenantOwnerAsync(TenantId tenantId, string tenantOwnerEmail, + CancellationToken cancellationToken) { - private readonly ISender _mediator; - private readonly ITenantRepository _tenantRepository; - - public Handler(ITenantRepository tenantRepository, ISender mediator) - { - _tenantRepository = tenantRepository; - _mediator = mediator; - } - - public async Task> Handle(Command command, CancellationToken cancellationToken) - { - var tenant = Tenant.Create(command.Subdomain, command.Name, command.Phone); - await _tenantRepository.AddAsync(tenant, cancellationToken); - - await CreateTenantOwnerAsync(tenant.Id, command.Email, cancellationToken); - return tenant.Id; - } - - private async Task CreateTenantOwnerAsync(TenantId tenantId, string tenantOwnerEmail, - CancellationToken cancellationToken) - { - var createTenantOwnerUserCommand = new CreateUser.Command(tenantId, tenantOwnerEmail, UserRole.TenantOwner); - var result = await _mediator.Send(createTenantOwnerUserCommand, cancellationToken); - - if (!result.IsSuccess) throw new UnreachableException($"Create Tenant Owner: {result.GetErrorSummary()}"); - } + var createTenantOwnerUserCommand = new CreateUserCommand(tenantId, tenantOwnerEmail, UserRole.TenantOwner); + var result = await _mediator.Send(createTenantOwnerUserCommand, cancellationToken); + + if (!result.IsSuccess) throw new UnreachableException($"Create Tenant Owner: {result.GetErrorSummary()}"); } +} - [UsedImplicitly] - public sealed class Validator : TenantValidator +[UsedImplicitly] +public sealed class CreateTenantValidator : TenantValidator +{ + public CreateTenantValidator(ITenantRepository tenantRepository) { - public Validator(ITenantRepository tenantRepository) - { - RuleFor(x => x.Email).NotEmpty().SetValidator(new SharedValidations.Email()); - RuleFor(x => x.Subdomain).NotEmpty(); - RuleFor(x => x.Subdomain) - .Matches("^[a-z0-9]{3,30}$") - .WithMessage("Subdomain must be between 3-30 alphanumeric and lowercase characters.") - .MustAsync(async (subdomain, cancellationToken) => - await tenantRepository.IsSubdomainFreeAsync(subdomain, cancellationToken)) - .WithMessage("The subdomain is not available.") - .When(x => !string.IsNullOrEmpty(x.Subdomain)); - } + RuleFor(x => x.Email).NotEmpty().SetValidator(new SharedValidations.Email()); + RuleFor(x => x.Subdomain).NotEmpty(); + RuleFor(x => x.Subdomain) + .Matches("^[a-z0-9]{3,30}$") + .WithMessage("Subdomain must be between 3-30 alphanumeric and lowercase characters.") + .MustAsync(async (subdomain, cancellationToken) => + await tenantRepository.IsSubdomainFreeAsync(subdomain, cancellationToken)) + .WithMessage("The subdomain is not available.") + .When(x => !string.IsNullOrEmpty(x.Subdomain)); } } \ No newline at end of file diff --git a/application/account-management/Application/Tenants/DeleteTenant.cs b/application/account-management/Application/Tenants/DeleteTenant.cs index 3b7494d67..4edfdcd9f 100644 --- a/application/account-management/Application/Tenants/DeleteTenant.cs +++ b/application/account-management/Application/Tenants/DeleteTenant.cs @@ -3,42 +3,36 @@ namespace PlatformPlatform.AccountManagement.Application.Tenants; -public static class DeleteTenant +public sealed record DeleteTenantCommand(TenantId Id) : ICommand, IRequest; + +[UsedImplicitly] +public sealed class DeleteTenantHandler : IRequestHandler { - public sealed record Command(TenantId Id) : ICommand, IRequest; + private readonly ITenantRepository _tenantRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler + public DeleteTenantHandler(ITenantRepository tenantRepository) { - private readonly ITenantRepository _tenantRepository; - - public Handler(ITenantRepository tenantRepository) - { - _tenantRepository = tenantRepository; - } + _tenantRepository = tenantRepository; + } - public async Task Handle(Command command, CancellationToken cancellationToken) - { - var tenant = await _tenantRepository.GetByIdAsync(command.Id, cancellationToken); - if (tenant is null) - { - return Result.NotFound($"Tenant with id '{command.Id}' not found."); - } + public async Task Handle(DeleteTenantCommand command, CancellationToken cancellationToken) + { + var tenant = await _tenantRepository.GetByIdAsync(command.Id, cancellationToken); + if (tenant is null) return Result.NotFound($"Tenant with id '{command.Id}' not found."); - _tenantRepository.Remove(tenant); - return Result.Success(); - } + _tenantRepository.Remove(tenant); + return Result.Success(); } +} - [UsedImplicitly] - public sealed class Validator : AbstractValidator +[UsedImplicitly] +public sealed class DeleteTenantValidator : AbstractValidator +{ + public DeleteTenantValidator(IUserRepository userRepository) { - public Validator(IUserRepository userRepository) - { - RuleFor(x => x.Id) - .MustAsync(async (tenantId, cancellationToken) => - await userRepository.CountTenantUsersAsync(tenantId, cancellationToken) == 0) - .WithMessage("All users must be deleted before the tenant can be deleted."); - } + RuleFor(x => x.Id) + .MustAsync(async (tenantId, cancellationToken) => + await userRepository.CountTenantUsersAsync(tenantId, cancellationToken) == 0) + .WithMessage("All users must be deleted before the tenant can be deleted."); } } \ No newline at end of file diff --git a/application/account-management/Application/Tenants/GetTenant.cs b/application/account-management/Application/Tenants/GetTenant.cs index 6e4dd47bc..38b50662d 100644 --- a/application/account-management/Application/Tenants/GetTenant.cs +++ b/application/account-management/Application/Tenants/GetTenant.cs @@ -3,25 +3,22 @@ namespace PlatformPlatform.AccountManagement.Application.Tenants; -public static class GetTenant +public sealed record GetTenantQuery(TenantId Id) : IRequest>; + +[UsedImplicitly] +public sealed class GetTenantHandler : IRequestHandler> { - public sealed record Query(TenantId Id) : IRequest>; + private readonly ITenantRepository _tenantRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler> + public GetTenantHandler(ITenantRepository tenantRepository) { - private readonly ITenantRepository _tenantRepository; - - public Handler(ITenantRepository tenantRepository) - { - _tenantRepository = tenantRepository; - } + _tenantRepository = tenantRepository; + } - public async Task> Handle(Query request, CancellationToken cancellationToken) - { - var tenant = await _tenantRepository.GetByIdAsync(request.Id, cancellationToken); - return tenant?.Adapt() - ?? Result.NotFound($"Tenant with id '{request.Id}' not found."); - } + public async Task> Handle(GetTenantQuery request, CancellationToken cancellationToken) + { + var tenant = await _tenantRepository.GetByIdAsync(request.Id, cancellationToken); + return tenant?.Adapt() + ?? Result.NotFound($"Tenant with id '{request.Id}' not found."); } } \ No newline at end of file diff --git a/application/account-management/Application/Tenants/UpdateTenant.cs b/application/account-management/Application/Tenants/UpdateTenant.cs index 811e0869d..2ee53b2ae 100644 --- a/application/account-management/Application/Tenants/UpdateTenant.cs +++ b/application/account-management/Application/Tenants/UpdateTenant.cs @@ -2,44 +2,38 @@ namespace PlatformPlatform.AccountManagement.Application.Tenants; -public static class UpdateTenant +public sealed record UpdateTenantCommand : ICommand, ITenantValidation, IRequest { - public sealed record Command : ICommand, ITenantValidation, IRequest - { - [JsonIgnore] // Removes the Id from the API contract - public TenantId Id { get; init; } = null!; + [JsonIgnore] // Removes the Id from the API contract + public TenantId Id { get; init; } = null!; - public required string Name { get; init; } + public required string Name { get; init; } - public string? Phone { get; init; } - } + public string? Phone { get; init; } +} + +[UsedImplicitly] +public sealed class UpdateTenantHandler : IRequestHandler +{ + private readonly ITenantRepository _tenantRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler + public UpdateTenantHandler(ITenantRepository tenantRepository) { - private readonly ITenantRepository _tenantRepository; - - public Handler(ITenantRepository tenantRepository) - { - _tenantRepository = tenantRepository; - } - - public async Task Handle(Command command, CancellationToken cancellationToken) - { - var tenant = await _tenantRepository.GetByIdAsync(command.Id, cancellationToken); - if (tenant is null) - { - return Result.NotFound($"Tenant with id '{command.Id}' not found."); - } - - tenant.Update(command.Name, command.Phone); - _tenantRepository.Update(tenant); - return Result.Success(); - } + _tenantRepository = tenantRepository; } - [UsedImplicitly] - public sealed class Validator : TenantValidator + public async Task Handle(UpdateTenantCommand command, CancellationToken cancellationToken) { + var tenant = await _tenantRepository.GetByIdAsync(command.Id, cancellationToken); + if (tenant is null) return Result.NotFound($"Tenant with id '{command.Id}' not found."); + + tenant.Update(command.Name, command.Phone); + _tenantRepository.Update(tenant); + return Result.Success(); } +} + +[UsedImplicitly] +public sealed class UpdateTenantValidator : TenantValidator +{ } \ No newline at end of file diff --git a/application/account-management/Application/Users/CreateUser.cs b/application/account-management/Application/Users/CreateUser.cs index 693ba2e7d..1c822209f 100644 --- a/application/account-management/Application/Users/CreateUser.cs +++ b/application/account-management/Application/Users/CreateUser.cs @@ -3,46 +3,43 @@ namespace PlatformPlatform.AccountManagement.Application.Users; -public static class CreateUser +public sealed record CreateUserCommand(TenantId TenantId, string Email, UserRole UserRole) + : ICommand, IUserValidation, IRequest>; + +[UsedImplicitly] +public sealed class CreateUserHandler : IRequestHandler> { - public sealed record Command(TenantId TenantId, string Email, UserRole UserRole) - : ICommand, IUserValidation, IRequest>; + private readonly IUserRepository _userRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler> + public CreateUserHandler(IUserRepository userRepository) { - private readonly IUserRepository _userRepository; - - public Handler(IUserRepository userRepository) - { - _userRepository = userRepository; - } + _userRepository = userRepository; + } - public async Task> Handle(Command command, CancellationToken cancellationToken) - { - var user = User.Create(command.TenantId, command.Email, command.UserRole); - await _userRepository.AddAsync(user, cancellationToken); - return user.Id; - } + public async Task> Handle(CreateUserCommand command, CancellationToken cancellationToken) + { + var user = User.Create(command.TenantId, command.Email, command.UserRole); + await _userRepository.AddAsync(user, cancellationToken); + return user.Id; } +} - [UsedImplicitly] - public sealed class Validator : UserValidator +[UsedImplicitly] +public sealed class CreateUserValidator : UserValidator +{ + public CreateUserValidator(IUserRepository userRepository, ITenantRepository tenantRepository) { - public Validator(IUserRepository userRepository, ITenantRepository tenantRepository) - { - RuleFor(x => x.TenantId) - .MustAsync(async (tenantId, cancellationToken) => - await tenantRepository.ExistsAsync(tenantId, cancellationToken)) - .WithMessage(x => $"The tenant '{x.TenantId}' does not exist.") - .When(x => !string.IsNullOrEmpty(x.Email)); + RuleFor(x => x.TenantId) + .MustAsync(async (tenantId, cancellationToken) => + await tenantRepository.ExistsAsync(tenantId, cancellationToken)) + .WithMessage(x => $"The tenant '{x.TenantId}' does not exist.") + .When(x => !string.IsNullOrEmpty(x.Email)); - RuleFor(x => x) - .MustAsync(async (x, cancellationToken) - => await userRepository.IsEmailFreeAsync(x.TenantId, x.Email, cancellationToken)) - .WithName("Email") - .WithMessage(x => $"The email '{x.Email}' is already in use by another user on this tenant.") - .When(x => !string.IsNullOrEmpty(x.Email)); - } + RuleFor(x => x) + .MustAsync(async (x, cancellationToken) + => await userRepository.IsEmailFreeAsync(x.TenantId, x.Email, cancellationToken)) + .WithName("Email") + .WithMessage(x => $"The email '{x.Email}' is already in use by another user on this tenant.") + .When(x => !string.IsNullOrEmpty(x.Email)); } } \ No newline at end of file diff --git a/application/account-management/Application/Users/DeleteUser.cs b/application/account-management/Application/Users/DeleteUser.cs index 3ff427610..14b29c55d 100644 --- a/application/account-management/Application/Users/DeleteUser.cs +++ b/application/account-management/Application/Users/DeleteUser.cs @@ -2,30 +2,24 @@ namespace PlatformPlatform.AccountManagement.Application.Users; -public static class DeleteUser +public sealed record DeleteUserCommand(UserId Id) : ICommand, IRequest; + +[UsedImplicitly] +public sealed class DeleteUserHandler : IRequestHandler { - public sealed record Command(UserId Id) : ICommand, IRequest; + private readonly IUserRepository _userRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler + public DeleteUserHandler(IUserRepository userRepository) { - private readonly IUserRepository _userRepository; - - public Handler(IUserRepository userRepository) - { - _userRepository = userRepository; - } + _userRepository = userRepository; + } - public async Task Handle(Command command, CancellationToken cancellationToken) - { - var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); - if (user is null) - { - return Result.NotFound($"User with id '{command.Id}' not found."); - } + public async Task Handle(DeleteUserCommand command, CancellationToken cancellationToken) + { + var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); + if (user is null) return Result.NotFound($"User with id '{command.Id}' not found."); - _userRepository.Remove(user); - return Result.Success(); - } + _userRepository.Remove(user); + return Result.Success(); } } \ No newline at end of file diff --git a/application/account-management/Application/Users/GetUser.cs b/application/account-management/Application/Users/GetUser.cs index 37f885121..98382f943 100644 --- a/application/account-management/Application/Users/GetUser.cs +++ b/application/account-management/Application/Users/GetUser.cs @@ -3,25 +3,22 @@ namespace PlatformPlatform.AccountManagement.Application.Users; -public static class GetUser +public sealed record GetUserQuery(UserId Id) : IRequest>; + +[UsedImplicitly] +public sealed class GetUserHandler : IRequestHandler> { - public sealed record Query(UserId Id) : IRequest>; + private readonly IUserRepository _userRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler> + public GetUserHandler(IUserRepository userRepository) { - private readonly IUserRepository _userRepository; - - public Handler(IUserRepository userRepository) - { - _userRepository = userRepository; - } + _userRepository = userRepository; + } - public async Task> Handle(Query request, CancellationToken cancellationToken) - { - var user = await _userRepository.GetByIdAsync(request.Id, cancellationToken); - return user?.Adapt() - ?? Result.NotFound($"User with id '{request.Id}' not found."); - } + public async Task> Handle(GetUserQuery request, CancellationToken cancellationToken) + { + var user = await _userRepository.GetByIdAsync(request.Id, cancellationToken); + return user?.Adapt() + ?? Result.NotFound($"User with id '{request.Id}' not found."); } } \ No newline at end of file diff --git a/application/account-management/Application/Users/UpdateUser.cs b/application/account-management/Application/Users/UpdateUser.cs index c64c6df1e..b5d463149 100644 --- a/application/account-management/Application/Users/UpdateUser.cs +++ b/application/account-management/Application/Users/UpdateUser.cs @@ -2,44 +2,38 @@ namespace PlatformPlatform.AccountManagement.Application.Users; -public static class UpdateUser +public sealed record UpdateUserCommand : ICommand, IUserValidation, IRequest { - public sealed record Command : ICommand, IUserValidation, IRequest - { - [JsonIgnore] // Removes the Id from the API contract - public UserId Id { get; init; } = null!; + [JsonIgnore] // Removes the Id from the API contract + public UserId Id { get; init; } = null!; - public required UserRole UserRole { get; init; } + public required UserRole UserRole { get; init; } - public required string Email { get; init; } - } + public required string Email { get; init; } +} + +[UsedImplicitly] +public sealed class UpdateUserHandler : IRequestHandler +{ + private readonly IUserRepository _userRepository; - [UsedImplicitly] - public sealed class Handler : IRequestHandler + public UpdateUserHandler(IUserRepository userRepository) { - private readonly IUserRepository _userRepository; - - public Handler(IUserRepository userRepository) - { - _userRepository = userRepository; - } - - public async Task Handle(Command command, CancellationToken cancellationToken) - { - var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); - if (user is null) - { - return Result.NotFound($"User with id '{command.Id}' not found."); - } - - user.Update(command.Email, command.UserRole); - _userRepository.Update(user); - return Result.Success(); - } + _userRepository = userRepository; } - [UsedImplicitly] - public sealed class Validator : UserValidator + public async Task Handle(UpdateUserCommand command, CancellationToken cancellationToken) { + var user = await _userRepository.GetByIdAsync(command.Id, cancellationToken); + if (user is null) return Result.NotFound($"User with id '{command.Id}' not found."); + + user.Update(command.Email, command.UserRole); + _userRepository.Update(user); + return Result.Success(); } +} + +[UsedImplicitly] +public sealed class UpdateUserValidator : UserValidator +{ } \ No newline at end of file diff --git a/application/account-management/Tests/Api/Tenants/TenantEndpointsTests.cs b/application/account-management/Tests/Api/Tenants/TenantEndpointsTests.cs index 1fe0fc91d..4131cde23 100644 --- a/application/account-management/Tests/Api/Tenants/TenantEndpointsTests.cs +++ b/application/account-management/Tests/Api/Tenants/TenantEndpointsTests.cs @@ -78,7 +78,7 @@ public async Task CreateTenant_WhenValid_ShouldCreateTenantAndOwnerUser() // Arrange var subdomain = Faker.Subdomain(); var email = Faker.Internet.Email(); - var command = new CreateTenant.Command(subdomain, Faker.TenantName(), Faker.PhoneNumber(), email); + var command = new CreateTenantCommand(subdomain, Faker.TenantName(), Faker.PhoneNumber(), email); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/tenants", command); @@ -86,7 +86,7 @@ public async Task CreateTenant_WhenValid_ShouldCreateTenantAndOwnerUser() // Assert await EnsureSuccessPostRequest(response, $"/api/tenants/{subdomain}"); Connection.RowExists("Tenants", subdomain); - Connection.ExecuteScalar("SELECT COUNT(*) FROM Users WHERE Email = @email", new {email}).Should().Be(1); + Connection.ExecuteScalar("SELECT COUNT(*) FROM Users WHERE Email = @email", new { email }).Should().Be(1); } [Fact] @@ -98,7 +98,7 @@ public async Task CreateTenant_WhenInvalid_ShouldReturnBadRequest() var invalidPhone = Faker.Phone.PhoneNumber("+1 ### ###-INVALID"); var invalidEmail = Faker.InvalidEmail(); - var command = new CreateTenant.Command(invalidSubdomain, invalidName, invalidPhone, invalidEmail); + var command = new CreateTenantCommand(invalidSubdomain, invalidName, invalidPhone, invalidEmail); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/tenants", command); @@ -119,7 +119,7 @@ public async Task CreateTenant_WhenTenantExists_ShouldReturnBadRequest() { // Arrange var unavailableSubdomain = DatabaseSeeder.Tenant1.Id; - var command = new CreateTenant.Command(unavailableSubdomain, Faker.TenantName(), null, Faker.Internet.Email()); + var command = new CreateTenantCommand(unavailableSubdomain, Faker.TenantName(), null, Faker.Internet.Email()); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/tenants", command); @@ -137,7 +137,7 @@ public async Task UpdateTenant_WhenValid_ShouldUpdateTenant() { // Arrange var existingTenantId = DatabaseSeeder.Tenant1.Id; - var command = new UpdateTenant.Command {Name = Faker.TenantName(), Phone = Faker.PhoneNumber()}; + var command = new UpdateTenantCommand { Name = Faker.TenantName(), Phone = Faker.PhoneNumber() }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/tenants/{existingTenantId}", command); @@ -153,7 +153,7 @@ public async Task UpdateTenant_WhenInvalid_ShouldReturnBadRequest() var existingTenantId = DatabaseSeeder.Tenant1.Id; var invalidName = Faker.Random.String2(31); var invalidPhone = Faker.Phone.PhoneNumber("+1 ### ###-INVALID"); - var command = new UpdateTenant.Command {Name = invalidName, Phone = invalidPhone}; + var command = new UpdateTenantCommand { Name = invalidName, Phone = invalidPhone }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/tenants/{existingTenantId}", command); @@ -172,7 +172,7 @@ public async Task UpdateTenant_WhenTenantDoesNotExists_ShouldReturnNotFound() { // Arrange var unknownTenantId = Faker.Subdomain(); - var command = new UpdateTenant.Command {Name = Faker.TenantName(), Phone = Faker.PhoneNumber()}; + var command = new UpdateTenantCommand { Name = Faker.TenantName(), Phone = Faker.PhoneNumber() }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/tenants/{unknownTenantId}", command); diff --git a/application/account-management/Tests/Api/Users/UserEndpointsTests.cs b/application/account-management/Tests/Api/Users/UserEndpointsTests.cs index 3ca70e7e4..c946af8d7 100644 --- a/application/account-management/Tests/Api/Users/UserEndpointsTests.cs +++ b/application/account-management/Tests/Api/Users/UserEndpointsTests.cs @@ -75,7 +75,7 @@ public async Task CreateUser_WhenValid_ShouldCreateUser() { // Arrange var existingTenantId = DatabaseSeeder.Tenant1.Id; - var command = new CreateUser.Command(existingTenantId, Faker.Internet.Email(), UserRole.TenantUser); + var command = new CreateUserCommand(existingTenantId, Faker.Internet.Email(), UserRole.TenantUser); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/users", command); @@ -91,7 +91,7 @@ public async Task CreateUser_WhenInvalidEmail_ShouldReturnBadRequest() // Arrange var existingTenantId = DatabaseSeeder.Tenant1.Id; var invalidEmail = Faker.InvalidEmail(); - var command = new CreateUser.Command(existingTenantId, invalidEmail, UserRole.TenantUser); + var command = new CreateUserCommand(existingTenantId, invalidEmail, UserRole.TenantUser); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/users", command); @@ -110,7 +110,7 @@ public async Task CreateUser_WhenUserExists_ShouldReturnBadRequest() // Arrange var existingTenantId = DatabaseSeeder.Tenant1.Id; var existingUserEmail = DatabaseSeeder.User1.Email; - var command = new CreateUser.Command(existingTenantId, existingUserEmail, UserRole.TenantUser); + var command = new CreateUserCommand(existingTenantId, existingUserEmail, UserRole.TenantUser); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/users", command); @@ -130,7 +130,7 @@ public async Task CreateUser_WhenTenantDoesNotExists_ShouldReturnBadRequest() // Arrange var unknownTenantId = Faker.Subdomain(); var command = - new CreateUser.Command(new TenantId(unknownTenantId), Faker.Internet.Email(), UserRole.TenantUser); + new CreateUserCommand(new TenantId(unknownTenantId), Faker.Internet.Email(), UserRole.TenantUser); // Act var response = await TestHttpClient.PostAsJsonAsync("/api/users", command); @@ -148,7 +148,7 @@ public async Task UpdateUser_WhenValid_ShouldUpdateUser() { // Arrange var existingUserId = DatabaseSeeder.User1.Id; - var command = new UpdateUser.Command {Email = Faker.Internet.Email(), UserRole = UserRole.TenantOwner}; + var command = new UpdateUserCommand { Email = Faker.Internet.Email(), UserRole = UserRole.TenantOwner }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/users/{existingUserId}", command); @@ -163,7 +163,7 @@ public async Task UpdateUser_WhenInvalid_ShouldReturnBadRequest() // Arrange var existingUserId = DatabaseSeeder.User1.Id; var invalidEmail = Faker.InvalidEmail(); - var command = new UpdateUser.Command {Email = invalidEmail, UserRole = UserRole.TenantAdmin}; + var command = new UpdateUserCommand { Email = invalidEmail, UserRole = UserRole.TenantAdmin }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/users/{existingUserId}", command); @@ -181,7 +181,7 @@ public async Task UpdateUser_WhenUserDoesNotExists_ShouldReturnNotFound() { // Arrange var unknownUserId = Faker.RandomUlid(); - var command = new UpdateUser.Command {Email = Faker.Internet.Email(), UserRole = UserRole.TenantAdmin}; + var command = new UpdateUserCommand { Email = Faker.Internet.Email(), UserRole = UserRole.TenantAdmin }; // Act var response = await TestHttpClient.PutAsJsonAsync($"/api/users/{unknownUserId}", command); diff --git a/application/account-management/Tests/Application/Tenants/CreateTenantValidationTests.cs b/application/account-management/Tests/Application/Tenants/CreateTenantValidationTests.cs index 0062168ae..c04d2cf31 100644 --- a/application/account-management/Tests/Application/Tenants/CreateTenantValidationTests.cs +++ b/application/account-management/Tests/Application/Tenants/CreateTenantValidationTests.cs @@ -16,7 +16,7 @@ public async Task CreateTenant_WhenValidCommand_ShouldReturnSuccessfulResult(str string name, string phone, string email) { // Arrange - var command = new CreateTenant.Command(subdomain, name, phone, email); + var command = new CreateTenantCommand(subdomain, name, phone, email); var mediator = Provider.GetRequiredService(); // Act @@ -44,7 +44,7 @@ public async Task CreateTenant_WhenInvalidCommand_ShouldReturnUnsuccessfulResult string subdomain, string name, string phone, string email) { // Arrange - var command = new CreateTenant.Command(subdomain, name, phone, email); + var command = new CreateTenantCommand(subdomain, name, phone, email); var mediator = Provider.GetRequiredService(); // Act diff --git a/application/account-management/Tests/Application/Tenants/TenantCreatedEventHandlerTests.cs b/application/account-management/Tests/Application/Tenants/TenantCreatedEventHandlerTests.cs index 7cc0e7c88..d9451306d 100644 --- a/application/account-management/Tests/Application/Tenants/TenantCreatedEventHandlerTests.cs +++ b/application/account-management/Tests/Application/Tenants/TenantCreatedEventHandlerTests.cs @@ -17,7 +17,7 @@ public async Task TenantCreatedEvent_WhenTenantIsCreated_ShouldLogCorrectInforma var mediator = Provider.GetRequiredService(); // Act - var command = new CreateTenant.Command("tenant2", "TestTenant", "1234567890", "test@test.com"); + var command = new CreateTenantCommand("tenant2", "TestTenant", "1234567890", "test@test.com"); _ = await mediator.Send(command); // Assert