mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Replaces FluentValidation and Mediator command/queries handling with custom implementations.
This commit is contained in:
1 parent
9a5c7473f9
commit
2d1c6b1ab8
297 files changed
+3619
-3045
No files matched your search
+16
-11
@@ -8,6 +8,7 @@ using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
|
||||
@@ -53,6 +54,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
_mockDataSeedService = Substitute.For<IDataSeedService>();
|
||||
_setupApplicationCommandFixture = new SetupApplicationCommandFixture();
|
||||
IValidator<SetupApplicationCommand> mockValidator = Substitute.For<IValidator<SetupApplicationCommand>>();
|
||||
mockValidator.Validate(Arg.Any<SetupApplicationCommand>())
|
||||
.Returns([]);
|
||||
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
@@ -64,7 +68,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockTotpTokenGenerator,
|
||||
_mockQRCodeGenerator,
|
||||
_mockDateTimeProvider,
|
||||
_mockDataSeedService);
|
||||
_mockDataSeedService,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,7 +87,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -119,7 +124,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -143,7 +148,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(new[] { existingUser });
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -165,7 +170,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -189,7 +194,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -215,7 +220,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -242,7 +247,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -272,7 +277,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -305,7 +310,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -337,7 +342,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+31
-40
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -34,11 +36,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = null };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -49,11 +50,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,11 +64,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -79,11 +78,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -94,11 +92,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -109,11 +106,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -124,11 +120,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -139,11 +134,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -154,11 +148,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -169,11 +162,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordsNotMatch.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordsNotMatch);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -190,11 +182,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidPassword.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -209,10 +200,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -223,11 +214,11 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = "$321Bcda", PasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.PasswordConfirm);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -48,7 +48,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(users.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsInitialized);
|
||||
@@ -63,7 +63,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
@@ -79,7 +79,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
|
||||
Reference in new issue
Block a user