0
0
mirror of https://github.com/alex289/CleanArchitecture.git synced 2025-06-29 18:21:08 +00:00

feat: Rename error codes

This commit is contained in:
alex289 2023-11-25 16:09:15 +01:00
parent 463121f3dc
commit 12659a138d
No known key found for this signature in database
GPG Key ID: 573F77CD2D87F863
33 changed files with 138 additions and 140 deletions

View File

@ -48,7 +48,7 @@ public sealed class TenantController : ApiController
return Response(tenants);
}
[HttpGet("{id:guid}")]
[HttpGet("{id}")]
[SwaggerOperation("Get a tenant by id")]
[SwaggerResponse(200, "Request successful", typeof(ResponseMessage<TenantViewModel>))]
public async Task<IActionResult> GetTenantByIdAsync([FromRoute] Guid id)
@ -75,7 +75,7 @@ public sealed class TenantController : ApiController
return Response(tenant);
}
[HttpDelete("{id:guid}")]
[HttpDelete("{id}")]
[SwaggerOperation("Delete an existing tenant")]
[SwaggerResponse(200, "Request successful", typeof(ResponseMessage<Guid>))]
public async Task<IActionResult> DeleteTenantAsync([FromRoute] Guid id)

View File

@ -48,7 +48,7 @@ public sealed class UserController : ApiController
return Response(users);
}
[HttpGet("{id:guid}")]
[HttpGet("{id}")]
[SwaggerOperation("Get a user by id")]
[SwaggerResponse(200, "Request successful", typeof(ResponseMessage<UserViewModel>))]
public async Task<IActionResult> GetUserByIdAsync([FromRoute] Guid id)
@ -75,7 +75,7 @@ public sealed class UserController : ApiController
return Response(userId);
}
[HttpDelete("{id:guid}")]
[HttpDelete("{id}")]
[SwaggerOperation("Delete a user")]
[SwaggerResponse(200, "Request successful", typeof(ResponseMessage<Guid>))]
public async Task<IActionResult> DeleteUserAsync([FromRoute] Guid id)

View File

@ -33,8 +33,6 @@ public sealed class GetUserByIdTestFixture : QueryHandlerBaseFixture
"Password",
UserRole.User);
var query = new[] { user }.BuildMock();
UserRepository.GetByIdAsync(Arg.Is<Guid>(y => y == ExistingUserId)).Returns(user);
}

View File

@ -40,7 +40,7 @@ public sealed class GetUserByIdQueryHandlerTests
_fixture.VerifyExistingNotification(
nameof(GetUserByIdQuery),
ErrorCodes.ObjectNotFound,
$"User with id {request.UserId} could not be found");
$"User with id {request.Id} could not be found");
result.Should().BeNull();
}

View File

@ -4,4 +4,4 @@ using MediatR;
namespace CleanArchitecture.Application.Queries.Users.GetUserById;
public sealed record GetUserByIdQuery(Guid UserId) : IRequest<UserViewModel?>;
public sealed record GetUserByIdQuery(Guid Id) : IRequest<UserViewModel?>;

View File

@ -23,14 +23,14 @@ public sealed class GetUserByIdQueryHandler :
public async Task<UserViewModel?> Handle(GetUserByIdQuery request, CancellationToken cancellationToken)
{
var user = await _userRepository.GetByIdAsync(request.UserId);
var user = await _userRepository.GetByIdAsync(request.Id);
if (user is null)
{
await _bus.RaiseEventAsync(
new DomainNotification(
nameof(GetUserByIdQuery),
$"User with id {request.UserId} could not be found",
$"User with id {request.Id} could not be found",
ErrorCodes.ObjectNotFound));
return null;
}

View File

@ -64,7 +64,7 @@ public sealed class CreateTenantCommandHandlerTests
.VerifyNoRaisedEvent<TenantCreatedEvent>()
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.Tenant.TenantAlreadyExists,
DomainErrorCodes.Tenant.AlreadyExists,
$"There is already a tenant with Id {command.AggregateId}");
}
}

View File

@ -27,7 +27,7 @@ public sealed class CreateTenantCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyId,
DomainErrorCodes.Tenant.EmptyId,
"Tenant id may not be empty");
}
@ -38,7 +38,7 @@ public sealed class CreateTenantCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyName,
DomainErrorCodes.Tenant.EmptyName,
"Name may not be empty");
}

View File

