mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12: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
+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);
|
||||
}
|
||||
}
|
||||
+14
-9
@@ -7,6 +7,7 @@ using Lumina.Application.Common.DataAccess.Repositories.Users;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions.Fixtures;
|
||||
@@ -60,10 +61,14 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
_mockUnitOfWork.GetRepository<IRoleRepository>().Returns(_mockRoleRepository);
|
||||
_mockUnitOfWork.GetRepository<IPermissionRepository>().Returns(_mockPermissionRepository);
|
||||
|
||||
IValidator<UpdateUserRoleAndPermissionsCommand> mockValidator = Substitute.For<IValidator<UpdateUserRoleAndPermissionsCommand>>();
|
||||
mockValidator.Validate(Arg.Any<UpdateUserRoleAndPermissionsCommand>())
|
||||
.Returns([]);
|
||||
_sut = new UpdateUserRoleAndPermissionsCommandHandler(
|
||||
_mockAuthorizationService,
|
||||
_mockCurrentUserService,
|
||||
_mockUnitOfWork);
|
||||
_mockUnitOfWork,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -75,7 +80,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -94,7 +99,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -116,7 +121,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -162,7 +167,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From(users));
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -192,7 +197,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -242,7 +247,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -286,7 +291,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -321,7 +326,7 @@ public class UpdateUserRoleAndPermissionsCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+12
-12
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ApplicationErrors = Lumina.Application.Common.Errors.Errors;
|
||||
using DomainErrors = Lumina.Domain.SharedKernel.Common.Errors.Errors;
|
||||
@@ -35,11 +37,10 @@ public class UpdateUserRoleAndPermissionsCommandValidatorTests
|
||||
[Guid.NewGuid()]);
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateUserRoleAndPermissionsCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(DomainErrors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(DomainErrors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -52,11 +53,10 @@ public class UpdateUserRoleAndPermissionsCommandValidatorTests
|
||||
[Guid.Empty, Guid.NewGuid()]);
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateUserRoleAndPermissionsCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Permissions[0]")
|
||||
.WithErrorMessage(ApplicationErrors.Authorization.PermissionIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(ApplicationErrors.Authorization.PermissionIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,10 +69,10 @@ public class UpdateUserRoleAndPermissionsCommandValidatorTests
|
||||
null!);
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateUserRoleAndPermissionsCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Permissions);
|
||||
result.ShouldNotHaveValidationError(ApplicationErrors.Authorization.PermissionIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -85,10 +85,10 @@ public class UpdateUserRoleAndPermissionsCommandValidatorTests
|
||||
[]);
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateUserRoleAndPermissionsCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Permissions);
|
||||
result.ShouldNotHaveValidationError(ApplicationErrors.Authorization.PermissionIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -101,7 +101,7 @@ public class UpdateUserRoleAndPermissionsCommandValidatorTests
|
||||
[Guid.NewGuid()]);
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateUserRoleAndPermissionsCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
|
||||
+10
-6
@@ -4,6 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
@@ -33,7 +34,10 @@ public class GetAuthorizationQueryHandlerTests
|
||||
{
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
_sut = new GetAuthorizationQueryHandler(_mockAuthorizationService, _mockCurrentUserService);
|
||||
IValidator<GetAuthorizationQuery> mockValidator = Substitute.For<IValidator<GetAuthorizationQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetAuthorizationQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetAuthorizationQueryHandler(_mockAuthorizationService, _mockCurrentUserService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -49,7 +53,7 @@ public class GetAuthorizationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(authEntity));
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -75,7 +79,7 @@ public class GetAuthorizationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(targetAuthEntity));
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -98,7 +102,7 @@ public class GetAuthorizationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(currentUserAuth));
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -119,7 +123,7 @@ public class GetAuthorizationQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -143,7 +147,7 @@ public class GetAuthorizationQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<AuthorizationResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+9
-9
@@ -1,9 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -33,11 +35,10 @@ public class GetAuthorizationQueryValidatorTests
|
||||
query = query with { UserId = null };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetAuthorizationQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,11 +49,10 @@ public class GetAuthorizationQueryValidatorTests
|
||||
query = query with { UserId = Guid.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetAuthorizationQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,9 +62,9 @@ public class GetAuthorizationQueryValidatorTests
|
||||
GetAuthorizationQuery query = GetAuthorizationQueryFixture.CreateGetAuthorizationQuery();
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetAuthorizationQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.UserId);
|
||||
result.ShouldNotHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+10
-5
@@ -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.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserPermissions.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
@@ -50,10 +51,14 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
|
||||
IValidator<GetUserPermissionsQuery> mockValidator = Substitute.For<IValidator<GetUserPermissionsQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetUserPermissionsQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetUserPermissionsQueryHandler(
|
||||
_mockAuthorizationService,
|
||||
_mockCurrentUserService,
|
||||
_mockUnitOfWork);
|
||||
_mockUnitOfWork,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,7 +70,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -86,7 +91,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -105,7 +110,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -144,7 +149,7 @@ public class GetUserPermissionsQueryHandlerTests
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+9
-9
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -31,11 +33,10 @@ public class GetUserPermissionsQueryValidatorTests
|
||||
GetUserPermissionsQuery query = new(null);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserPermissionsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,11 +46,10 @@ public class GetUserPermissionsQueryValidatorTests
|
||||
GetUserPermissionsQuery query = new(Guid.Empty);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserPermissionsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,9 +59,9 @@ public class GetUserPermissionsQueryValidatorTests
|
||||
GetUserPermissionsQuery query = new(Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserPermissionsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.UserId);
|
||||
result.ShouldNotHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+11
-6
@@ -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.Authorization;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserRole.Fixtures;
|
||||
@@ -48,10 +49,14 @@ public class GetUserRoleQueryHandlerTests
|
||||
_mockCurrentUserService.UserId.Returns(_userId);
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
|
||||
IValidator<GetUserRoleQuery> mockValidator = Substitute.For<IValidator<GetUserRoleQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetUserRoleQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetUserRoleQueryHandler(
|
||||
_mockAuthorizationService,
|
||||
_mockCurrentUserService,
|
||||
_mockUnitOfWork);
|
||||
_mockUnitOfWork,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -63,7 +68,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -84,7 +89,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -103,7 +108,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
.Returns((UserEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -123,7 +128,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -159,7 +164,7 @@ public class GetUserRoleQueryHandlerTests
|
||||
.Returns(user);
|
||||
|
||||
// Act
|
||||
ErrorOr<RoleResponse?> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<RoleResponse?> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+9
-9
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -31,11 +33,10 @@ public class GetUserRoleQueryValidatorTests
|
||||
GetUserRoleQuery query = new(null);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserRoleQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,11 +46,10 @@ public class GetUserRoleQueryValidatorTests
|
||||
GetUserRoleQuery query = new(Guid.Empty);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserRoleQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.UserId)
|
||||
.WithErrorMessage(Errors.Users.UserIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,9 +59,9 @@ public class GetUserRoleQueryValidatorTests
|
||||
GetUserRoleQuery query = new(Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetUserRoleQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.UserId);
|
||||
result.ShouldNotHaveValidationError(Errors.Users.UserIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user