Replaces FluentValidation and Mediator command/queries handling with custom implementations.

This commit is contained in:
BinaryAlley committed 2026-08-13 08:53:06 -07:00
1 parent 9a5c7473f9
commit 2d1c6b1ab8
297 files changed
+3619 -3045

No files matched your search

@@ -1,16 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using Mediator;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Behaviors.Fixtures;
/// <summary>
/// Fixture class for the <see cref="ValidationBehavior"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidationBehaviorFixture : IRequest<ErrorOr<ValidationBehaviorTestResponse>>
{
}
@@ -1,13 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Behaviors.Fixtures;
/// <summary>
/// Fixture test class for validation behavior responses.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidationBehaviorTestResponse
{
}
@@ -1,99 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentValidation;
using FluentValidation.Results;
using Lumina.Application.Common.Behaviors;
using Lumina.Application.UnitTests.Common.Behaviors.Fixtures;
using Mediator;
using NSubstitute;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Common.Behaviors;
/// <summary>
/// Contains unit tests for the <see cref="ValidationBehavior"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidationBehaviorTests
{
private readonly IValidator<ValidationBehaviorFixture> _mockValidator;
private readonly MessageHandlerDelegate<ValidationBehaviorFixture, ErrorOr<ValidationBehaviorTestResponse>> _nextDelegate;
/// <summary>
/// Initializes a new instance of the <see cref="ValidationBehaviorTests"/> class.
/// </summary>
public ValidationBehaviorTests()
{
_mockValidator = Substitute.For<IValidator<ValidationBehaviorFixture>>();
_nextDelegate = Substitute.For<MessageHandlerDelegate<ValidationBehaviorFixture, ErrorOr<ValidationBehaviorTestResponse>>>();
}
[Fact]
public async Task Handle_WhenValidatorIsNull_ShouldInvokeNextDelegate()
{
// Arrange
ValidationBehavior<ValidationBehaviorFixture, ErrorOr<ValidationBehaviorTestResponse>> behavior = new();
ValidationBehaviorFixture request = new();
ValidationBehaviorTestResponse expectedResponse = new();
_nextDelegate.Invoke(request, Arg.Any<CancellationToken>()).Returns(new ValueTask<ErrorOr<ValidationBehaviorTestResponse>>(ErrorOrFactory.From(expectedResponse)));
// Act
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
[Fact]
public async Task Handle_WhenValidationSucceeds_ShouldInvokeNextDelegate()
{
// Arrange
ValidationBehavior<ValidationBehaviorFixture, ErrorOr<ValidationBehaviorTestResponse>> behavior = new(_mockValidator);
ValidationBehaviorFixture request = new();
ValidationBehaviorTestResponse expectedResponse = new();
_mockValidator.ValidateAsync(request, Arg.Any<CancellationToken>()).Returns(new ValidationResult());
_nextDelegate.Invoke(request, Arg.Any<CancellationToken>()).Returns(new ValueTask<ErrorOr<ValidationBehaviorTestResponse>>(ErrorOrFactory.From(expectedResponse)));
// Act
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
Assert.False(result.IsError);
Assert.Equal(expectedResponse, result.Value);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.Received(1).Invoke(request, Arg.Any<CancellationToken>());
}
[Fact]
public async Task Handle_WhenValidationFails_ShouldReturnErrors()
{
// Arrange
ValidationBehavior<ValidationBehaviorFixture, ErrorOr<ValidationBehaviorTestResponse>> behavior = new(_mockValidator);
ValidationBehaviorFixture request = new();
List<ValidationFailure> validationFailures =
[
new ValidationFailure("Property1", "Error message 1"),
new ValidationFailure("Property2", "Error message 2")
];
_mockValidator.ValidateAsync(request, Arg.Any<CancellationToken>()).Returns(new ValidationResult(validationFailures));
// Act
ErrorOr<ValidationBehaviorTestResponse> result = await behavior.Handle(request, _nextDelegate, CancellationToken.None);
// Assert
Assert.True(result.IsError);
Assert.Equal(2, result.Errors.Count);
Assert.Equal(ErrorType.Validation, result.Errors[0].Type);
Assert.Equal("Error message 1", result.Errors[0].Description);
Assert.Equal(ErrorType.Validation, result.Errors[1].Type);
Assert.Equal("Error message 2", result.Errors[1].Description);
await _mockValidator.Received(1).ValidateAsync(request, Arg.Any<CancellationToken>());
await _nextDelegate.DidNotReceive().Invoke(request, Arg.Any<CancellationToken>());
}
}
@@ -30,7 +30,7 @@ public static class ValidatorTestExtensions
/// <param name="expectedError">The error that should not be present in the validation results.</param>
public static void ShouldNotHaveValidationError(this List<Error> errors, Error expectedError)
{
Assert.DoesNotContain(errors, error => error.Code == expectedError.Code);
Assert.DoesNotContain(errors, error => error.Description == expectedError.Description);
}
/// <summary>
@@ -40,7 +40,7 @@ public static class ValidatorTestExtensions
/// <param name="expectedError">The error that should be present in the validation results.</param>
public static void ShouldHaveValidationError(this List<Error> errors, Error expectedError)
{
Assert.Contains(errors, error => error.Code == expectedError.Code);
Assert.Contains(errors, error => error.Description == expectedError.Description);
}
/// <summary>
@@ -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,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;
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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,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;
@@ -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);
@@ -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);
@@ -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();
}
}
@@ -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);
@@ -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();
}
@@ -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);
@@ -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,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);
@@ -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();
}
}
@@ -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);
@@ -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,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);
@@ -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);
}
}
@@ -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);
@@ -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,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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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
@@ -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);
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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();
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -5,10 +5,10 @@ using System.Diagnostics.CodeAnalysis;
namespace Lumina.Infrastructure.UnitTests.Common.Utilities.Fixtures;
/// <summary>
/// Contains unit tests for the <see cref="OptionsBuilderFluentValidationUtilitiesTests"/> class.
/// Contains unit tests for the <see cref="OptionsBuilderValidationUtilitiesTests"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionsBuilderFluentValidationUtilitiesFixture
public class OptionsBuilderValidationUtilitiesFixture
{
}
}
@@ -1,7 +1,7 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentValidation;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Infrastructure.Common.Utilities;
using Lumina.Infrastructure.Common.Validation;
using Lumina.Infrastructure.UnitTests.Common.Utilities.Fixtures;
@@ -16,17 +16,17 @@ using System.Linq;
namespace Lumina.Infrastructure.UnitTests.Common.Utilities;
/// <summary>
/// Contains unit tests for the <see cref="OptionsBuilderFluentValidationUtilities"/> class.
/// Contains unit tests for the <see cref="OptionsBuilderValidationUtilities"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionsBuilderFluentValidationUtilitiesTests
public class OptionsBuilderValidationUtilitiesTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="OptionsBuilderFluentValidationUtilitiesTests"/> class.
/// Initializes a new instance of the <see cref="OptionsBuilderValidationUtilitiesTests"/> class.
/// </summary>
public OptionsBuilderFluentValidationUtilitiesTests()
public OptionsBuilderValidationUtilitiesTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
@@ -37,15 +37,15 @@ public class OptionsBuilderFluentValidationUtilitiesTests
// Arrange
IServiceCollection services = Substitute.For<IServiceCollection>();
string name = _fixture.Create<string>();
OptionsBuilder<OptionsBuilderFluentValidationUtilitiesFixture> optionsBuilder = new(services, name);
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> optionsBuilder = new(services, name);
// Act
OptionsBuilder<OptionsBuilderFluentValidationUtilitiesFixture> result = optionsBuilder.ValidateFluently();
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> result = optionsBuilder.ValidateFluently();
// Assert
Assert.Same(optionsBuilder, result);
services.Received(1).Add(Arg.Is<ServiceDescriptor>(sd =>
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>) &&
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderValidationUtilitiesFixture>) &&
sd.Lifetime == ServiceLifetime.Singleton &&
sd.ImplementationFactory != null));
}
@@ -56,14 +56,14 @@ public class OptionsBuilderFluentValidationUtilitiesTests
// Arrange
ServiceCollection services = new();
string name = _fixture.Create<string>();
OptionsBuilder<OptionsBuilderFluentValidationUtilitiesFixture> optionsBuilder = new(services, name);
OptionsBuilder<OptionsBuilderValidationUtilitiesFixture> optionsBuilder = new(services, name);
// Act
optionsBuilder.ValidateFluently();
// Assert
ServiceDescriptor? serviceDescriptor = services.FirstOrDefault(sd =>
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderFluentValidationUtilitiesFixture>) &&
sd.ServiceType == typeof(IValidateOptions<OptionsBuilderValidationUtilitiesFixture>) &&
sd.Lifetime == ServiceLifetime.Singleton &&
sd.ImplementationFactory != null);
@@ -73,12 +73,12 @@ public class OptionsBuilderFluentValidationUtilitiesTests
Assert.NotNull(implementationFactory);
IServiceProvider serviceProvider = Substitute.For<IServiceProvider>();
IValidator<OptionsBuilderFluentValidationUtilitiesFixture> mockValidator = Substitute.For<IValidator<OptionsBuilderFluentValidationUtilitiesFixture>>();
serviceProvider.GetService(typeof(IValidator<OptionsBuilderFluentValidationUtilitiesFixture>))
IValidator<OptionsBuilderValidationUtilitiesFixture> mockValidator = Substitute.For<IValidator<OptionsBuilderValidationUtilitiesFixture>>();
serviceProvider.GetService(typeof(IValidator<OptionsBuilderValidationUtilitiesFixture>))
.Returns(mockValidator);
FluentValidationOptions<OptionsBuilderFluentValidationUtilitiesFixture>? fluentValidationOptions = implementationFactory!(serviceProvider) as FluentValidationOptions<OptionsBuilderFluentValidationUtilitiesFixture>;
Assert.NotNull(fluentValidationOptions);
Assert.Equal(name, fluentValidationOptions.Name);
ValidationOptions<OptionsBuilderValidationUtilitiesFixture>? validationOptions = implementationFactory!(serviceProvider) as ValidationOptions<OptionsBuilderValidationUtilitiesFixture>;
Assert.NotNull(validationOptions);
Assert.Equal(name, validationOptions.Name);
}
}
@@ -5,10 +5,10 @@ using System.Diagnostics.CodeAnalysis;
namespace Lumina.Infrastructure.UnitTests.Common.Validation.Fixtures;
/// <summary>
/// Contains unit tests for the <see cref="FluentValidationOptionsTests"/> class.
/// Contains unit tests for the <see cref="ValidationOptionsTests"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FluentValidationOptionsFixture
public class ValidationOptionsFixture
{
}
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentValidation;
using FluentValidation.Results;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Infrastructure.Common.Validation;
using Lumina.Infrastructure.UnitTests.Common.Validation.Fixtures;
using Microsoft.Extensions.Options;
@@ -15,17 +15,17 @@ using System.Diagnostics.CodeAnalysis;
namespace Lumina.Infrastructure.UnitTests.Common.Validation;
/// <summary>
/// Contains unit tests for the <see cref="FluentValidationOptions"/> class.
/// Contains unit tests for the <see cref="ValidationOptions"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class FluentValidationOptionsTests
public class ValidationOptionsTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="FluentValidationOptionsTests"/> class.
/// Initializes a new instance of the <see cref="ValidationOptionsTests"/> class.
/// </summary>
public FluentValidationOptionsTests()
public ValidationOptionsTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
@@ -35,10 +35,10 @@ public class FluentValidationOptionsTests
{
// Arrange
string name = _fixture.Create<string>();
FluentValidationOptionsFixture options = _fixture.Create<FluentValidationOptionsFixture>();
IValidator<FluentValidationOptionsFixture> validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
validator.Validate(options).Returns(new ValidationResult());
FluentValidationOptions<FluentValidationOptionsFixture> sut = new(name, validator);
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
// Act
ValidateOptionsResult result = sut.Validate(name, options);
@@ -55,9 +55,9 @@ public class FluentValidationOptionsTests
// Arrange
string name = _fixture.Create<string>();
string differentName = _fixture.Create<string>();
FluentValidationOptionsFixture options = _fixture.Create<FluentValidationOptionsFixture>();
IValidator<FluentValidationOptionsFixture> validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
FluentValidationOptions<FluentValidationOptionsFixture> sut = new(name, validator);
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
// Act
ValidateOptionsResult result = sut.Validate(differentName, options);
@@ -71,10 +71,10 @@ public class FluentValidationOptionsTests
public void Validate_WhenNullName_ShouldValidateOptions()
{
// Arrange
FluentValidationOptionsFixture options = _fixture.Create<FluentValidationOptionsFixture>();
IValidator<FluentValidationOptionsFixture> validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
validator.Validate(options).Returns(new ValidationResult());
FluentValidationOptions<FluentValidationOptionsFixture> sut = new(null, validator);
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<ValidationOptionsFixture> sut = new(null, validator);
// Act
ValidateOptionsResult result = sut.Validate(_fixture.Create<string>(), options);
@@ -90,8 +90,8 @@ public class FluentValidationOptionsTests
{
// Arrange
string name = _fixture.Create<string>();
IValidator<FluentValidationOptionsFixture> validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
FluentValidationOptions<FluentValidationOptionsFixture> sut = new(name, validator);
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
// Act
Action act = () => sut.Validate(name, null!);
@@ -105,14 +105,14 @@ public class FluentValidationOptionsTests
{
// Arrange
string name = _fixture.Create<string>();
FluentValidationOptionsFixture options = _fixture.Create<FluentValidationOptionsFixture>();
IValidator<FluentValidationOptionsFixture> validator = Substitute.For<IValidator<FluentValidationOptionsFixture>>();
List<ValidationFailure> validationFailures =
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
List<Error> validationFailures =
[
new("PropertyName", "Error Message")
Error.Validation("PropertyName", "Error Message")
];
validator.Validate(options).Returns(new ValidationResult(validationFailures));
FluentValidationOptions<FluentValidationOptionsFixture> sut = new(name, validator);
validator.Validate(options).Returns(validationFailures);
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
// Act
ValidateOptionsResult result = sut.Validate(name, options);
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using Lumina.Infrastructure.Common.Validators;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -36,11 +38,10 @@ public class CommonSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -52,11 +53,10 @@ public class CommonSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.ApplicationThemeCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.ApplicationThemeCannotBeEmpty.Description, result[0].Description);
}
}
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using Lumina.Infrastructure.Common.Validators;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -36,11 +38,10 @@ public class DatabaseSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -52,11 +53,10 @@ public class DatabaseSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.DatabaseConnectionStringCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.DatabaseConnectionStringCannotBeEmpty.Description, result[0].Description);
}
}
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using Lumina.Infrastructure.Common.Validators;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -36,11 +38,10 @@ public class EncryptionSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -52,12 +53,11 @@ public class EncryptionSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.EncryptionSecretKeyCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.EncryptionSecretKeyCannotBeEmpty.Description, result[0].Description);
}
[Theory]
@@ -72,11 +72,10 @@ public class EncryptionSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.EncryptionSecretKeyMustBeABase64String.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.EncryptionSecretKeyMustBeABase64String.Description, result[0].Description);
}
}
@@ -1,11 +1,12 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using Lumina.Infrastructure.Common.Validators;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Infrastructure.UnitTests.Common.Validators;
@@ -40,11 +41,10 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -59,13 +59,12 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Equal(2, result.Errors.Count);
Assert.Contains(Errors.Configuration.JwtSecretKeyCannotBeEmpty.Description, result.Errors.Select(e => e.ErrorMessage));
Assert.Contains(Errors.Configuration.JwtSecretKeyTooShort.Description, result.Errors.Select(e => e.ErrorMessage));
Assert.Equal(2, result.Count);
Assert.Contains(result, error => error.Description == Errors.Configuration.JwtSecretKeyCannotBeEmpty.Description);
Assert.Contains(result, error => error.Description == Errors.Configuration.JwtSecretKeyTooShort.Description);
}
[Fact]
@@ -80,12 +79,11 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.JwtSecretKeyTooShort.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.JwtSecretKeyTooShort.Description, result[0].Description);
}
[Theory]
@@ -103,12 +101,11 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.JwtExpiryMinutesMustBePositive.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.JwtExpiryMinutesMustBePositive.Description, result[0].Description);
}
[Fact]
@@ -123,12 +120,11 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.JwtIssuerCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.JwtIssuerCannotBeEmpty.Description, result[0].Description);
}
[Fact]
@@ -143,11 +139,10 @@ public class JwtSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.JwtAudienceCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.JwtAudienceCannotBeEmpty.Description, result[0].Description);
}
}
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
using Lumina.Infrastructure.Common.Errors;
using Lumina.Infrastructure.Common.Validators;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
@@ -36,11 +38,10 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -52,12 +53,11 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
}
[Fact]
@@ -69,12 +69,11 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.MediaRootDirectoryCannotBeEmpty.Description, result[0].Description);
}
[Fact]
@@ -86,12 +85,11 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
}
[Fact]
@@ -103,11 +101,10 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.True(result.IsValid);
Assert.Empty(result.Errors);
Assert.Empty(result);
}
[Fact]
@@ -119,11 +116,10 @@ public class MediaSettingsDtoValidatorTests
.Create();
// Act
FluentValidation.Results.ValidationResult result = _validator.Validate(model);
List<Error> result = _validator.Validate(model);
// Assert
Assert.False(result.IsValid);
Assert.Single(result.Errors);
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result.Errors[0].ErrorMessage);
Assert.Single(result);
Assert.Equal(Errors.Configuration.MediaLibrariesDirectoryCannotBeEmpty.Description, result[0].Description);
}
}
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Admin.Authorization.Permissions.Queries.GetPermissions;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Permissions.GetPermissions;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Admin.Authorization.P
[ExcludeFromCodeCoverage]
public class GetPermissionsEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>> _mockHandler;
private readonly GetPermissionsEndpoint _sut;
/// <summary>
@@ -33,8 +33,8 @@ public class GetPermissionsEndpointTests
/// </summary>
public GetPermissionsEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetPermissionsEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>>>();
_sut = Factory.Create<GetPermissionsEndpoint>(_mockHandler);
}
[Fact]
@@ -48,7 +48,7 @@ public class GetPermissionsEndpointTests
new(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers),
new(Guid.NewGuid(), AuthorizationPermission.CanRegisterUsers)
];
_mockSender.Send(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -65,7 +65,7 @@ public class GetPermissionsEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Permissions.NotFound", "No permissions found.");
_mockSender.Send(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -90,16 +90,14 @@ public class GetPermissionsEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
IEnumerable<PermissionResponse> response = [];
_mockSender.Send(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(new ValueTask<ErrorOr<IEnumerable<PermissionResponse>>>(
ErrorOrFactory.From(response)
));
_mockHandler.HandleAsync(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(response));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Any<GetPermissionsQuery>(),
Arg.Is(cancellationToken));
}
@@ -112,16 +110,14 @@ public class GetPermissionsEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<IEnumerable<PermissionResponse>>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Enumerable.Empty<PermissionResponse>());
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<GetPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Enumerable.Empty<PermissionResponse>());
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.DeleteRole;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -22,7 +21,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Admin.Authorization.R
[ExcludeFromCodeCoverage]
public class DeleteRoleEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<DeleteRoleCommand, ErrorOr<Deleted>> _mockHandler;
private readonly DeleteRoleEndpoint _sut;
/// <summary>
@@ -30,8 +29,8 @@ public class DeleteRoleEndpointTests
/// </summary>
public DeleteRoleEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<DeleteRoleEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<DeleteRoleCommand, ErrorOr<Deleted>>>();
_sut = FastEndpoints.Factory.Create<DeleteRoleEndpoint>(_mockHandler);
}
[Fact]
@@ -40,7 +39,7 @@ public class DeleteRoleEndpointTests
// Arrange
DeleteRoleRequest request = new(Guid.NewGuid());
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Result.Deleted));
// Act
@@ -57,7 +56,7 @@ public class DeleteRoleEndpointTests
DeleteRoleRequest request = new(Guid.NewGuid());
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Role.Deletion.Failed", "Failed to delete role.");
_mockSender.Send(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -83,14 +82,14 @@ public class DeleteRoleEndpointTests
Guid roleId = Guid.NewGuid();
DeleteRoleRequest request = new(roleId);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Result.Deleted));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<DeleteRoleCommand>(cmd => cmd.RoleId == request.RoleId),
Arg.Is(cancellationToken));
}
@@ -103,16 +102,14 @@ public class DeleteRoleEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<Deleted>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Result.Deleted);
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Result.Deleted);
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new DeleteRoleRequest(Guid.NewGuid()), cts.Token);
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRoles;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Admin.Authorization.R
[ExcludeFromCodeCoverage]
public class GetRolesEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetRolesQuery, ErrorOr<IEnumerable<RoleResponse>>> _mockHandler;
private readonly GetRolesEndpoint _sut;
/// <summary>
@@ -31,8 +31,8 @@ public class GetRolesEndpointTests
/// </summary>
public GetRolesEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetRolesEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetRolesQuery, ErrorOr<IEnumerable<RoleResponse>>>>();
_sut = Factory.Create<GetRolesEndpoint>(_mockHandler);
}
[Fact]
@@ -44,7 +44,7 @@ public class GetRolesEndpointTests
[
new RoleResponse(Guid.NewGuid(), "Admin")
];
_mockSender.Send(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -61,7 +61,7 @@ public class GetRolesEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Roles.NotFound", "No roles found.");
_mockSender.Send(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -85,19 +85,17 @@ public class GetRolesEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(new ValueTask<ErrorOr<IEnumerable<RoleResponse>>>(
ErrorOrFactory.From(new List<RoleResponse>
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new List<RoleResponse>
{
new(Guid.NewGuid(), "Admin")
} as IEnumerable<RoleResponse>)
));
} as IEnumerable<RoleResponse>));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Any<GetRolesQuery>(),
Arg.Is(cancellationToken));
}
@@ -110,16 +108,14 @@ public class GetRolesEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<IEnumerable<RoleResponse>>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new List<RoleResponse>() as IEnumerable<RoleResponse>);
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new List<RoleResponse>() as IEnumerable<RoleResponse>);
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -1,13 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using Lumina.Contracts.DTO.Authentication;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.UpdateRole;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -27,7 +26,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Admin.Authorization.R
[ExcludeFromCodeCoverage]
public class UpdateRoleEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<UpdateRoleCommand, ErrorOr<RolePermissionsResponse>> _mockHandler;
private readonly UpdateRoleEndpoint _sut;
/// <summary>
@@ -35,8 +34,8 @@ public class UpdateRoleEndpointTests
/// </summary>
public UpdateRoleEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<UpdateRoleEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<UpdateRoleCommand, ErrorOr<RolePermissionsResponse>>>();
_sut = FastEndpoints.Factory.Create<UpdateRoleEndpoint>(_mockHandler);
}
[Fact]
@@ -49,7 +48,7 @@ public class UpdateRoleEndpointTests
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
[new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
);
_mockSender.Send(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -67,7 +66,7 @@ public class UpdateRoleEndpointTests
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Role.Update.Failed", "Failed to update role.");
_mockSender.Send(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -92,7 +91,7 @@ public class UpdateRoleEndpointTests
// Arrange
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new RolePermissionsResponse(
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
[]
@@ -102,7 +101,7 @@ public class UpdateRoleEndpointTests
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<UpdateRoleCommand>(cmd =>
cmd.RoleId == request.RoleId &&
cmd.RoleName == request.RoleName &&
@@ -118,19 +117,17 @@ public class UpdateRoleEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<RolePermissionsResponse>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RolePermissionsResponse(
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
[]
));
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RolePermissionsResponse(
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
[]
));
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(
@@ -3,11 +3,11 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetDirectories;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -28,7 +28,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
public class GetDirectoriesEndpointTests
{
private readonly IFixture _fixture;
private readonly ISender _mockSender;
private readonly IQueryHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>> _mockHandler;
private readonly GetDirectoriesEndpoint _sut;
/// <summary>
@@ -37,8 +37,8 @@ public class GetDirectoriesEndpointTests
public GetDirectoriesEndpointTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetDirectoriesEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>>>();
_sut = Factory.Create<GetDirectoriesEndpoint>(_mockHandler);
}
[Fact]
@@ -48,7 +48,7 @@ public class GetDirectoriesEndpointTests
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
List<DirectoryResponse> expectedResponses = _fixture.CreateMany<DirectoryResponse>(3).ToList();
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
// Act
@@ -66,7 +66,7 @@ public class GetDirectoriesEndpointTests
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Directory.NotFound", "The requested directory was not found.");
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -92,7 +92,7 @@ public class GetDirectoriesEndpointTests
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -117,14 +117,14 @@ public class GetDirectoriesEndpointTests
// Arrange
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<DirectoryResponse>()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<GetDirectoriesQuery>(q => q.Path == request.Path && q.IncludeHiddenElements == request.IncludeHiddenElements),
Arg.Is(cancellationToken));
}
@@ -138,14 +138,14 @@ public class GetDirectoriesEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<DirectoryResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_fixture.CreateMany<DirectoryResponse>(3).AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Drives.GetDrives;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetDrivesEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> _mockHandler;
private readonly GetDrivesEndpoint _sut;
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
@@ -34,9 +34,9 @@ public class GetDrivesEndpointTests
/// </summary>
public GetDrivesEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_mockHandler = Substitute.For<IQueryHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>>();
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
_sut = Factory.Create<GetDrivesEndpoint>(_mockSender);
_sut = Factory.Create<GetDrivesEndpoint>(_mockHandler);
}
[Fact]
@@ -45,7 +45,7 @@ public class GetDrivesEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 1, 1);
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
// Act
@@ -62,7 +62,7 @@ public class GetDrivesEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Drive.NotFound", "The requested drive was not found.");
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -86,14 +86,14 @@ public class GetDrivesEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Any<GetDrivesQuery>(), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Is(cancellationToken));
}
[Fact]
@@ -104,14 +104,14 @@ public class GetDrivesEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_fileSystemTreeNodeResponseFixture.CreateMany(3, 1, 1).AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.FileSystem.GetType;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -22,7 +22,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetFileSystemTypeEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse> _mockHandler;
private readonly GetTypeEndpoint _sut;
/// <summary>
@@ -30,8 +30,8 @@ public class GetFileSystemTypeEndpointTests
/// </summary>
public GetFileSystemTypeEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetTypeEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse>>();
_sut = Factory.Create<GetTypeEndpoint>(_mockHandler);
}
[Fact]
@@ -40,7 +40,7 @@ public class GetFileSystemTypeEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
FileSystemTypeResponse expectedResponse = new(PlatformType.Windows);
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -59,7 +59,7 @@ public class GetFileSystemTypeEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
FileSystemTypeResponse expectedResponse = new(platformType);
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -75,14 +75,14 @@ public class GetFileSystemTypeEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
.Returns(new FileSystemTypeResponse(PlatformType.Windows));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Any<GetFileSystemQuery>(), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Is(cancellationToken));
}
[Fact]
@@ -93,14 +93,14 @@ public class GetFileSystemTypeEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<FileSystemTypeResponse>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return new FileSystemTypeResponse(PlatformType.Windows);
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using Lumina.Presentation.Api.Common.Http;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Files.GetFiles;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -30,7 +30,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
public class GetFilesEndpointTests
{
private readonly IFixture _fixture;
private readonly ISender _mockSender;
private readonly IQueryHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>> _mockHandler;
private readonly GetFilesEndpoint _sut;
/// <summary>
@@ -39,8 +39,8 @@ public class GetFilesEndpointTests
public GetFilesEndpointTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetFilesEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>>>();
_sut = Factory.Create<GetFilesEndpoint>(_mockHandler);
}
[Fact]
@@ -50,7 +50,7 @@ public class GetFilesEndpointTests
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
List<FileResponse> expectedResponses = _fixture.CreateMany<FileResponse>(3).ToList();
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
// Act
@@ -68,7 +68,7 @@ public class GetFilesEndpointTests
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -94,7 +94,7 @@ public class GetFilesEndpointTests
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -119,14 +119,14 @@ public class GetFilesEndpointTests
// Arrange
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileResponse>()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Is<GetFilesQuery>(q =>
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetFilesQuery>(q =>
q.Path == request.Path &&
q.IncludeHiddenElements == request.IncludeHiddenElements),
Arg.Is(cancellationToken));
@@ -141,14 +141,14 @@ public class GetFilesEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_fixture.CreateMany<FileResponse>(3).AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -3,12 +3,12 @@ using AutoFixture;
using AutoFixture.AutoNSubstitute;
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Files.GetTreeFiles;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -29,7 +29,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
public class GetTreeFilesEndpointTests
{
private readonly IFixture _fixture;
private readonly ISender _mockSender;
private readonly IQueryHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> _mockHandler;
private readonly GetTreeFilesEndpoint _sut;
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
@@ -39,9 +39,9 @@ public class GetTreeFilesEndpointTests
public GetTreeFilesEndpointTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockSender = Substitute.For<ISender>();
_mockHandler = Substitute.For<IQueryHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>>();
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
_sut = Factory.Create<GetTreeFilesEndpoint>(_mockSender);
_sut = Factory.Create<GetTreeFilesEndpoint>(_mockHandler);
}
[Fact]
@@ -51,7 +51,7 @@ public class GetTreeFilesEndpointTests
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5);
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
// Act
@@ -69,7 +69,7 @@ public class GetTreeFilesEndpointTests
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -95,7 +95,7 @@ public class GetTreeFilesEndpointTests
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -120,14 +120,14 @@ public class GetTreeFilesEndpointTests
// Arrange
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Is<GetTreeFilesQuery>(q =>
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetTreeFilesQuery>(q =>
q.Path == request.Path &&
q.IncludeHiddenElements == request.IncludeHiddenElements),
Arg.Is(cancellationToken));
@@ -142,14 +142,14 @@ public class GetTreeFilesEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5).AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CheckPathExists;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class CheckPathExistsEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<CheckPathExistsQuery, ErrorOr<PathExistsResponse>> _mockHandler;
private readonly CheckPathExistsEndpoint _sut;
private readonly CheckPathExistsRequestFixture _checkPathExistsRequestFixture;
@@ -33,8 +33,8 @@ public class CheckPathExistsEndpointTests
/// </summary>
public CheckPathExistsEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<CheckPathExistsEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<CheckPathExistsQuery, ErrorOr<PathExistsResponse>>>();
_sut = Factory.Create<CheckPathExistsEndpoint>(_mockHandler);
_checkPathExistsRequestFixture = new CheckPathExistsRequestFixture();
}
@@ -45,7 +45,7 @@ public class CheckPathExistsEndpointTests
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
CancellationToken cancellationToken = CancellationToken.None;
PathExistsResponse expectedResponse = new(true);
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -62,14 +62,14 @@ public class CheckPathExistsEndpointTests
// Arrange
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
.Returns(new PathExistsResponse(true));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<CheckPathExistsQuery>(q => q.Path == request.Path && q.IncludeHiddenElements == request.IncludeHiddenElements),
Arg.Is(cancellationToken));
}
@@ -83,14 +83,14 @@ public class CheckPathExistsEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<PathExistsResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new PathExistsResponse(true));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CombinePath;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class CombinePathEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>> _mockHandler;
private readonly CombinePathEndpoint _sut;
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
private readonly CombinePathRequestFixture _combinePathRequestFixture;
@@ -34,8 +33,8 @@ public class CombinePathEndpointTests
/// </summary>
public CombinePathEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<CombinePathEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>>>();
_sut = FastEndpoints.Factory.Create<CombinePathEndpoint>(_mockHandler);
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
_combinePathRequestFixture = new CombinePathRequestFixture();
}
@@ -47,7 +46,7 @@ public class CombinePathEndpointTests
CombinePathRequest request = _combinePathRequestFixture.Create("C:\\Users", "TestUser");
CancellationToken cancellationToken = CancellationToken.None;
PathSegmentResponse expectedResponse = _pathSegmentResponseFixture.Create();
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -65,7 +64,7 @@ public class CombinePathEndpointTests
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -91,7 +90,7 @@ public class CombinePathEndpointTests
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -116,14 +115,14 @@ public class CombinePathEndpointTests
// Arrange
CombinePathRequest request = _combinePathRequestFixture.Create("C:\\Users", "TestUser");
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.Create()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<CombinePathCommand>(c => c.OriginalPath == request.OriginalPath && c.NewPath == request.NewPath),
Arg.Is(cancellationToken));
}
@@ -137,14 +136,14 @@ public class CombinePathEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathParent;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -26,7 +26,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetPathParentEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>> _mockHandler;
private readonly GetPathParentEndpoint _sut;
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
private readonly GetPathParentRequestFixture _getPathParentRequestFixture;
@@ -36,8 +36,8 @@ public class GetPathParentEndpointTests
/// </summary>
public GetPathParentEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetPathParentEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>>>();
_sut = Factory.Create<GetPathParentEndpoint>(_mockHandler);
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
_getPathParentRequestFixture = new GetPathParentRequestFixture();
}
@@ -49,7 +49,7 @@ public class GetPathParentEndpointTests
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
IEnumerable<PathSegmentResponse> expectedResponse = _pathSegmentResponseFixture.CreateMany();
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -67,7 +67,7 @@ public class GetPathParentEndpointTests
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -93,7 +93,7 @@ public class GetPathParentEndpointTests
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"InvalidPath");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -118,14 +118,14 @@ public class GetPathParentEndpointTests
// Arrange
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Is<GetPathParentQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetPathParentQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
}
[Fact]
@@ -137,14 +137,14 @@ public class GetPathParentEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathRoot;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetPathRootEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>> _mockHandler;
private readonly GetPathRootEndpoint _sut;
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
private readonly GetPathRootRequestFixture _getPathRootRequestFixture;
@@ -34,8 +34,8 @@ public class GetPathRootEndpointTests
/// </summary>
public GetPathRootEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetPathRootEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>>>();
_sut = Factory.Create<GetPathRootEndpoint>(_mockHandler);
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
_getPathRootRequestFixture = new GetPathRootRequestFixture();
}
@@ -47,7 +47,7 @@ public class GetPathRootEndpointTests
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
PathSegmentResponse expectedResponse = _pathSegmentResponseFixture.Create();
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -65,7 +65,7 @@ public class GetPathRootEndpointTests
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -91,7 +91,7 @@ public class GetPathRootEndpointTests
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"InvalidPath");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -116,14 +116,14 @@ public class GetPathRootEndpointTests
// Arrange
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.Create()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Is<GetPathRootQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetPathRootQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
}
[Fact]
@@ -135,14 +135,14 @@ public class GetPathRootEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathSeparator;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -22,7 +22,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetPathSeparatorEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetPathSeparatorQuery, PathSeparatorResponse> _mockHandler;
private readonly GetPathSeparatorEndpoint _sut;
private readonly PathSeparatorResponseFixture _pathSeparatorResponseFixture;
@@ -31,8 +31,8 @@ public class GetPathSeparatorEndpointTests
/// </summary>
public GetPathSeparatorEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetPathSeparatorEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetPathSeparatorQuery, PathSeparatorResponse>>();
_sut = Factory.Create<GetPathSeparatorEndpoint>(_mockHandler);
_pathSeparatorResponseFixture = new PathSeparatorResponseFixture();
}
@@ -42,7 +42,7 @@ public class GetPathSeparatorEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
PathSeparatorResponse expectedResponse = _pathSeparatorResponseFixture.Create();
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -58,14 +58,14 @@ public class GetPathSeparatorEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
.Returns(_pathSeparatorResponseFixture.Create());
// Act
await _sut.ExecuteAsync(cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Is(cancellationToken));
}
[Fact]
@@ -76,14 +76,14 @@ public class GetPathSeparatorEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<PathSeparatorResponse>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return _pathSeparatorResponseFixture.Create();
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.SplitPath;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -26,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class SplitPathEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>> _mockHandler;
private readonly SplitPathEndpoint _sut;
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
private readonly SplitPathRequestFixture _splitPathRequestFixture;
@@ -36,8 +35,8 @@ public class SplitPathEndpointTests
/// </summary>
public SplitPathEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<SplitPathEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>>>();
_sut = FastEndpoints.Factory.Create<SplitPathEndpoint>(_mockHandler);
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
_splitPathRequestFixture = new SplitPathRequestFixture();
}
@@ -49,7 +48,7 @@ public class SplitPathEndpointTests
SplitPathRequest request = _splitPathRequestFixture.Create(@"C:\Users\TestUser\Documents");
CancellationToken cancellationToken = CancellationToken.None;
IEnumerable<PathSegmentResponse> expectedResponse = _pathSegmentResponseFixture.CreateMany();
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -67,7 +66,7 @@ public class SplitPathEndpointTests
SplitPathRequest request = _splitPathRequestFixture.Create(@"InvalidPath");
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -93,14 +92,14 @@ public class SplitPathEndpointTests
// Arrange
SplitPathRequest request = _splitPathRequestFixture.Create(@"C:\Users\TestUser\Documents");
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<SplitPathCommand>(c => c.Path == request.Path),
Arg.Is(cancellationToken));
}
@@ -114,8 +113,8 @@ public class SplitPathEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
@@ -124,7 +123,7 @@ public class SplitPathEndpointTests
{
_pathSegmentResponseFixture.Create()
}.AsEnumerable());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.ValidatePath;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class ValidatePathEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<ValidatePathQuery, PathValidResponse> _mockHandler;
private readonly ValidatePathEndpoint _sut;
private readonly ValidatePathRequestFixture _validatePathRequestFixture;
@@ -32,8 +32,8 @@ public class ValidatePathEndpointTests
/// </summary>
public ValidatePathEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<ValidatePathEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<ValidatePathQuery, PathValidResponse>>();
_sut = Factory.Create<ValidatePathEndpoint>(_mockHandler);
_validatePathRequestFixture = new ValidatePathRequestFixture();
}
@@ -44,7 +44,7 @@ public class ValidatePathEndpointTests
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
CancellationToken cancellationToken = CancellationToken.None;
PathValidResponse expectedResponse = new(true);
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -61,14 +61,14 @@ public class ValidatePathEndpointTests
// Arrange
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
.Returns(new PathValidResponse(true));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<ValidatePathQuery>(q => q.Path == request.Path),
Arg.Is(cancellationToken));
}
@@ -82,14 +82,14 @@ public class ValidatePathEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<PathValidResponse>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return new PathValidResponse(true);
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Presentation.Api.Common.Utilities;
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Thumbnails.GetThumbnail;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
[ExcludeFromCodeCoverage]
public class GetThumbnailEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>> _mockHandler;
private readonly GetThumbnailEndpoint _sut;
private readonly GetThumbnailRequestFixture _getThumbnailRequestFixture;
@@ -34,8 +34,8 @@ public class GetThumbnailEndpointTests
/// </summary>
public GetThumbnailEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetThumbnailEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>>>();
_sut = Factory.Create<GetThumbnailEndpoint>(_mockHandler);
_getThumbnailRequestFixture = new GetThumbnailRequestFixture();
}
@@ -46,7 +46,7 @@ public class GetThumbnailEndpointTests
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
CancellationToken cancellationToken = CancellationToken.None;
ThumbnailResponse expectedResponse = ThumbnailResponseFixture.CreateThumbnailResponse();
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -65,7 +65,7 @@ public class GetThumbnailEndpointTests
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.NotFound("Thumbnail.NotFound", "The requested thumbnail was not found.");
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -91,7 +91,7 @@ public class GetThumbnailEndpointTests
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -116,14 +116,14 @@ public class GetThumbnailEndpointTests
// Arrange
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(ThumbnailResponseFixture.CreateThumbnailResponse()));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(Arg.Is<GetThumbnailQuery>(q => q.Path == request.Path && q.Quality == request.Quality), Arg.Is(cancellationToken));
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetThumbnailQuery>(q => q.Path == request.Path && q.Quality == request.Quality), Arg.Is(cancellationToken));
}
[Fact]
@@ -135,14 +135,14 @@ public class GetThumbnailEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<ThumbnailResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(ThumbnailResponseFixture.CreateThumbnailResponse());
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
using Lumina.Contracts.Responses.UsersManagement;
using Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -21,7 +21,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.Applicati
[ExcludeFromCodeCoverage]
public class CheckInitializationEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<CheckInitializationQuery, InitializationResponse> _mockHandler;
private readonly CheckInitializationEndpoint _sut;
/// <summary>
@@ -29,8 +29,8 @@ public class CheckInitializationEndpointTests
/// </summary>
public CheckInitializationEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<CheckInitializationEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<CheckInitializationQuery, InitializationResponse>>();
_sut = Factory.Create<CheckInitializationEndpoint>(_mockHandler);
}
[Fact]
@@ -39,7 +39,7 @@ public class CheckInitializationEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
InitializationResponse expectedResponse = new(IsInitialized: true);
_mockSender.Send(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedResponse);
// Act
@@ -55,14 +55,14 @@ public class CheckInitializationEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
.Returns(new InitializationResponse(IsInitialized: true));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Any<CheckInitializationQuery>(),
Arg.Is(cancellationToken));
}
@@ -75,14 +75,14 @@ public class CheckInitializationEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<InitializationResponse>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return new InitializationResponse(IsInitialized: true);
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
using Lumina.Contracts.Requests.Authentication;
@@ -8,7 +8,6 @@ using Lumina.Contracts.Responses.Authentication;
using Lumina.Contracts.Responses.UsersManagement;
using Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -26,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.Applicati
[ExcludeFromCodeCoverage]
public class SetupApplicationEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<SetupApplicationCommand, ErrorOr<RegistrationResponse>> _mockHandler;
private readonly SetupApplicationEndpoint _sut;
private readonly RegistrationRequestFixture _registrationRequestFixture;
@@ -35,8 +34,8 @@ public class SetupApplicationEndpointTests
/// </summary>
public SetupApplicationEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<SetupApplicationEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<SetupApplicationCommand, ErrorOr<RegistrationResponse>>>();
_sut = FastEndpoints.Factory.Create<SetupApplicationEndpoint>(_mockHandler);
_registrationRequestFixture = new RegistrationRequestFixture();
}
@@ -47,7 +46,7 @@ public class SetupApplicationEndpointTests
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
_mockSender.Send(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -66,7 +65,7 @@ public class SetupApplicationEndpointTests
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Conflict("Registration.Failed", "The application is already initialized.");
_mockSender.Send(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -91,14 +90,14 @@ public class SetupApplicationEndpointTests
// Arrange
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<SetupApplicationCommand>(cmd =>
cmd.Username == request.Username &&
cmd.Password == request.Password &&
@@ -116,14 +115,14 @@ public class SetupApplicationEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<RegistrationResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.ChangePassword;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.ChangePassword.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class ChangePasswordEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>> _mockHandler;
private readonly ChangePasswordEndpoint _sut;
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture;
@@ -33,8 +32,8 @@ public class ChangePasswordEndpointTests
/// </summary>
public ChangePasswordEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<ChangePasswordEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<ChangePasswordCommand, ErrorOr<ChangePasswordResponse>>>();
_sut = FastEndpoints.Factory.Create<ChangePasswordEndpoint>(_mockHandler);
_changePasswordRequestFixture = new ChangePasswordRequestFixture();
}
@@ -45,7 +44,7 @@ public class ChangePasswordEndpointTests
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
ChangePasswordResponse expectedResponse = new(IsPasswordChanged: true);
_mockSender.Send(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -63,7 +62,7 @@ public class ChangePasswordEndpointTests
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Password.Invalid", "The current password is incorrect.");
_mockSender.Send(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -87,14 +86,14 @@ public class ChangePasswordEndpointTests
// Arrange
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new ChangePasswordResponse(true)));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<ChangePasswordCommand>(cmd =>
cmd.Username == request.Username &&
cmd.CurrentPassword == request.CurrentPassword &&
@@ -112,14 +111,14 @@ public class ChangePasswordEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<ChangePasswordResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new ChangePasswordResponse(true));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -23,15 +23,15 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class GetUsersEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>> _mockHandler;
private readonly GetUsersEndpoint _sut;
/// <summary>
/// Initializes a new instance of the <see cref="GetUsersEndpointTests"/> class.
/// </summary>
public GetUsersEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetUsersEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetUsersQuery, ErrorOr<IEnumerable<UserResponse>>>>();
_sut = Factory.Create<GetUsersEndpoint>(_mockHandler);
}
[Fact]
@@ -43,7 +43,7 @@ public class GetUsersEndpointTests
[
new UserResponse(Guid.NewGuid(), "testUser", DateTime.UtcNow, null)
];
_mockSender.Send(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -60,7 +60,7 @@ public class GetUsersEndpointTests
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Users.NotFound", "No users found.");
_mockSender.Send(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -84,16 +84,14 @@ public class GetUsersEndpointTests
{
// Arrange
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(new ValueTask<ErrorOr<IEnumerable<UserResponse>>>(
ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>)
));
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>));
// Act
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Any<GetUsersQuery>(),
Arg.Is(cancellationToken));
}
@@ -106,16 +104,14 @@ public class GetUsersEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<IEnumerable<UserResponse>>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>);
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Array.Empty<UserResponse>() as IEnumerable<UserResponse>);
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Login;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.Login.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class LoginEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<LoginUserQuery, ErrorOr<LoginResponse>> _mockHandler;
private readonly LoginEndpoint _sut;
private readonly LoginRequestFixture _loginRequestFixture;
@@ -33,8 +33,8 @@ public class LoginEndpointTests
/// </summary>
public LoginEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<LoginEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<LoginUserQuery, ErrorOr<LoginResponse>>>();
_sut = Factory.Create<LoginEndpoint>(_mockHandler);
_loginRequestFixture = new LoginRequestFixture();
}
@@ -45,7 +45,7 @@ public class LoginEndpointTests
LoginRequest request = _loginRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
LoginResponse expectedResponse = new(Guid.NewGuid(), "testUser", "jwt_token", true);
_mockSender.Send(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -63,7 +63,7 @@ public class LoginEndpointTests
LoginRequest request = _loginRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Login.Failed", "Invalid username or password.");
_mockSender.Send(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -87,14 +87,14 @@ public class LoginEndpointTests
// Arrange
LoginRequest request = _loginRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<LoginUserQuery>(q =>
q.Username == request.Username &&
q.Password == request.Password &&
@@ -111,14 +111,14 @@ public class LoginEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<LoginResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.RecoverPassword;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.RecoverPassword.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class RecoverPasswordEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>> _mockHandler;
private readonly RecoverPasswordEndpoint _sut;
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture;
@@ -33,8 +32,8 @@ public class RecoverPasswordEndpointTests
/// </summary>
public RecoverPasswordEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<RecoverPasswordEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<RecoverPasswordCommand, ErrorOr<RecoverPasswordResponse>>>();
_sut = FastEndpoints.Factory.Create<RecoverPasswordEndpoint>(_mockHandler);
_recoverPasswordRequestFixture = new RecoverPasswordRequestFixture();
}
@@ -45,7 +44,7 @@ public class RecoverPasswordEndpointTests
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
RecoverPasswordResponse expectedResponse = new(IsPasswordReset: true);
_mockSender.Send(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -63,7 +62,7 @@ public class RecoverPasswordEndpointTests
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Recovery.Failed", "Invalid username or TOTP code.");
_mockSender.Send(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -87,14 +86,14 @@ public class RecoverPasswordEndpointTests
// Arrange
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new RecoverPasswordResponse(true)));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<RecoverPasswordCommand>(cmd =>
cmd.Username == request.Username &&
cmd.TotpCode == request.TotpCode),
@@ -110,14 +109,14 @@ public class RecoverPasswordEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<RecoverPasswordResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RecoverPasswordResponse(true));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
using Lumina.Contracts.Requests.Authentication;
using Lumina.Contracts.Responses.Authentication;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Register;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -24,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class RegisterEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>> _mockHandler;
private readonly RegisterEndpoint _sut;
private readonly RegistrationRequestFixture _registrationRequestFixture;
@@ -33,8 +32,8 @@ public class RegisterEndpointTests
/// </summary>
public RegisterEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<RegisterEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<RegisterUserCommand, ErrorOr<RegistrationResponse>>>();
_sut = FastEndpoints.Factory.Create<RegisterEndpoint>(_mockHandler);
_registrationRequestFixture = new RegistrationRequestFixture();
}
@@ -45,7 +44,7 @@ public class RegisterEndpointTests
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
_mockSender.Send(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -64,7 +63,7 @@ public class RegisterEndpointTests
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Validation("Registration.Failed", "Username is already taken.");
_mockSender.Send(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -88,14 +87,14 @@ public class RegisterEndpointTests
// Arrange
RegistrationRequest request = _registrationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<RegisterUserCommand>(cmd =>
cmd.Username == request.Username &&
cmd.Password == request.Password &&
@@ -113,14 +112,14 @@ public class RegisterEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<RegistrationResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetAuthorization;
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authorization.GetAuthorization.Fixtures;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -27,7 +27,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
[ExcludeFromCodeCoverage]
public class GetAuthorizationEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetAuthorizationQuery, ErrorOr<AuthorizationResponse>> _mockHandler;
private readonly GetAuthorizationEndpoint _sut;
/// <summary>
@@ -35,8 +35,8 @@ public class GetAuthorizationEndpointTests
/// </summary>
public GetAuthorizationEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetAuthorizationEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetAuthorizationQuery, ErrorOr<AuthorizationResponse>>>();
_sut = Factory.Create<GetAuthorizationEndpoint>(_mockHandler);
}
[Fact]
@@ -50,7 +50,7 @@ public class GetAuthorizationEndpointTests
"Admin",
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
_mockSender.Send(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -69,7 +69,7 @@ public class GetAuthorizationEndpointTests
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Unauthorized("Authorization.Failed", "User is not authorized.");
_mockSender.Send(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -95,7 +95,7 @@ public class GetAuthorizationEndpointTests
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new AuthorizationResponse(
request.UserId!.Value,
string.Empty,
@@ -106,7 +106,7 @@ public class GetAuthorizationEndpointTests
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<GetAuthorizationQuery>(query =>
query.UserId == request.UserId),
Arg.Is(cancellationToken));
@@ -121,8 +121,8 @@ public class GetAuthorizationEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => new ValueTask<ErrorOr<AuthorizationResponse>>(Task.Run(async () =>
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
.Returns(callInfo => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
@@ -132,7 +132,7 @@ public class GetAuthorizationEndpointTests
string.Empty,
new HashSet<AuthorizationPermission>().ToHashSet()
));
}, callInfo.Arg<CancellationToken>())));
}, callInfo.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
@@ -1,12 +1,12 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetUserPermissions;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
[ExcludeFromCodeCoverage]
public class GetUserPermissionsEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetUserPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>> _mockHandler;
private readonly GetUserPermissionsEndpoint _sut;
/// <summary>
@@ -33,8 +33,8 @@ public class GetUserPermissionsEndpointTests
/// </summary>
public GetUserPermissionsEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetUserPermissionsEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetUserPermissionsQuery, ErrorOr<IEnumerable<PermissionResponse>>>>();
_sut = Factory.Create<GetUserPermissionsEndpoint>(_mockHandler);
}
[Fact]
@@ -48,7 +48,7 @@ public class GetUserPermissionsEndpointTests
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
];
_mockSender.Send(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -66,7 +66,7 @@ public class GetUserPermissionsEndpointTests
GetUserPermissionsRequest request = new(Guid.NewGuid());
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("User.Permissions.NotFound", "User permissions not found.");
_mockSender.Send(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -92,16 +92,14 @@ public class GetUserPermissionsEndpointTests
Guid userId = Guid.NewGuid();
GetUserPermissionsRequest request = new(userId);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(new ValueTask<ErrorOr<IEnumerable<PermissionResponse>>>(
ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>)
));
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<GetUserPermissionsQuery>(cmd => cmd.UserId == request.UserId),
Arg.Is(cancellationToken));
}
@@ -114,16 +112,14 @@ public class GetUserPermissionsEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<IEnumerable<PermissionResponse>>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>);
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>);
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserPermissionsRequest(Guid.NewGuid()), cts.Token);
@@ -1,11 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.GetUserRole;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
[ExcludeFromCodeCoverage]
public class GetUserRoleEndpointTests
{
private readonly ISender _mockSender;
private readonly IQueryHandler<GetUserRoleQuery, ErrorOr<RoleResponse?>> _mockHandler;
private readonly GetUserRoleEndpoint _sut;
/// <summary>
@@ -31,8 +31,8 @@ public class GetUserRoleEndpointTests
/// </summary>
public GetUserRoleEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<GetUserRoleEndpoint>(_mockSender);
_mockHandler = Substitute.For<IQueryHandler<GetUserRoleQuery, ErrorOr<RoleResponse?>>>();
_sut = Factory.Create<GetUserRoleEndpoint>(_mockHandler);
}
[Fact]
@@ -42,8 +42,8 @@ public class GetUserRoleEndpointTests
GetUserRoleRequest request = new(Guid.NewGuid());
CancellationToken cancellationToken = CancellationToken.None;
RoleResponse expectedResponse = new(Guid.NewGuid(), "Admin");
_mockSender.Send(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<RoleResponse?>(expectedResponse));
// Act
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
@@ -60,7 +60,7 @@ public class GetUserRoleEndpointTests
GetUserRoleRequest request = new(Guid.NewGuid());
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("User.Role.NotFound", "User role not found.");
_mockSender.Send(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -86,14 +86,14 @@ public class GetUserRoleEndpointTests
Guid userId = Guid.NewGuid();
GetUserRoleRequest request = new(userId);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new RoleResponse(Guid.NewGuid(), "Admin")));
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
// Act
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<GetUserRoleQuery>(cmd => cmd.UserId == request.UserId),
Arg.Is(cancellationToken));
}
@@ -106,16 +106,14 @@ public class GetUserRoleEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<RoleResponse?>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new RoleResponse(Guid.NewGuid(), "Admin"));
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserRoleRequest(Guid.NewGuid()), cts.Token);
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FastEndpoints;
using Lumina.Application.Common.CQRS;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using Lumina.Contracts.Requests.Authorization;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authorization.UpdateUserRoleAndPermissions;
using Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using NSubstitute;
@@ -26,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Autho
[ExcludeFromCodeCoverage]
public class UpdateUserRoleAndPermissionsEndpointTests
{
private readonly ISender _mockSender;
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, ErrorOr<AuthorizationResponse>> _mockHandler;
private readonly UpdateUserRoleAndPermissionsEndpoint _sut;
/// <summary>
@@ -34,8 +33,8 @@ public class UpdateUserRoleAndPermissionsEndpointTests
/// </summary>
public UpdateUserRoleAndPermissionsEndpointTests()
{
_mockSender = Substitute.For<ISender>();
_sut = Factory.Create<UpdateUserRoleAndPermissionsEndpoint>(_mockSender);
_mockHandler = Substitute.For<ICommandHandler<UpdateUserRoleAndPermissionsCommand, ErrorOr<AuthorizationResponse>>>();
_sut = FastEndpoints.Factory.Create<UpdateUserRoleAndPermissionsEndpoint>(_mockHandler);
}
[Fact]
@@ -53,7 +52,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
"Admin",
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
);
_mockSender.Send(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(expectedResponse));
// Act
@@ -75,7 +74,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
);
CancellationToken cancellationToken = CancellationToken.None;
Error expectedError = Error.Failure("Authorization.Update.Failed", "Failed to update user role and permissions.");
_mockSender.Send(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
.Returns(expectedError);
// Act
@@ -104,7 +103,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
[Guid.NewGuid()]
);
CancellationToken cancellationToken = CancellationToken.None;
_mockSender.Send(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
.Returns(ErrorOrFactory.From(new AuthorizationResponse(
Guid.NewGuid(),
"Admin",
@@ -115,7 +114,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
await _sut.ExecuteAsync(request, cancellationToken);
// Assert
await _mockSender.Received(1).Send(
await _mockHandler.Received(1).HandleAsync(
Arg.Is<UpdateUserRoleAndPermissionsCommand>(cmd =>
cmd.UserId == request.UserId &&
cmd.RoleId == request.RoleId &&
@@ -131,20 +130,18 @@ public class UpdateUserRoleAndPermissionsEndpointTests
TaskCompletionSource<bool> operationStarted = new();
TaskCompletionSource<bool> cancellationRequested = new();
_mockSender.Send(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
.Returns(info => new ValueTask<ErrorOr<AuthorizationResponse>>(
Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new AuthorizationResponse(
Guid.NewGuid(),
"Admin",
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
));
}, info.Arg<CancellationToken>())
));
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
.Returns(info => Task.Run(async () =>
{
operationStarted.SetResult(true);
await cancellationRequested.Task;
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
return ErrorOrFactory.From(new AuthorizationResponse(
Guid.NewGuid(),
"Admin",
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
));
}, info.Arg<CancellationToken>()));
// Act
Task<IResult> operationTask = _sut.ExecuteAsync(