@ -27,7 +27,7 @@ public sealed class DeleteTenantCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyId,
DomainErrorCodes.Tenant.EmptyId,
"Tenant id may not be empty");
}

View File

@ -27,7 +27,7 @@ public sealed class UpdateTenantCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyId,
DomainErrorCodes.Tenant.EmptyId,
"Tenant id may not be empty");
}
@ -38,7 +38,7 @@ public sealed class UpdateTenantCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyName,
DomainErrorCodes.Tenant.EmptyName,
"Name may not be empty");
}

View File

@ -57,7 +57,7 @@ public sealed class ChangePasswordCommandHandlerTests
.VerifyNoRaisedEvent<UserUpdatedEvent>()
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.User.UserPasswordIncorrect,
DomainErrorCodes.User.PasswordIncorrect,
"The password is incorrect");
}
}

View File

@ -28,12 +28,12 @@ public sealed class ChangePasswordCommandValidationTests :
var errors = new List<string>
{
DomainErrorCodes.User.UserEmptyPassword,
DomainErrorCodes.User.UserSpecialCharPassword,
DomainErrorCodes.User.UserNumberPassword,
DomainErrorCodes.User.UserLowercaseLetterPassword,
DomainErrorCodes.User.UserUppercaseLetterPassword,
DomainErrorCodes.User.UserShortPassword
DomainErrorCodes.User.EmptyPassword,
DomainErrorCodes.User.SpecialCharPassword,
DomainErrorCodes.User.NumberPassword,
DomainErrorCodes.User.LowercaseLetterPassword,
DomainErrorCodes.User.UppercaseLetterPassword,
DomainErrorCodes.User.ShortPassword
};
ShouldHaveExpectedErrors(command, errors.ToArray());
@ -44,7 +44,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand("z8tnayvd5FNLU9AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserSpecialCharPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.SpecialCharPassword);
}
[Fact]
@ -52,7 +52,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand("z]tnayvdFNLU:]AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserNumberPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.NumberPassword);
}
[Fact]
@ -60,7 +60,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand("Z8]TNAYVDFNLU:]AQM");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLowercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LowercaseLetterPassword);
}
[Fact]
@ -68,7 +68,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand("z8]tnayvd5fnlu9:]aqm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserUppercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.UppercaseLetterPassword);
}
[Fact]
@ -76,7 +76,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand("zA6{");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserShortPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.ShortPassword);
}
[Fact]
@ -84,7 +84,7 @@ public sealed class ChangePasswordCommandValidationTests :
{
var command = CreateTestCommand(string.Concat(Enumerable.Repeat("zA6{", 12), 12));
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLongPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LongPassword);
}
private static ChangePasswordCommand CreateTestCommand(

View File

@ -59,7 +59,7 @@ public sealed class CreateUserCommandHandlerTests
.VerifyNoRaisedEvent<UserCreatedEvent>()
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.User.UserAlreadyExists,
DomainErrorCodes.User.AlreadyExists,
$"There is already a user with Id {command.UserId}");
}
@ -94,7 +94,7 @@ public sealed class CreateUserCommandHandlerTests
.VerifyNoRaisedEvent<UserCreatedEvent>()
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.User.UserAlreadyExists,
DomainErrorCodes.User.AlreadyExists,
$"There is already a user with email {command.Email}");
}

View File

