mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21: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
+11
-6
@@ -5,6 +5,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
@@ -39,9 +40,13 @@ public class ChangePasswordCommandHandlerTests
|
||||
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
|
||||
IValidator<ChangePasswordCommand> mockValidator = Substitute.For<IValidator<ChangePasswordCommand>>();
|
||||
mockValidator.Validate(Arg.Any<ChangePasswordCommand>())
|
||||
.Returns([]);
|
||||
_sut = new ChangePasswordCommandHandler(
|
||||
_mockUnitOfWork,
|
||||
_mockHashService);
|
||||
_mockHashService,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -72,7 +77,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -95,7 +100,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -125,7 +130,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -163,7 +168,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -193,7 +198,7 @@ public class ChangePasswordCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<ChangePasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+41
-54
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { Username = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> 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]
|
||||
@@ -47,11 +48,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> 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]
|
||||
@@ -62,11 +62,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> 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]
|
||||
@@ -77,11 +76,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { CurrentPassword = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.CurrentPassword)
|
||||
.WithErrorMessage(Errors.Authentication.CurrentPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.CurrentPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -92,11 +90,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { CurrentPassword = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.CurrentPassword)
|
||||
.WithErrorMessage(Errors.Authentication.CurrentPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.CurrentPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,11 +104,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { CurrentPassword = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.CurrentPassword)
|
||||
.WithErrorMessage(Errors.Authentication.CurrentPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.CurrentPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,11 +118,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPassword = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPassword)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -137,11 +132,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPassword = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPassword)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -152,11 +146,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPassword = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPassword)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -167,11 +160,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPasswordConfirm = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -182,11 +174,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPasswordConfirm = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -197,11 +188,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPasswordConfirm = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.NewPasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.NewPasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -212,11 +202,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPassword)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordsNotMatch.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordsNotMatch);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -233,11 +222,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { CurrentPassword = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.CurrentPassword)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidPassword.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -254,11 +242,10 @@ public class ChangePasswordCommandValidatorTests
|
||||
command = command with { NewPassword = password, NewPasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPassword)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidPassword.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -278,11 +265,11 @@ public class ChangePasswordCommandValidatorTests
|
||||
};
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.CurrentPassword);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.NewPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -292,12 +279,12 @@ public class ChangePasswordCommandValidatorTests
|
||||
ChangePasswordCommand command = ChangePasswordCommandFixture.CreateChangePasswordCommand();
|
||||
|
||||
// Act
|
||||
TestValidationResult<ChangePasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.CurrentPassword);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.NewPassword);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.NewPasswordConfirm);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.NewPasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+14
-9
@@ -6,6 +6,7 @@ using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
@@ -44,11 +45,15 @@ public class RecoverPasswordCommandHandlerTests
|
||||
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
|
||||
IValidator<RecoverPasswordCommand> mockValidator = Substitute.For<IValidator<RecoverPasswordCommand>>();
|
||||
mockValidator.Validate(Arg.Any<RecoverPasswordCommand>())
|
||||
.Returns([]);
|
||||
_sut = new RecoverPasswordCommandHandler(
|
||||
_mockUnitOfWork,
|
||||
_mockHashService,
|
||||
_mockTotpTokenGenerator,
|
||||
_mockCryptographyService);
|
||||
_mockCryptographyService,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -78,7 +83,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -101,7 +106,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -126,7 +131,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -150,7 +155,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -182,7 +187,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -218,7 +223,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -247,7 +252,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -273,7 +278,7 @@ public class RecoverPasswordCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(user));
|
||||
|
||||
// Act
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RecoverPasswordResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+22
-27
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { Username = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> 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]
|
||||
@@ -47,11 +48,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> 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]
|
||||
@@ -62,11 +62,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> 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]
|
||||
@@ -77,11 +76,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { TotpCode = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.TotpCode)
|
||||
.WithErrorMessage(Errors.Authentication.TotpCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.TotpCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -92,11 +90,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { TotpCode = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.TotpCode)
|
||||
.WithErrorMessage(Errors.Authentication.TotpCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.TotpCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,11 +104,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { TotpCode = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.TotpCode)
|
||||
.WithErrorMessage(Errors.Authentication.TotpCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.TotpCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -128,11 +124,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { TotpCode = totpCode };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.TotpCode)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidTotpCode.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -146,10 +141,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
command = command with { TotpCode = totpCode };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.TotpCode);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -159,10 +154,10 @@ public class RecoverPasswordCommandValidatorTests
|
||||
RecoverPasswordCommand command = RecoverPasswordCommandFixture.CreateRecoverPasswordCommand();
|
||||
|
||||
// Act
|
||||
TestValidationResult<RecoverPasswordCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.TotpCode);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.TotpCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -7,6 +7,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.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
|
||||
@@ -51,13 +52,17 @@ public class RegisterUserCommandHandlerTests
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
|
||||
IValidator<RegisterUserCommand> mockValidator = Substitute.For<IValidator<RegisterUserCommand>>();
|
||||
mockValidator.Validate(Arg.Any<RegisterUserCommand>())
|
||||
.Returns([]);
|
||||
_sut = new RegisterUserCommandHandler(
|
||||
_mockUnitOfWork,
|
||||
_mockHashService,
|
||||
_mockCryptographyService,
|
||||
_mockTotpTokenGenerator,
|
||||
_mockQRCodeGenerator,
|
||||
_mockDateTimeProvider);
|
||||
_mockDateTimeProvider,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -84,7 +89,7 @@ public class RegisterUserCommandHandlerTests
|
||||
.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);
|
||||
@@ -115,7 +120,7 @@ public class RegisterUserCommandHandlerTests
|
||||
.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);
|
||||
@@ -142,7 +147,7 @@ public class RegisterUserCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(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);
|
||||
@@ -166,7 +171,7 @@ public class RegisterUserCommandHandlerTests
|
||||
.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);
|
||||
@@ -188,7 +193,7 @@ public class RegisterUserCommandHandlerTests
|
||||
.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);
|
||||
|
||||
+38
-48
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -47,11 +48,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -62,11 +62,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -77,11 +76,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Password = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -92,11 +90,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Password = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -107,11 +104,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Password = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -122,11 +118,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { PasswordConfirm = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -137,11 +132,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { PasswordConfirm = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -152,11 +146,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { PasswordConfirm = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -167,11 +160,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { PasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -188,11 +180,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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]
|
||||
@@ -207,10 +198,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -226,12 +217,12 @@ public class RegisterUserCommandValidatorTests
|
||||
};
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> 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);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -245,11 +236,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = username };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameMustBeBetween3And255CharactersLong.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameMustBeBetween3And255CharactersLong);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -270,10 +260,10 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = username };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidUsername);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -291,9 +281,9 @@ public class RegisterUserCommandValidatorTests
|
||||
command = command with { Username = username };
|
||||
|
||||
// Act
|
||||
TestValidationResult<RegisterUserCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
}
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidUsername);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -65,7 +65,7 @@ public class GetUsersQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -86,7 +86,7 @@ public class GetUsersQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -107,7 +107,7 @@ public class GetUsersQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(users));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<UserResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+16
-11
@@ -7,6 +7,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.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
@@ -50,13 +51,17 @@ public class LoginUserQueryHandlerTests
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
|
||||
IValidator<LoginUserQuery> mockValidator = Substitute.For<IValidator<LoginUserQuery>>();
|
||||
mockValidator.Validate(Arg.Any<LoginUserQuery>())
|
||||
.Returns([]);
|
||||
_sut = new LoginUserQueryHandler(
|
||||
_mockUnitOfWork,
|
||||
_mockHashService,
|
||||
_mockJwtTokenGenerator,
|
||||
_mockTotpTokenGenerator,
|
||||
_mockCryptographyService,
|
||||
_mockDateTimeProvider);
|
||||
_mockDateTimeProvider,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -81,7 +86,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(jwtToken);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -120,7 +125,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -140,7 +145,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From<UserEntity?>(null));
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -166,7 +171,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -196,7 +201,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -236,7 +241,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(jwtToken);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -266,7 +271,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -299,7 +304,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -317,7 +322,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -347,7 +352,7 @@ public class LoginUserQueryHandlerTests
|
||||
.Returns(false); // Temp password check also fails
|
||||
|
||||
// Act
|
||||
ErrorOr<LoginResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<LoginResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+29
-35
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Username = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,11 +76,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Password = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -92,11 +90,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Password = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,11 +104,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Password = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -128,11 +124,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Password = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidPassword.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -147,10 +142,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { Password = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -167,11 +162,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { TotpCode = totpCode };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.TotpCode)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidTotpCode.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -185,10 +179,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { TotpCode = totpCode };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.TotpCode);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -199,10 +193,10 @@ public class LoginUserQueryValidatorTests
|
||||
query = query with { TotpCode = null };
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.TotpCode);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -212,11 +206,11 @@ public class LoginUserQueryValidatorTests
|
||||
LoginUserQuery query = LoginUserQueryFixture.CreateLoginQuery(true);
|
||||
|
||||
// Act
|
||||
TestValidationResult<LoginUserQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.TotpCode);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidTotpCode);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user