mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Replaces FluentValidation and Mediator command/queries handling with custom implementations.
This commit is contained in:
1 parent
9a5c7473f9
commit
2d1c6b1ab8
297 files changed
+3619
-3045
No files matched your search
+4
-4
@@ -70,7 +70,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(permissions));
|
||||
|
||||
// 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);
|
||||
@@ -89,7 +89,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
.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);
|
||||
@@ -111,7 +111,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
.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);
|
||||
@@ -137,7 +137,7 @@ public class GetPermissionsQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(permissions));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.Handle(query, cancellationToken);
|
||||
ErrorOr<IEnumerable<PermissionResponse>> result = await _sut.HandleAsync(query, cancellationToken);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
|
||||
+12
-7
@@ -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.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.DeleteRole.Fixtures;
|
||||
using NSubstitute;
|
||||
@@ -36,6 +37,9 @@ public class DeleteRoleCommandHandlerTests
|
||||
/// </summary>
|
||||
public DeleteRoleCommandHandlerTests()
|
||||
{
|
||||
IValidator<DeleteRoleCommand> mockValidator = Substitute.For<IValidator<DeleteRoleCommand>>();
|
||||
mockValidator.Validate(Arg.Any<DeleteRoleCommand>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
@@ -49,7 +53,8 @@ public class DeleteRoleCommandHandlerTests
|
||||
_sut = new DeleteRoleCommandHandler(
|
||||
_mockAuthorizationService,
|
||||
_mockCurrentUserService,
|
||||
_mockUnitOfWork);
|
||||
_mockUnitOfWork,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -61,7 +66,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -81,7 +86,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -102,7 +107,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns(adminRole);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -123,7 +128,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -147,7 +152,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -170,7 +175,7 @@ public class DeleteRoleCommandHandlerTests
|
||||
.Returns(Result.Deleted);
|
||||
|
||||
// Act
|
||||
ErrorOr<Deleted> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<Deleted> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+7
-6
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -31,11 +33,10 @@ public class DeleteRoleCommandValidatorTests
|
||||
DeleteRoleCommand command = new(Guid.Empty);
|
||||
|
||||
// Act
|
||||
TestValidationResult<DeleteRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.RoleId)
|
||||
.WithErrorMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.RoleIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,9 +46,9 @@ public class DeleteRoleCommandValidatorTests
|
||||
DeleteRoleCommand command = new(Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
TestValidationResult<DeleteRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.RoleId);
|
||||
result.ShouldNotHaveValidationError(Errors.Authorization.RoleIdCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+13
-8
@@ -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.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.UpdateRole.Fixtures;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
@@ -39,6 +40,9 @@ public class UpdateRoleCommandHandlerTests
|
||||
/// </summary>
|
||||
public UpdateRoleCommandHandlerTests()
|
||||
{
|
||||
IValidator<UpdateRoleCommand> mockValidator = Substitute.For<IValidator<UpdateRoleCommand>>();
|
||||
mockValidator.Validate(Arg.Any<UpdateRoleCommand>())
|
||||
.Returns([]);
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
|
||||
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
|
||||
@@ -52,7 +56,8 @@ public class UpdateRoleCommandHandlerTests
|
||||
_sut = new UpdateRoleCommandHandler(
|
||||
_mockAuthorizationService,
|
||||
_mockCurrentUserService,
|
||||
_mockUnitOfWork);
|
||||
_mockUnitOfWork,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,7 +69,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -85,7 +90,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -108,7 +113,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -129,7 +134,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns((RoleEntity?)null);
|
||||
|
||||
// Act
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -145,7 +150,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
{
|
||||
Id = command.RoleId,
|
||||
RoleName = command.RoleName,
|
||||
RolePermissions = command.Permissions.Select(p => new RolePermissionEntity
|
||||
RolePermissions = [.. command.Permissions.Select(p => new RolePermissionEntity
|
||||
{
|
||||
RoleId = command.RoleId,
|
||||
PermissionId = p,
|
||||
@@ -155,7 +160,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
Id = p,
|
||||
PermissionName = AuthorizationPermission.CanViewUsers
|
||||
}
|
||||
}).ToList()
|
||||
})]
|
||||
};
|
||||
|
||||
_mockAuthorizationService.IsInRoleAsync(_userId, "Admin", Arg.Any<CancellationToken>())
|
||||
@@ -166,7 +171,7 @@ public class UpdateRoleCommandHandlerTests
|
||||
.Returns(role);
|
||||
|
||||
// Act
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RolePermissionsResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+18
-23
@@ -1,9 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.UpdateRole.Fixtures;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -35,11 +37,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { RoleId = Guid.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.RoleId)
|
||||
.WithErrorMessage(Errors.Authorization.RoleIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.RoleIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,11 +51,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { RoleName = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.RoleName)
|
||||
.WithErrorMessage(Errors.Authorization.RoleNameCannotBeNull.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.RoleNameCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -65,11 +65,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { RoleName = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.RoleName)
|
||||
.WithErrorMessage(Errors.Authorization.RoleNameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.RoleNameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -80,11 +79,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { RoleName = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.RoleName)
|
||||
.WithErrorMessage(Errors.Authorization.RoleNameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.RoleNameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -95,11 +93,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { Permissions = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Permissions)
|
||||
.WithErrorMessage(Errors.Authorization.PermissionsListCannotBeNull.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.PermissionsListCannotBeNull);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -110,11 +107,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { Permissions = [] };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Permissions)
|
||||
.WithErrorMessage(Errors.Authorization.PermissionsListCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.PermissionsListCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -125,11 +121,10 @@ public class UpdateRoleCommandValidatorTests
|
||||
command = command with { Permissions = [Guid.Empty, Guid.NewGuid()] };
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor("Permissions[0]")
|
||||
.WithErrorMessage(Errors.Authorization.PermissionIdCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authorization.PermissionIdCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -139,7 +134,7 @@ public class UpdateRoleCommandValidatorTests
|
||||
UpdateRoleCommand command = _fixture.CreateCommand();
|
||||
|
||||
// Act
|
||||
TestValidationResult<UpdateRoleCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
|
||||
-1
@@ -1,6 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
|
||||
+3
-3
@@ -63,7 +63,7 @@ public class GetRolesQueryHandlerTests
|
||||
.Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -84,7 +84,7 @@ public class GetRolesQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -108,7 +108,7 @@ public class GetRolesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(roles));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<RoleResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+9
-5
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,7 +38,10 @@ public class GetDirectoriesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockDirectoryService = Substitute.For<IDirectoryService>();
|
||||
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService);
|
||||
IValidator<GetDirectoriesQuery> mockValidator = Substitute.For<IValidator<GetDirectoriesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetDirectoriesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetDirectoriesQueryHandler(_mockDirectoryService, mockValidator);
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -87,7 +91,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(directories));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(getDirectoriesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(getDirectoriesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -119,7 +123,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -137,7 +141,7 @@ public class GetDirectoriesQueryHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<DirectoryResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+15
-16
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
#endregion
|
||||
@@ -32,11 +34,10 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,10 +76,10 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -91,10 +90,10 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,9 +104,9 @@ public class GetDirectoriesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetDirectoriesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -54,7 +54,7 @@ public class GetDrivesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(drives));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getDrivesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getDrivesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -90,7 +90,7 @@ public class GetDrivesQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -108,7 +108,7 @@ public class GetDrivesQueryHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+5
-5
@@ -47,7 +47,7 @@ public class GetFileSystemQueryHandlerTests
|
||||
_mockPlatformContext.Platform.Returns(platformType);
|
||||
|
||||
// Act
|
||||
FileSystemTypeResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
FileSystemTypeResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
@@ -63,7 +63,7 @@ public class GetFileSystemQueryHandlerTests
|
||||
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
|
||||
|
||||
// Act
|
||||
ValueTask<FileSystemTypeResponse> resultTask = _sut.Handle(query, CancellationToken.None);
|
||||
Task<FileSystemTypeResponse> resultTask = _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(resultTask.IsCompleted);
|
||||
@@ -81,8 +81,8 @@ public class GetFileSystemQueryHandlerTests
|
||||
_mockPlatformContext.Platform.Returns(PlatformType.Windows);
|
||||
|
||||
// Act
|
||||
FileSystemTypeResponse result1 = await _sut.Handle(query1, CancellationToken.None);
|
||||
FileSystemTypeResponse result2 = await _sut.Handle(query2, CancellationToken.None);
|
||||
FileSystemTypeResponse result1 = await _sut.HandleAsync(query1, CancellationToken.None);
|
||||
FileSystemTypeResponse result2 = await _sut.HandleAsync(query2, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(result1.PlatformType, result2.PlatformType);
|
||||
@@ -99,7 +99,7 @@ public class GetFileSystemQueryHandlerTests
|
||||
|
||||
// Act & Assert
|
||||
Exception? exception = await Record.ExceptionAsync(async () =>
|
||||
await _sut.Handle(query, cancellationToken));
|
||||
await _sut.HandleAsync(query, cancellationToken));
|
||||
Assert.Null(exception);
|
||||
_mockPlatformContextManager.Received(1).GetCurrentContext();
|
||||
}
|
||||
|
||||
+9
-5
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFi
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,7 +38,10 @@ public class GetFilesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
_sut = new GetFilesQueryHandler(_mockFileService);
|
||||
IValidator<GetFilesQuery> mockValidator = Substitute.For<IValidator<GetFilesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetFilesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetFilesQueryHandler(_mockFileService, mockValidator);
|
||||
_fileFixture = new FileFixture();
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public class GetFilesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -87,7 +91,7 @@ public class GetFilesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -119,7 +123,7 @@ public class GetFilesQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -137,7 +141,7 @@ public class GetFilesQueryHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+15
-16
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,10 +76,10 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -91,10 +90,10 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,9 +104,9 @@ public class GetFilesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -9,6 +9,7 @@ using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -37,7 +38,10 @@ public class GetTreeFilesQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockFileService = Substitute.For<IFileService>();
|
||||
_sut = new GetTreeFilesQueryHandler(_mockFileService);
|
||||
IValidator<GetTreeFilesQuery> mockValidator = Substitute.For<IValidator<GetTreeFilesQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetTreeFilesQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetTreeFilesQueryHandler(_mockFileService, mockValidator);
|
||||
_fileFixture = new FileFixture();
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -88,7 +92,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(files));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(getFilesQuery, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(getFilesQuery, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -121,7 +125,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -139,7 +143,7 @@ public class GetTreeFilesQueryHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+15
-16
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,10 +76,10 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -91,10 +90,10 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = true };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -105,9 +104,9 @@ public class GetTreeFilesQueryValidatorTests
|
||||
query = query with { IncludeHiddenElements = false };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetTreeFilesQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.IncludeHiddenElements);
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -6,6 +6,7 @@ using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
@@ -31,7 +32,10 @@ public class CombinePathCommandHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new CombinePathCommandHandler(_mockPathService);
|
||||
IValidator<CombinePathCommand> mockValidator = Substitute.For<IValidator<CombinePathCommand>>();
|
||||
mockValidator.Validate(Arg.Any<CombinePathCommand>())
|
||||
.Returns([]);
|
||||
_sut = new CombinePathCommandHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,7 +49,7 @@ public class CombinePathCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From(combinedPath));
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(combinePathCommand, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(combinePathCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -64,7 +68,7 @@ public class CombinePathCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -81,7 +85,7 @@ public class CombinePathCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From(string.Empty));
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+18
-22
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.CombinePath.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { OriginalPath = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { OriginalPath = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { OriginalPath = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.OriginalPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,11 +76,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { NewPath = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -92,11 +90,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { NewPath = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,11 +104,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { NewPath = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.NewPath)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -122,10 +118,10 @@ public class CombinePathCommandValidatorTests
|
||||
command = command with { OriginalPath = "/valid/path", NewPath = "new/segment" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CombinePathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.OriginalPath);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.NewPath);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -37,7 +38,10 @@ public class SplitPathCommandHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new SplitPathCommandHandler(_mockPathService);
|
||||
IValidator<SplitPathCommand> mockValidator = Substitute.For<IValidator<SplitPathCommand>>();
|
||||
mockValidator.Validate(Arg.Any<SplitPathCommand>())
|
||||
.Returns([]);
|
||||
_sut = new SplitPathCommandHandler(_mockPathService, mockValidator);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
}
|
||||
|
||||
@@ -53,7 +57,7 @@ public class SplitPathCommandHandlerTests
|
||||
.Returns(ErrorOrFactory.From(pathSegments));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(splitPathCommand, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(splitPathCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -78,7 +82,7 @@ public class SplitPathCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -96,7 +100,7 @@ public class SplitPathCommandHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+11
-12
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class SplitPathCommandValidatorTests
|
||||
command = command with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class SplitPathCommandValidatorTests
|
||||
command = command with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class SplitPathCommandValidatorTests
|
||||
command = command with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,9 +76,9 @@ public class SplitPathCommandValidatorTests
|
||||
command = command with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SplitPathCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+11
-7
@@ -4,6 +4,7 @@ using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
@@ -27,7 +28,10 @@ public class CheckPathExistsQueryHandlerTests
|
||||
public CheckPathExistsQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new CheckPathExistsQueryHandler(_mockPathService);
|
||||
IValidator<CheckPathExistsQuery> mockValidator = Substitute.For<IValidator<CheckPathExistsQuery>>();
|
||||
mockValidator.Validate(Arg.Any<CheckPathExistsQuery>())
|
||||
.Returns([]);
|
||||
_sut = new CheckPathExistsQueryHandler(_mockPathService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -38,7 +42,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -54,7 +58,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
_mockPathService.Exists(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -70,7 +74,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
_mockPathService.Exists(query.Path!, false).Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -86,7 +90,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
_mockPathService.Exists(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -102,7 +106,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(false);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -119,7 +123,7 @@ public class CheckPathExistsQueryHandlerTests
|
||||
CancellationToken cancellationToken = new(true);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathExistsResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathExistsResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+11
-12
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class CheckPathExistsQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class CheckPathExistsQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class CheckPathExistsQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,9 +76,9 @@ public class CheckPathExistsQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<CheckPathExistsQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -8,6 +8,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPat
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -33,7 +34,10 @@ public class GetPathParentQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new GetPathParentQueryHandler(_mockPathService);
|
||||
IValidator<GetPathParentQuery> mockValidator = Substitute.For<IValidator<GetPathParentQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetPathParentQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetPathParentQueryHandler(_mockPathService, mockValidator);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
}
|
||||
|
||||
@@ -52,7 +56,7 @@ public class GetPathParentQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(pathSegments));
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -71,7 +75,7 @@ public class GetPathParentQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -89,7 +93,7 @@ public class GetPathParentQueryHandlerTests
|
||||
.Returns(emptyList);
|
||||
|
||||
// Act
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<IEnumerable<PathSegmentResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+11
-12
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathParent.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class GetPathParentQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class GetPathParentQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class GetPathParentQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,9 +76,9 @@ public class GetPathParentQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathParentQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -6,6 +6,7 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPat
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
@@ -30,7 +31,10 @@ public class GetPathRootQueryHandlerTests
|
||||
public GetPathRootQueryHandlerTests()
|
||||
{
|
||||
_mockPathService = Substitute.For<IPathService>();
|
||||
_sut = new GetPathRootQueryHandler(_mockPathService);
|
||||
IValidator<GetPathRootQuery> mockValidator = Substitute.For<IValidator<GetPathRootQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetPathRootQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetPathRootQueryHandler(_mockPathService, mockValidator);
|
||||
_pathSegmentFixture = new PathSegmentFixture();
|
||||
}
|
||||
|
||||
@@ -45,7 +49,7 @@ public class GetPathRootQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(pathSegment));
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -64,7 +68,7 @@ public class GetPathRootQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -83,7 +87,7 @@ public class GetPathRootQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(rootPathSegment));
|
||||
|
||||
// Act
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<PathSegmentResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+11
-12
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.GetPathRoot.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class GetPathRootQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class GetPathRootQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class GetPathRootQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,9 +76,9 @@ public class GetPathRootQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetPathRootQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -38,7 +38,7 @@ public class GetPathSeparatorQueryHandlerTests
|
||||
_mockPathService.PathSeparator.Returns(expectedSeparator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
@@ -57,7 +57,7 @@ public class GetPathSeparatorQueryHandlerTests
|
||||
_mockPathService.PathSeparator.Returns(separator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathSeparatorResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(result);
|
||||
@@ -74,8 +74,8 @@ public class GetPathSeparatorQueryHandlerTests
|
||||
_mockPathService.PathSeparator.Returns(expectedSeparator);
|
||||
|
||||
// Act
|
||||
PathSeparatorResponse result1 = await _sut.Handle(query, CancellationToken.None);
|
||||
PathSeparatorResponse result2 = await _sut.Handle(query, CancellationToken.None);
|
||||
PathSeparatorResponse result1 = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
PathSeparatorResponse result2 = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(result1, result2);
|
||||
@@ -91,7 +91,7 @@ public class GetPathSeparatorQueryHandlerTests
|
||||
|
||||
// Act
|
||||
Exception? exception = await Record.ExceptionAsync(
|
||||
async () => await _sut.Handle(query, cts.Token)
|
||||
async () => await _sut.HandleAsync(query, cts.Token)
|
||||
);
|
||||
|
||||
// Assert
|
||||
|
||||
+4
-4
@@ -37,7 +37,7 @@ public class ValidatePathQueryHandlerTests
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(true);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsValid);
|
||||
@@ -52,7 +52,7 @@ public class ValidatePathQueryHandlerTests
|
||||
_mockPathService.IsValidPath(query.Path!).Returns(false);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsValid);
|
||||
@@ -67,7 +67,7 @@ public class ValidatePathQueryHandlerTests
|
||||
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsValid);
|
||||
@@ -82,7 +82,7 @@ public class ValidatePathQueryHandlerTests
|
||||
_mockPathService.IsValidPath(Arg.Any<string>()).Returns(false);
|
||||
|
||||
// Act
|
||||
PathValidResponse result = await _sut.Handle(query, CancellationToken.None);
|
||||
PathValidResponse result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsValid);
|
||||
|
||||
+11
-12
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.ValidatePath.Fixtures;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -32,11 +34,10 @@ public class ValidatePathQueryValidatorTests
|
||||
query = query with { Path = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,11 +48,10 @@ public class ValidatePathQueryValidatorTests
|
||||
query = query with { Path = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -62,11 +62,10 @@ public class ValidatePathQueryValidatorTests
|
||||
query = query with { Path = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path)
|
||||
.WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -77,9 +76,9 @@ public class ValidatePathQueryValidatorTests
|
||||
query = query with { Path = "/valid/path" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<ValidatePathQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -6,6 +6,7 @@ using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbna
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
@@ -28,7 +29,10 @@ public class GetThumbnailQueryHandlerTests
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockThumbnailService = Substitute.For<IThumbnailService>();
|
||||
_sut = new GetThumbnailQueryHandler(_mockThumbnailService);
|
||||
IValidator<GetThumbnailQuery> mockValidator = Substitute.For<IValidator<GetThumbnailQuery>>();
|
||||
mockValidator.Validate(Arg.Any<GetThumbnailQuery>())
|
||||
.Returns([]);
|
||||
_sut = new GetThumbnailQueryHandler(_mockThumbnailService, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -42,7 +46,7 @@ public class GetThumbnailQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(thumbnail));
|
||||
|
||||
// Act
|
||||
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -62,7 +66,7 @@ public class GetThumbnailQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<ThumbnailResponse> result = await _sut.Handle(query, CancellationToken.None);
|
||||
ErrorOr<ThumbnailResponse> result = await _sut.HandleAsync(query, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -82,7 +86,7 @@ public class GetThumbnailQueryHandlerTests
|
||||
.Returns(Task.FromCanceled<ErrorOr<Thumbnail>>(cts.Token));
|
||||
|
||||
// Act & Assert
|
||||
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.Handle(query, cts.Token).AsTask());
|
||||
await Assert.ThrowsAsync<TaskCanceledException>(() => _sut.HandleAsync(query, cts.Token));
|
||||
await _mockThumbnailService.Received(1).GetThumbnailAsync(query.Path!, query.Quality, cts.Token);
|
||||
}
|
||||
}
|
||||
+15
-13
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Domain.SharedKernel.Common.Errors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -30,10 +32,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new(null!, 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -43,10 +45,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new(string.Empty, 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Path).WithErrorMessage(Errors.FileSystemManagement.PathCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -56,10 +58,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new("test", 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Path);
|
||||
result.ShouldNotHaveValidationError(Errors.FileSystemManagement.PathCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -69,10 +71,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new("test", -1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred.Description);
|
||||
result.ShouldHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,10 +84,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new("test", 101);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Quality).WithErrorMessage(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred.Description);
|
||||
result.ShouldHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -95,10 +97,10 @@ public class GetThumbnailQueryValidatorTests
|
||||
GetThumbnailQuery query = new("test", 1);
|
||||
|
||||
// Act
|
||||
TestValidationResult<GetThumbnailQuery> result = _validator.TestValidate(query);
|
||||
List<Error> result = _validator.TestValidate(query);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Quality);
|
||||
result.ShouldNotHaveValidationError(Errors.Thumbnails.ImageQualityMustBeBetweenZeroAndOneHundred);
|
||||
}
|
||||
|
||||
}
|
||||
+16
-11
@@ -8,6 +8,7 @@ using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Common.Infrastructure.Authentication;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Common.Infrastructure.Time;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
|
||||
@@ -53,6 +54,9 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
|
||||
_mockDataSeedService = Substitute.For<IDataSeedService>();
|
||||
_setupApplicationCommandFixture = new SetupApplicationCommandFixture();
|
||||
IValidator<SetupApplicationCommand> mockValidator = Substitute.For<IValidator<SetupApplicationCommand>>();
|
||||
mockValidator.Validate(Arg.Any<SetupApplicationCommand>())
|
||||
.Returns([]);
|
||||
|
||||
_mockUnitOfWork.GetRepository<IUserRepository>().Returns(_mockUserRepository);
|
||||
_mockDateTimeProvider.UtcNow.Returns(DateTime.UtcNow);
|
||||
@@ -64,7 +68,8 @@ public class SetupApplicationCommandHandlerTests
|
||||
_mockTotpTokenGenerator,
|
||||
_mockQRCodeGenerator,
|
||||
_mockDateTimeProvider,
|
||||
_mockDataSeedService);
|
||||
_mockDataSeedService,
|
||||
mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -82,7 +87,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -119,7 +124,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -143,7 +148,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(new[] { existingUser });
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -165,7 +170,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -189,7 +194,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -215,7 +220,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -242,7 +247,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -272,7 +277,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -305,7 +310,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -337,7 +342,7 @@ public class SetupApplicationCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<RegistrationResponse> result = await _sut.Handle(command, CancellationToken.None);
|
||||
ErrorOr<RegistrationResponse> result = await _sut.HandleAsync(command, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+31
-40
@@ -1,8 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentValidation.TestHelper;
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Errors;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.Maintenance.ApplicationSetup.Commands.SetupApplication.Fixtures;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -34,11 +36,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = null };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -49,11 +50,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -64,11 +64,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Username = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username)
|
||||
.WithErrorMessage(Errors.Authentication.UsernameCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -79,11 +78,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -94,11 +92,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -109,11 +106,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -124,11 +120,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = null! };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -139,11 +134,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = string.Empty };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -154,11 +148,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = " " };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.PasswordConfirm)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordConfirmCannotBeEmpty.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -169,11 +162,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { PasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.PasswordsNotMatch.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.PasswordsNotMatch);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -190,11 +182,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password)
|
||||
.WithErrorMessage(Errors.Authentication.InvalidPassword.Description);
|
||||
result.ShouldHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -209,10 +200,10 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = password, PasswordConfirm = password };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -223,11 +214,11 @@ public class SetupApplicationCommandValidatorTests
|
||||
command = command with { Password = "$321Bcda", PasswordConfirm = "$321Bcda" };
|
||||
|
||||
// Act
|
||||
TestValidationResult<SetupApplicationCommand> result = _validator.TestValidate(command);
|
||||
List<Error> result = _validator.TestValidate(command);
|
||||
|
||||
// Assert
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Username);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.Password);
|
||||
result.ShouldNotHaveValidationErrorFor(x => x.PasswordConfirm);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.UsernameCannotBeEmpty);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.InvalidPassword);
|
||||
result.ShouldNotHaveValidationError(Errors.Authentication.PasswordConfirmCannotBeEmpty);
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -48,7 +48,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(users.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsInitialized);
|
||||
@@ -63,7 +63,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<UserEntity>()));
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
@@ -79,7 +79,7 @@ public class CheckInitializationQueryHandlerTests
|
||||
.Returns(error);
|
||||
|
||||
// Act
|
||||
InitializationResponse result = await _sut.Handle(new CheckInitializationQuery(), CancellationToken.None);
|
||||
InitializationResponse result = await _sut.HandleAsync(new CheckInitializationQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsInitialized);
|
||||
|
||||
+14
-10
@@ -5,6 +5,7 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
@@ -48,7 +49,10 @@ public class AddBookCommandHandlerTests
|
||||
|
||||
_mockUnitOfWork.GetRepository<IBookRepository>().Returns(_mockBookRepository);
|
||||
|
||||
_sut = new AddBookCommandHandler(_mockUnitOfWork);
|
||||
IValidator<AddBookCommand> mockValidator = Substitute.For<IValidator<AddBookCommand>>();
|
||||
mockValidator.Validate(Arg.Any<AddBookCommand>())
|
||||
.Returns([]);
|
||||
_sut = new AddBookCommandHandler(_mockUnitOfWork, mockValidator);
|
||||
_commandBookFixture = new AddBookCommandFixture();
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ public class AddBookCommandHandlerTests
|
||||
.Returns(Result.Created);
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -81,7 +85,7 @@ public class AddBookCommandHandlerTests
|
||||
.Returns(Errors.WrittenContent.BookAlreadyExists);
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -98,7 +102,7 @@ public class AddBookCommandHandlerTests
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -115,7 +119,7 @@ public class AddBookCommandHandlerTests
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -138,7 +142,7 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -161,7 +165,7 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -191,7 +195,7 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -214,7 +218,7 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
@@ -237,7 +241,7 @@ public class AddBookCommandHandlerTests
|
||||
};
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
ErrorOr<BookResponse> result = await _sut.HandleAsync(bookCommand, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+259
-257
File diff suppressed because it is too large.
Load diff
+6
-2
@@ -3,6 +3,7 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
using Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
|
||||
using NSubstitute;
|
||||
@@ -31,7 +32,10 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>().Returns(_mockConfigurationRepository);
|
||||
_sut = new ReorderLibraryMetadataProvidersCommandHandler(_mockUnitOfWork);
|
||||
IValidator<ReorderLibraryMetadataProvidersCommand> mockValidator = Substitute.For<IValidator<ReorderLibraryMetadataProvidersCommand>>();
|
||||
mockValidator.Validate(Arg.Any<ReorderLibraryMetadataProvidersCommand>())
|
||||
.Returns([]);
|
||||
_sut = new ReorderLibraryMetadataProvidersCommandHandler(_mockUnitOfWork, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,7 +52,7 @@ public class ReorderLibraryMetadataProvidersCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new ReorderLibraryMetadataProvidersCommand(libraryId, [secondProvider.PluginId, firstProvider.PluginId]), CancellationToken.None);
|
||||
ErrorOr<Success> result = await _sut.HandleAsync(new ReorderLibraryMetadataProvidersCommand(libraryId, [secondProvider.PluginId, firstProvider.PluginId]), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+7
-3
@@ -3,6 +3,7 @@ using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -30,7 +31,10 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
|
||||
_mockUnitOfWork.GetRepository<ILibraryMetadataProviderConfigurationRepository>().Returns(_mockConfigurationRepository);
|
||||
_sut = new SetLibraryMetadataProviderEnabledCommandHandler(_mockUnitOfWork);
|
||||
IValidator<SetLibraryMetadataProviderEnabledCommand> mockValidator = Substitute.For<IValidator<SetLibraryMetadataProviderEnabledCommand>>();
|
||||
mockValidator.Validate(Arg.Any<SetLibraryMetadataProviderEnabledCommand>())
|
||||
.Returns([]);
|
||||
_sut = new SetLibraryMetadataProviderEnabledCommandHandler(_mockUnitOfWork, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -47,7 +51,7 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new SetLibraryMetadataProviderEnabledCommand(libraryId, pluginId, true), CancellationToken.None);
|
||||
ErrorOr<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(libraryId, pluginId, true), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -77,7 +81,7 @@ public class SetLibraryMetadataProviderEnabledCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new SetLibraryMetadataProviderEnabledCommand(existingConfiguration.LibraryId, existingConfiguration.PluginId, true), CancellationToken.None);
|
||||
ErrorOr<Success> result = await _sut.HandleAsync(new SetLibraryMetadataProviderEnabledCommand(existingConfiguration.LibraryId, existingConfiguration.PluginId, true), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+6
-2
@@ -2,6 +2,7 @@
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Common.Infrastructure.Validation;
|
||||
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -29,7 +30,10 @@ public class UpdatePluginSettingsCommandHandlerTests
|
||||
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
|
||||
_mockPluginRepository = Substitute.For<IPluginRepository>();
|
||||
_mockUnitOfWork.GetRepository<IPluginRepository>().Returns(_mockPluginRepository);
|
||||
_sut = new UpdatePluginSettingsCommandHandler(_mockUnitOfWork);
|
||||
IValidator<UpdatePluginSettingsCommand> mockValidator = Substitute.For<IValidator<UpdatePluginSettingsCommand>>();
|
||||
mockValidator.Validate(Arg.Any<UpdatePluginSettingsCommand>())
|
||||
.Returns([]);
|
||||
_sut = new UpdatePluginSettingsCommandHandler(_mockUnitOfWork, mockValidator);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -42,7 +46,7 @@ public class UpdatePluginSettingsCommandHandlerTests
|
||||
.Returns(Result.Updated);
|
||||
|
||||
// Act
|
||||
ErrorOr<Success> result = await _sut.Handle(new UpdatePluginSettingsCommand(pluginId, settings), CancellationToken.None);
|
||||
ErrorOr<Success> result = await _sut.HandleAsync(new UpdatePluginSettingsCommand(pluginId, settings), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ public class GetPluginsQueryHandlerTests
|
||||
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(plugins);
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.Handle(new GetPluginsQuery(), CancellationToken.None);
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsError);
|
||||
@@ -61,7 +61,7 @@ public class GetPluginsQueryHandlerTests
|
||||
.Returns(Error.Failure(description: "Failed to get plugins"));
|
||||
|
||||
// Act
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.Handle(new GetPluginsQuery(), CancellationToken.None);
|
||||
ErrorOr<IReadOnlyList<PluginResponse>> result = await _sut.HandleAsync(new GetPluginsQuery(), CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsError);
|
||||
|
||||
+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