@ -30,7 +30,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyId,
DomainErrorCodes.User.EmptyId,
"User id may not be empty");
}
@ -41,7 +41,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -52,7 +52,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -63,7 +63,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmailExceedsMaxLength,
DomainErrorCodes.User.EmailExceedsMaxLength,
$"Email may not be longer than {MaxLengths.User.Email} characters");
}
@ -74,7 +74,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyFirstName,
DomainErrorCodes.User.EmptyFirstName,
"FirstName may not be empty");
}
@ -85,7 +85,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserFirstNameExceedsMaxLength,
DomainErrorCodes.User.FirstNameExceedsMaxLength,
$"FirstName may not be longer than {MaxLengths.User.FirstName} characters");
}
@ -96,7 +96,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyLastName,
DomainErrorCodes.User.EmptyLastName,
"LastName may not be empty");
}
@ -107,7 +107,7 @@ public sealed class CreateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserLastNameExceedsMaxLength,
DomainErrorCodes.User.LastNameExceedsMaxLength,
$"LastName may not be longer than {MaxLengths.User.LastName} characters");
}
@ -118,12 +118,12 @@ public sealed class CreateUserCommandValidationTests :
var errors = new List<string>
{
DomainErrorCodes.User.UserEmptyPassword,
DomainErrorCodes.User.UserSpecialCharPassword,
DomainErrorCodes.User.UserNumberPassword,
DomainErrorCodes.User.UserLowercaseLetterPassword,
DomainErrorCodes.User.UserUppercaseLetterPassword,
DomainErrorCodes.User.UserShortPassword
DomainErrorCodes.User.EmptyPassword,
DomainErrorCodes.User.SpecialCharPassword,
DomainErrorCodes.User.NumberPassword,
DomainErrorCodes.User.LowercaseLetterPassword,
DomainErrorCodes.User.UppercaseLetterPassword,
DomainErrorCodes.User.ShortPassword
};
ShouldHaveExpectedErrors(command, errors.ToArray());
@ -134,7 +134,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z8tnayvd5FNLU9AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserSpecialCharPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.SpecialCharPassword);
}
[Fact]
@ -142,7 +142,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z]tnayvdFNLU:]AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserNumberPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.NumberPassword);
}
[Fact]
@ -150,7 +150,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: "Z8]TNAYVDFNLU:]AQM");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLowercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LowercaseLetterPassword);
}
[Fact]
@ -158,7 +158,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z8]tnayvd5fnlu9:]aqm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserUppercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.UppercaseLetterPassword);
}
[Fact]
@ -166,7 +166,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: "zA6{");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserShortPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.ShortPassword);
}
[Fact]
@ -174,7 +174,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(password: string.Concat(Enumerable.Repeat("zA6{", 12), 12));
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLongPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LongPassword);
}
[Fact]
@ -182,7 +182,7 @@ public sealed class CreateUserCommandValidationTests :
{
var command = CreateTestCommand(tenantId: Guid.Empty);
ShouldHaveSingleError(command, DomainErrorCodes.Tenant.TenantEmptyId);
ShouldHaveSingleError(command, DomainErrorCodes.Tenant.EmptyId);
}
private static CreateUserCommand CreateTestCommand(

View File

@ -27,7 +27,7 @@ public sealed class DeleteUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyId,
DomainErrorCodes.User.EmptyId,
"User id may not be empty");
}

View File

@ -74,7 +74,7 @@ public sealed class LoginUserCommandHandlerTests
_fixture
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.User.UserPasswordIncorrect,
DomainErrorCodes.User.PasswordIncorrect,
"The password is incorrect");
token.Should().BeEmpty();

View File

@ -29,7 +29,7 @@ public sealed class LoginUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -40,7 +40,7 @@ public sealed class LoginUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -51,7 +51,7 @@ public sealed class LoginUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmailExceedsMaxLength,
DomainErrorCodes.User.EmailExceedsMaxLength,
$"Email may not be longer than {MaxLengths.User.Email} characters");
}
@ -62,12 +62,12 @@ public sealed class LoginUserCommandValidationTests :
var errors = new List<string>
{
DomainErrorCodes.User.UserEmptyPassword,
DomainErrorCodes.User.UserSpecialCharPassword,
DomainErrorCodes.User.UserNumberPassword,
DomainErrorCodes.User.UserLowercaseLetterPassword,
DomainErrorCodes.User.UserUppercaseLetterPassword,
DomainErrorCodes.User.UserShortPassword
DomainErrorCodes.User.EmptyPassword,
DomainErrorCodes.User.SpecialCharPassword,
DomainErrorCodes.User.NumberPassword,
DomainErrorCodes.User.LowercaseLetterPassword,
DomainErrorCodes.User.UppercaseLetterPassword,
DomainErrorCodes.User.ShortPassword
};
ShouldHaveExpectedErrors(command, errors.ToArray());
@ -78,7 +78,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z8tnayvd5FNLU9AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserSpecialCharPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.SpecialCharPassword);
}
[Fact]
@ -86,7 +86,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z]tnayvdFNLU:]AQm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserNumberPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.NumberPassword);
}
[Fact]
@ -94,7 +94,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: "Z8]TNAYVDFNLU:]AQM");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLowercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LowercaseLetterPassword);
}
[Fact]
@ -102,7 +102,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: "z8]tnayvd5fnlu9:]aqm");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserUppercaseLetterPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.UppercaseLetterPassword);
}
[Fact]
@ -110,7 +110,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: "zA6{");
ShouldHaveSingleError(command, DomainErrorCodes.User.UserShortPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.ShortPassword);
}
[Fact]
@ -118,7 +118,7 @@ public sealed class LoginUserCommandValidationTests :
{
var command = CreateTestCommand(password: string.Concat(Enumerable.Repeat("zA6{", 12), 12));
ShouldHaveSingleError(command, DomainErrorCodes.User.UserLongPassword);
ShouldHaveSingleError(command, DomainErrorCodes.User.LongPassword);
}
private static LoginUserCommand CreateTestCommand(

View File

@ -95,7 +95,7 @@ public sealed class UpdateUserCommandHandlerTests
.VerifyNoRaisedEvent<UserUpdatedEvent>()
.VerifyAnyDomainNotification()
.VerifyExistingNotification(
DomainErrorCodes.User.UserAlreadyExists,
DomainErrorCodes.User.AlreadyExists,
$"There is already a user with email {command.Email}");
}

View File

@ -29,7 +29,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyId,
DomainErrorCodes.User.EmptyId,
"User id may not be empty");
}
@ -40,7 +40,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -51,7 +51,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserInvalidEmail,
DomainErrorCodes.User.InvalidEmail,
"Email is not a valid email address");
}
@ -62,7 +62,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmailExceedsMaxLength,
DomainErrorCodes.User.EmailExceedsMaxLength,
$"Email may not be longer than {MaxLengths.User.Email} characters");
}
@ -73,7 +73,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyFirstName,
DomainErrorCodes.User.EmptyFirstName,
"FirstName may not be empty");
}
@ -84,7 +84,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserFirstNameExceedsMaxLength,
DomainErrorCodes.User.FirstNameExceedsMaxLength,
$"FirstName may not be longer than {MaxLengths.User.FirstName} characters");
}
@ -95,7 +95,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserEmptyLastName,
DomainErrorCodes.User.EmptyLastName,
"LastName may not be empty");
}
@ -106,7 +106,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.User.UserLastNameExceedsMaxLength,
DomainErrorCodes.User.LastNameExceedsMaxLength,
$"LastName may not be longer than {MaxLengths.User.LastName} characters");
}
@ -117,7 +117,7 @@ public sealed class UpdateUserCommandValidationTests :
ShouldHaveSingleError(
command,
DomainErrorCodes.Tenant.TenantEmptyId,
DomainErrorCodes.Tenant.EmptyId,
"Tenant id may not be empty");
}

View File

@ -52,7 +52,7 @@ public sealed class CreateTenantCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
$"There is already a tenant with Id {request.AggregateId}",
DomainErrorCodes.Tenant.TenantAlreadyExists));
DomainErrorCodes.Tenant.AlreadyExists));
return;
}

View File

@ -16,7 +16,7 @@ public sealed class CreateTenantCommandValidation : AbstractValidator<CreateTena
{
RuleFor(cmd => cmd.AggregateId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyId)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyId)
.WithMessage("Tenant id may not be empty");
}
@ -24,10 +24,10 @@ public sealed class CreateTenantCommandValidation : AbstractValidator<CreateTena
{
RuleFor(cmd => cmd.Name)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyName)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyName)
.WithMessage("Name may not be empty")
.MaximumLength(MaxLengths.Tenant.Name)
.WithErrorCode(DomainErrorCodes.Tenant.TenantNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.Tenant.NameExceedsMaxLength)
.WithMessage($"Name may not be longer than {MaxLengths.Tenant.Name} characters");
}
}

View File

@ -14,7 +14,7 @@ public sealed class DeleteTenantCommandValidation : AbstractValidator<DeleteTena
{
RuleFor(cmd => cmd.AggregateId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyId)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyId)
.WithMessage("Tenant id may not be empty");
}
}

View File

@ -16,7 +16,7 @@ public sealed class UpdateTenantCommandValidation : AbstractValidator<UpdateTena
{
RuleFor(cmd => cmd.AggregateId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyId)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyId)
.WithMessage("Tenant id may not be empty");
}
@ -24,10 +24,10 @@ public sealed class UpdateTenantCommandValidation : AbstractValidator<UpdateTena
{
RuleFor(cmd => cmd.Name)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyName)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyName)
.WithMessage("Name may not be empty")
.MaximumLength(MaxLengths.Tenant.Name)
.WithErrorCode(DomainErrorCodes.Tenant.TenantNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.Tenant.NameExceedsMaxLength)
.WithMessage($"Name may not be longer than {MaxLengths.Tenant.Name} characters");
}
}

View File

@ -53,7 +53,7 @@ public sealed class ChangePasswordCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
"The password is incorrect",
DomainErrorCodes.User.UserPasswordIncorrect));
DomainErrorCodes.User.PasswordIncorrect));
return;
}

View File

@ -59,7 +59,7 @@ public sealed class CreateUserCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
$"There is already a user with Id {request.UserId}",
DomainErrorCodes.User.UserAlreadyExists));
DomainErrorCodes.User.AlreadyExists));
return;
}
@ -71,7 +71,7 @@ public sealed class CreateUserCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
$"There is already a user with email {request.Email}",
DomainErrorCodes.User.UserAlreadyExists));
DomainErrorCodes.User.AlreadyExists));
return;
}

View File

@ -21,7 +21,7 @@ public sealed class CreateUserCommandValidation : AbstractValidator<CreateUserCo
{
RuleFor(cmd => cmd.UserId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyId)
.WithErrorCode(DomainErrorCodes.User.EmptyId)
.WithMessage("User id may not be empty");
}
@ -29,7 +29,7 @@ public sealed class CreateUserCommandValidation : AbstractValidator<CreateUserCo
{
RuleFor(cmd => cmd.TenantId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyId)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyId)
.WithMessage("Tenant id may not be empty");
}
@ -37,10 +37,10 @@ public sealed class CreateUserCommandValidation : AbstractValidator<CreateUserCo
{
RuleFor(cmd => cmd.Email)
.EmailAddress()
.WithErrorCode(DomainErrorCodes.User.UserInvalidEmail)
.WithErrorCode(DomainErrorCodes.User.InvalidEmail)
.WithMessage("Email is not a valid email address")
.MaximumLength(MaxLengths.User.Email)
.WithErrorCode(DomainErrorCodes.User.UserEmailExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.EmailExceedsMaxLength)
.WithMessage($"Email may not be longer than {MaxLengths.User.Email} characters");
}
@ -48,10 +48,10 @@ public sealed class CreateUserCommandValidation : AbstractValidator<CreateUserCo
{
RuleFor(cmd => cmd.FirstName)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyFirstName)
.WithErrorCode(DomainErrorCodes.User.EmptyFirstName)
.WithMessage("FirstName may not be empty")
.MaximumLength(MaxLengths.User.FirstName)
.WithErrorCode(DomainErrorCodes.User.UserFirstNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.FirstNameExceedsMaxLength)
.WithMessage($"FirstName may not be longer than {MaxLengths.User.FirstName} characters");
}
@ -59,10 +59,10 @@ public sealed class CreateUserCommandValidation : AbstractValidator<CreateUserCo
{
RuleFor(cmd => cmd.LastName)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyLastName)
.WithErrorCode(DomainErrorCodes.User.EmptyLastName)
.WithMessage("LastName may not be empty")
.MaximumLength(MaxLengths.User.LastName)
.WithErrorCode(DomainErrorCodes.User.UserLastNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.LastNameExceedsMaxLength)
.WithMessage($"LastName may not be longer than {MaxLengths.User.LastName} characters");
}

View File

@ -14,7 +14,7 @@ public sealed class DeleteUserCommandValidation : AbstractValidator<DeleteUserCo
{
RuleFor(cmd => cmd.UserId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyId)
.WithErrorCode(DomainErrorCodes.User.EmptyId)
.WithMessage("User id may not be empty");
}
}

View File

@ -64,7 +64,7 @@ public sealed class LoginUserCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
"The password is incorrect",
DomainErrorCodes.User.UserPasswordIncorrect));
DomainErrorCodes.User.PasswordIncorrect));
return "";
}

View File

@ -17,10 +17,10 @@ public sealed class LoginUserCommandValidation : AbstractValidator<LoginUserComm
{
RuleFor(cmd => cmd.Email)
.EmailAddress()
.WithErrorCode(DomainErrorCodes.User.UserInvalidEmail)
.WithErrorCode(DomainErrorCodes.User.InvalidEmail)
.WithMessage("Email is not a valid email address")
.MaximumLength(MaxLengths.User.Email)
.WithErrorCode(DomainErrorCodes.User.UserEmailExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.EmailExceedsMaxLength)
.WithMessage($"Email may not be longer than {MaxLengths.User.Email} characters");
}

View File

@ -70,7 +70,7 @@ public sealed class UpdateUserCommandHandler : CommandHandlerBase,
new DomainNotification(
request.MessageType,
$"There is already a user with email {request.Email}",
DomainErrorCodes.User.UserAlreadyExists));
DomainErrorCodes.User.AlreadyExists));
return;
}
}

View File

@ -20,7 +20,7 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.UserId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyId)
.WithErrorCode(DomainErrorCodes.User.EmptyId)
.WithMessage("User id may not be empty");
}
@ -28,7 +28,7 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.TenantId)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.Tenant.TenantEmptyId)
.WithErrorCode(DomainErrorCodes.Tenant.EmptyId)
.WithMessage("Tenant id may not be empty");
}
@ -36,10 +36,10 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.Email)
.EmailAddress()
.WithErrorCode(DomainErrorCodes.User.UserInvalidEmail)
.WithErrorCode(DomainErrorCodes.User.InvalidEmail)
.WithMessage("Email is not a valid email address")
.MaximumLength(MaxLengths.User.Email)
.WithErrorCode(DomainErrorCodes.User.UserEmailExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.EmailExceedsMaxLength)
.WithMessage($"Email may not be longer than {MaxLengths.User.Email} characters");
}
@ -47,10 +47,10 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.FirstName)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyFirstName)
.WithErrorCode(DomainErrorCodes.User.EmptyFirstName)
.WithMessage("FirstName may not be empty")
.MaximumLength(MaxLengths.User.FirstName)
.WithErrorCode(DomainErrorCodes.User.UserFirstNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.FirstNameExceedsMaxLength)
.WithMessage($"FirstName may not be longer than {MaxLengths.User.FirstName} characters");
}
@ -58,10 +58,10 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.LastName)
.NotEmpty()
.WithErrorCode(DomainErrorCodes.User.UserEmptyLastName)
.WithErrorCode(DomainErrorCodes.User.EmptyLastName)
.WithMessage("LastName may not be empty")
.MaximumLength(MaxLengths.User.LastName)
.WithErrorCode(DomainErrorCodes.User.UserLastNameExceedsMaxLength)
.WithErrorCode(DomainErrorCodes.User.LastNameExceedsMaxLength)
.WithMessage($"LastName may not be longer than {MaxLengths.User.LastName} characters");
}
@ -69,7 +69,7 @@ public sealed class UpdateUserCommandValidation : AbstractValidator<UpdateUserCo
{
RuleFor(cmd => cmd.Role)
.IsInEnum()
.WithErrorCode(DomainErrorCodes.User.UserInvalidRole)
.WithErrorCode(DomainErrorCodes.User.InvalidRole)
.WithMessage("Role is not a valid role");
}
}

View File

@ -5,37 +5,37 @@ public static class DomainErrorCodes
public static class User
{
// User Validation
public const string UserEmptyId = "USER_EMPTY_ID";
public const string UserEmptyFirstName = "USER_EMPTY_FIRST_NAME";
public const string UserEmptyLastName = "USER_EMPTY_LAST_NAME";
public const string UserEmailExceedsMaxLength = "USER_EMAIL_EXCEEDS_MAX_LENGTH";
public const string UserFirstNameExceedsMaxLength = "USER_FIRST_NAME_EXCEEDS_MAX_LENGTH";
public const string UserLastNameExceedsMaxLength = "USER_LAST_NAME_EXCEEDS_MAX_LENGTH";
public const string UserInvalidEmail = "USER_INVALID_EMAIL";
public const string UserInvalidRole = "USER_INVALID_ROLE";
public const string EmptyId = "USER_EMPTY_ID";
public const string EmptyFirstName = "USER_EMPTY_FIRST_NAME";
public const string EmptyLastName = "USER_EMPTY_LAST_NAME";
public const string EmailExceedsMaxLength = "USER_EMAIL_EXCEEDS_MAX_LENGTH";
public const string FirstNameExceedsMaxLength = "USER_FIRST_NAME_EXCEEDS_MAX_LENGTH";
public const string LastNameExceedsMaxLength = "USER_LAST_NAME_EXCEEDS_MAX_LENGTH";
public const string InvalidEmail = "USER_INVALID_EMAIL";
public const string InvalidRole = "USER_INVALID_ROLE";
// User Password Validation
public const string UserEmptyPassword = "USER_PASSWORD_MAY_NOT_BE_EMPTY";
public const string UserShortPassword = "USER_PASSWORD_MAY_NOT_BE_SHORTER_THAN_6_CHARACTERS";
public const string UserLongPassword = "USER_PASSWORD_MAY_NOT_BE_LONGER_THAN_50_CHARACTERS";
public const string UserUppercaseLetterPassword = "USER_PASSWORD_MUST_CONTAIN_A_UPPERCASE_LETTER";
public const string UserLowercaseLetterPassword = "USER_PASSWORD_MUST_CONTAIN_A_LOWERCASE_LETTER";
public const string UserNumberPassword = "USER_PASSWORD_MUST_CONTAIN_A_NUMBER";
public const string UserSpecialCharPassword = "USER_PASSWORD_MUST_CONTAIN_A_SPECIAL_CHARACTER";
public const string EmptyPassword = "USER_PASSWORD_MAY_NOT_BE_EMPTY";
public const string ShortPassword = "USER_PASSWORD_MAY_NOT_BE_SHORTER_THAN_6_CHARACTERS";
public const string LongPassword = "USER_PASSWORD_MAY_NOT_BE_LONGER_THAN_50_CHARACTERS";
public const string UppercaseLetterPassword = "USER_PASSWORD_MUST_CONTAIN_A_UPPERCASE_LETTER";
public const string LowercaseLetterPassword = "USER_PASSWORD_MUST_CONTAIN_A_LOWERCASE_LETTER";
public const string NumberPassword = "USER_PASSWORD_MUST_CONTAIN_A_NUMBER";
public const string SpecialCharPassword = "USER_PASSWORD_MUST_CONTAIN_A_SPECIAL_CHARACTER";
// General
public const string UserAlreadyExists = "USER_ALREADY_EXISTS";
public const string UserPasswordIncorrect = "USER_PASSWORD_INCORRECT";
public const string AlreadyExists = "USER_ALREADY_EXISTS";
public const string PasswordIncorrect = "USER_PASSWORD_INCORRECT";
}
public static class Tenant
{
// Tenant Validation
public const string TenantEmptyId = "TENANT_EMPTY_ID";
public const string TenantEmptyName = "TENANT_EMPTY_NAME";
public const string TenantNameExceedsMaxLength = "TENANT_NAME_EXCEEDS_MAX_LENGTH";
public const string EmptyId = "TENANT_EMPTY_ID";
public const string EmptyName = "TENANT_EMPTY_NAME";
public const string NameExceedsMaxLength = "TENANT_NAME_EXCEEDS_MAX_LENGTH";
// General
public const string TenantAlreadyExists = "TENANT_ALREADY_EXISTS";
public const string AlreadyExists = "TENANT_ALREADY_EXISTS";
}
}

View File

@ -23,13 +23,13 @@ public static partial class CustomValidator
int maxLength = 50)
{
var options = ruleBuilder
.NotEmpty().WithErrorCode(DomainErrorCodes.User.UserEmptyPassword)
.MinimumLength(minLength).WithErrorCode(DomainErrorCodes.User.UserShortPassword)
.MaximumLength(maxLength).WithErrorCode(DomainErrorCodes.User.UserLongPassword)
.Matches("[A-Z]").WithErrorCode(DomainErrorCodes.User.UserUppercaseLetterPassword)
.Matches("[a-z]").WithErrorCode(DomainErrorCodes.User.UserLowercaseLetterPassword)
.Matches("[0-9]").WithErrorCode(DomainErrorCodes.User.UserNumberPassword)
.Matches("[^a-zA-Z0-9]").WithErrorCode(DomainErrorCodes.User.UserSpecialCharPassword);
.NotEmpty().WithErrorCode(DomainErrorCodes.User.EmptyPassword)
.MinimumLength(minLength).WithErrorCode(DomainErrorCodes.User.ShortPassword)
.MaximumLength(maxLength).WithErrorCode(DomainErrorCodes.User.LongPassword)
.Matches("[A-Z]").WithErrorCode(DomainErrorCodes.User.UppercaseLetterPassword)
.Matches("[a-z]").WithErrorCode(DomainErrorCodes.User.LowercaseLetterPassword)
.Matches("[0-9]").WithErrorCode(DomainErrorCodes.User.NumberPassword)
.Matches("[^a-zA-Z0-9]").WithErrorCode(DomainErrorCodes.User.SpecialCharPassword);
return options;
}