mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Merge branch 'refactor/standardize-test-fixtures-and-docs' into feature/add-artwork-provider-and-metadata-aggregation
This commit is contained in:
commit
4ff184d8a5
388 files changed
+13829
-2814
No files matched your search
+19
-8
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +28,9 @@ public class AddRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<AddRoleCommand, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly AddRoleEndpoint _sut;
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AddRoleEndpointTests"/> class.
|
||||
@@ -40,9 +45,11 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithRoleResponse()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(new RoleDto(Guid.NewGuid(), "Admin"), []);
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []);
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -58,7 +65,7 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Creation.Failed", "Failed to create role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -84,10 +91,12 @@ public class AddRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendAddRoleCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new("Admin", [Guid.NewGuid()]);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(roleName: "Admin", permissions: [Guid.NewGuid()]);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<AddRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(new RoleDto(Guid.NewGuid(), "Admin"), [])));
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: [])));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,11 +123,13 @@ public class AddRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(new RoleDto(Guid.NewGuid(), "Admin"), []));
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new AddRoleRequest("Admin", []), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_addRoleRequestFixture.Create(roleName: "Admin", permissions: []), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+6
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.DeleteRole;
|
||||
@@ -23,6 +24,7 @@ public class DeleteRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<DeleteRoleCommand, Result<Deleted>> _mockHandler;
|
||||
private readonly DeleteRoleEndpoint _sut;
|
||||
private readonly DeleteRoleRequestFixture _deleteRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DeleteRoleEndpointTests"/> class.
|
||||
@@ -37,7 +39,7 @@ public class DeleteRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnNoContent()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.NewGuid());
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
@@ -53,7 +55,7 @@ public class DeleteRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.NewGuid());
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Deletion.Failed", "Failed to delete role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -80,7 +82,7 @@ public class DeleteRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
DeleteRoleRequest request = new(roleId);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId: roleId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<DeleteRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Result.Deleted));
|
||||
@@ -112,7 +114,7 @@ public class DeleteRoleEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new DeleteRoleRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_deleteRoleRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+20
-14
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +28,10 @@ public class GetRolePermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetRolePermissionsQuery, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly GetRolePermissionsEndpoint _sut;
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
private readonly GetRolePermissionsRequestFixture _getRolePermissionsRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolePermissionsEndpointTests"/> class.
|
||||
@@ -40,11 +46,11 @@ public class GetRolePermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.NewGuid());
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: [_permissionDtoFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)]
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -61,7 +67,7 @@ public class GetRolePermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.NewGuid());
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Permissions.NotFound", "Role permissions not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -88,12 +94,12 @@ public class GetRolePermissionsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
GetRolePermissionsRequest request = new(roleId);
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId: roleId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolePermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[]
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -119,14 +125,14 @@ public class GetRolePermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "Admin"),
|
||||
[]
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "Admin"),
|
||||
permissions: []
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetRolePermissionsRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getRolePermissionsRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Admin.Authorization.Roles.GetRoles;
|
||||
@@ -25,6 +26,7 @@ public class GetRolesEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetRolesQuery, Result<IEnumerable<RoleResponse>>> _mockHandler;
|
||||
private readonly GetRolesEndpoint _sut;
|
||||
private readonly RoleResponseFixture _roleResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetRolesEndpointTests"/> class.
|
||||
@@ -42,8 +44,8 @@ public class GetRolesEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<RoleResponse> expectedResponse =
|
||||
[
|
||||
new RoleResponse(Guid.NewGuid(), "Admin")
|
||||
];
|
||||
_roleResponseFixture.Create(roleName: "Admin")
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -88,7 +90,7 @@ public class GetRolesEndpointTests
|
||||
_mockHandler.HandleAsync(Arg.Any<GetRolesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new List<RoleResponse>
|
||||
{
|
||||
new(Guid.NewGuid(), "Admin")
|
||||
_roleResponseFixture.Create(roleName: "Admin")
|
||||
} as IEnumerable<RoleResponse>));
|
||||
|
||||
// Act
|
||||
|
||||
+20
-14
@@ -1,7 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,10 @@ public class UpdateRoleEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateRoleCommand, Result<RolePermissionsResponse>> _mockHandler;
|
||||
private readonly UpdateRoleEndpoint _sut;
|
||||
private readonly UpdateRoleRequestFixture _updateRoleRequestFixture = new();
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly RoleDtoFixture _roleDtoFixture = new();
|
||||
private readonly PermissionDtoFixture _permissionDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateRoleEndpointTests"/> class.
|
||||
@@ -41,11 +47,11 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithUpdatedRole()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RolePermissionsResponse expectedResponse = new(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanViewUsers)]
|
||||
RolePermissionsResponse expectedResponse = _rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: [_permissionDtoFixture.Create(permissionName: AuthorizationPermission.CanViewUsers)]
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -62,7 +68,7 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Role.Update.Failed", "Failed to update role.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -88,12 +94,12 @@ public class UpdateRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateRoleCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(roleName: "UpdatedAdmin");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateRoleCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[]
|
||||
.Returns(Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: []
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -122,15 +128,15 @@ public class UpdateRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RolePermissionsResponse(
|
||||
new RoleDto(Guid.NewGuid(), "UpdatedAdmin"),
|
||||
[]
|
||||
return Result.From(_rolePermissionsResponseFixture.Create(
|
||||
role: _roleDtoFixture.Create(roleName: "UpdatedAdmin"),
|
||||
permissions: []
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(
|
||||
new UpdateRoleRequest(Guid.NewGuid(), "UpdatedAdmin", [Guid.NewGuid()]),
|
||||
_updateRoleRequestFixture.Create(roleName: "UpdatedAdmin"),
|
||||
cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
|
||||
+7
-5
@@ -2,8 +2,9 @@
|
||||
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.Fixtures.Core.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.FileSystem.GetType;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -24,6 +25,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse> _mockHandler;
|
||||
private readonly GetTypeEndpoint _sut;
|
||||
private readonly FileSystemTypeResponseFixture _fileSystemTypeResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTypeEndpointTests"/> class.
|
||||
@@ -39,7 +41,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(PlatformType.Windows);
|
||||
FileSystemTypeResponse expectedResponse = _fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -58,7 +60,7 @@ public class GetTypeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(platformType);
|
||||
FileSystemTypeResponse expectedResponse = _fileSystemTypeResponseFixture.Create(platformType: platformType);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -76,7 +78,7 @@ public class GetTypeEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new FileSystemTypeResponse(PlatformType.Windows));
|
||||
.Returns(_fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
@@ -99,7 +101,7 @@ public class GetTypeEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new FileSystemTypeResponse(PlatformType.Windows);
|
||||
return _fileSystemTypeResponseFixture.Create(platformType: PlatformType.Windows);
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class CheckPathExistsEndpointTests
|
||||
private readonly IQueryHandler<CheckPathExistsQuery, Result<PathExistsResponse>> _mockHandler;
|
||||
private readonly CheckPathExistsEndpoint _sut;
|
||||
private readonly CheckPathExistsRequestFixture _checkPathExistsRequestFixture = new();
|
||||
private readonly PathExistsResponseFixture _pathExistsResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckPathExistsEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class CheckPathExistsEndpointTests
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathExistsResponse expectedResponse = new(true);
|
||||
PathExistsResponse expectedResponse = _pathExistsResponseFixture.Create(exists: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -62,7 +64,7 @@ public class CheckPathExistsEndpointTests
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathExistsResponse(true));
|
||||
.Returns(_pathExistsResponseFixture.Create(exists: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -88,7 +90,7 @@ public class CheckPathExistsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new PathExistsResponse(true));
|
||||
return Result.From(_pathExistsResponseFixture.Create(exists: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class ValidatePathEndpointTests
|
||||
private readonly IQueryHandler<ValidatePathQuery, Result<PathValidResponse>> _mockHandler;
|
||||
private readonly ValidatePathEndpoint _sut;
|
||||
private readonly ValidatePathRequestFixture _validatePathRequestFixture = new();
|
||||
private readonly PathValidResponseFixture _pathValidResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ValidatePathEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathValidResponse expectedResponse = new(true);
|
||||
PathValidResponse expectedResponse = _pathValidResponseFixture.Create(isValid: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -62,7 +64,7 @@ public class ValidatePathEndpointTests
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidResponse(true));
|
||||
.Returns(_pathValidResponseFixture.Create(isValid: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,7 +116,7 @@ public class ValidatePathEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new PathValidResponse(true));
|
||||
return Result.From(_pathValidResponseFixture.Create(isValid: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@ using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.AddLibrary;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -104,7 +103,7 @@ public class AddLibraryEndpointTests
|
||||
command.CoverImage == request.CoverImage &&
|
||||
command.IsEnabled == request.IsEnabled &&
|
||||
command.IsLocked == request.IsLocked &&
|
||||
command.DownloadMetadataFromWeb == request.DownloadMetadataFromWeb &&
|
||||
command.CanDownloadMetadataFromWeb == request.CanDownloadMetadataFromWeb &&
|
||||
command.ShouldSaveMetadataInMediaDirectories == request.ShouldSaveMetadataInMediaDirectories &&
|
||||
command.ShouldSkipUnchangedDirectoriesDuringScan == request.ShouldSkipUnchangedDirectoriesDuringScan),
|
||||
Arg.Is(cancellationToken));
|
||||
|
||||
+4
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibraries;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.ScanLibraries;
|
||||
@@ -25,6 +26,7 @@ public class ScanLibrariesEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<ScanLibrariesCommand, Result<IEnumerable<MediaLibraryScanResponse>>> _mockHandler;
|
||||
private readonly ScanLibrariesEndpoint _sut;
|
||||
private readonly MediaLibraryScanResponseFixture _mediaLibraryScanResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibrariesEndpointTests"/> class.
|
||||
@@ -42,8 +44,8 @@ public class ScanLibrariesEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<MediaLibraryScanResponse> expectedResponses =
|
||||
[
|
||||
new MediaLibraryScanResponse(Guid.NewGuid(), Guid.NewGuid()),
|
||||
new MediaLibraryScanResponse(Guid.NewGuid(), Guid.NewGuid())
|
||||
_mediaLibraryScanResponseFixture.Create(),
|
||||
_mediaLibraryScanResponseFixture.Create()
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibrariesCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponses));
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class ScanLibraryEndpointTests
|
||||
private readonly ICommandHandler<ScanLibraryCommand, Result<MediaLibraryScanResponse>> _mockHandler;
|
||||
private readonly ScanLibraryEndpoint _sut;
|
||||
private readonly ScanLibraryRequestFixture _scanLibraryRequestFixture = new();
|
||||
private readonly MediaLibraryScanResponseFixture _mediaLibraryScanResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ScanLibraryEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class ScanLibraryEndpointTests
|
||||
// Arrange
|
||||
ScanLibraryRequest request = _scanLibraryRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
MediaLibraryScanResponse expectedResponse = new(Guid.NewGuid(), request.Id);
|
||||
MediaLibraryScanResponse expectedResponse = _mediaLibraryScanResponseFixture.Create(libraryId: request.Id);
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibraryCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class ScanLibraryEndpointTests
|
||||
ScanLibraryRequest request = _scanLibraryRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ScanLibraryCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new MediaLibraryScanResponse(Guid.NewGuid(), request.Id)));
|
||||
.Returns(Result.From(_mediaLibraryScanResponseFixture.Create(libraryId: request.Id)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -113,7 +115,7 @@ public class ScanLibraryEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new MediaLibraryScanResponse(Guid.NewGuid(), request.Id));
|
||||
return Result.From(_mediaLibraryScanResponseFixture.Create(libraryId: request.Id));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+1
-2
@@ -6,7 +6,6 @@ using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.Management.UpdateLibrary;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -106,7 +105,7 @@ public class UpdateLibraryEndpointTests
|
||||
command.CoverImage == request.CoverImage &&
|
||||
command.IsEnabled == request.IsEnabled &&
|
||||
command.IsLocked == request.IsLocked &&
|
||||
command.DownloadMetadataFromWeb == request.DownloadMetadataFromWeb &&
|
||||
command.CanDownloadMetadataFromWeb == request.CanDownloadMetadataFromWeb &&
|
||||
command.ShouldSaveMetadataInMediaDirectories == request.ShouldSaveMetadataInMediaDirectories &&
|
||||
command.ShouldSkipUnchangedDirectoriesDuringScan == request.ShouldSkipUnchangedDirectoriesDuringScan),
|
||||
Arg.Is(cancellationToken));
|
||||
|
||||
+3
-1
@@ -1,5 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBook;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -19,12 +20,13 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Library.WrittenConten
|
||||
public class GetBookEndpointTests
|
||||
{
|
||||
private readonly GetBookEndpoint _sut = Factory.Create<GetBookEndpoint>();
|
||||
private readonly GetBookRequestFixture _getBookRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResult()
|
||||
{
|
||||
// Arrange
|
||||
GetBookRequest request = new(Guid.NewGuid().ToString());
|
||||
GetBookRequest request = _getBookRequestFixture.Create(id: Guid.NewGuid().ToString());
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
// Act
|
||||
|
||||
+5
-12
@@ -2,15 +2,14 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooks;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Responses.Common;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -34,6 +33,7 @@ public class GetBooksEndpointTests
|
||||
private readonly GetBooksEndpoint _sut;
|
||||
private readonly GetBooksRequestFixture _getBooksRequestFixture = new();
|
||||
private readonly BookResponseFixture _bookResponseFixture = new();
|
||||
private readonly PaginatedResponseFixture<BookResponse> _paginatedResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksEndpointTests"/> class.
|
||||
@@ -171,19 +171,12 @@ public class GetBooksEndpointTests
|
||||
/// </summary>
|
||||
/// <param name="bookCount">The number of book responses to include in the data collection.</param>
|
||||
/// <returns>A configured paginated response instance.</returns>
|
||||
private static PaginatedResponse<BookResponse> CreatePaginatedResponse(int bookCount, BookResponseFixture bookResponseFixture)
|
||||
private PaginatedResponse<BookResponse> CreatePaginatedResponse(int bookCount, BookResponseFixture bookResponseFixture)
|
||||
{
|
||||
List<BookResponse> books = [];
|
||||
for (int index = 0; index < bookCount; index++)
|
||||
books.Add(bookResponseFixture.Create());
|
||||
|
||||
return new PaginatedResponse<BookResponse>
|
||||
{
|
||||
Data = books,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = bookCount,
|
||||
NumberOfPages = bookCount > 0 ? 1 : 0
|
||||
};
|
||||
return _paginatedResponseFixture.Create(data: books, currentPage: 1, perPage: 10, count: bookCount, numberOfPages: bookCount > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
+12
-15
@@ -3,11 +3,13 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Queries.GetBooksLite;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Fixtures.Responses.Common;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookLibrary.Books.GetBooksLite;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
@@ -30,6 +32,8 @@ public class GetBooksLiteEndpointTests
|
||||
private readonly IQueryHandler<GetBooksLiteQuery, Result<PaginatedResponse<BookLiteResponse>>> _mockHandler;
|
||||
private readonly GetBooksLiteEndpoint _sut;
|
||||
private readonly GetBooksLiteRequestFixture _getBooksLiteRequestFixture = new();
|
||||
private readonly BookLiteResponseFixture _bookLiteResponseFixture = new();
|
||||
private readonly PaginatedResponseFixture<BookLiteResponse> _paginatedResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetBooksLiteEndpointTests"/> class.
|
||||
@@ -167,24 +171,17 @@ public class GetBooksLiteEndpointTests
|
||||
/// </summary>
|
||||
/// <param name="bookCount">The number of book responses to include in the data collection.</param>
|
||||
/// <returns>A configured paginated response instance.</returns>
|
||||
private static PaginatedResponse<BookLiteResponse> CreatePaginatedResponse(int bookCount)
|
||||
private PaginatedResponse<BookLiteResponse> CreatePaginatedResponse(int bookCount)
|
||||
{
|
||||
List<BookLiteResponse> books = [];
|
||||
for (int index = 0; index < bookCount; index++)
|
||||
books.Add(new BookLiteResponse(
|
||||
Id: Guid.NewGuid(),
|
||||
Title: "Test Book",
|
||||
ReleaseYear: 2001,
|
||||
CoverPath: null
|
||||
books.Add(_bookLiteResponseFixture.Create(
|
||||
id: Guid.NewGuid(),
|
||||
title: "Test Book",
|
||||
releaseYear: 2001,
|
||||
coverPath: null
|
||||
));
|
||||
|
||||
return new PaginatedResponse<BookLiteResponse>
|
||||
{
|
||||
Data = books,
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = bookCount,
|
||||
NumberOfPages = bookCount > 0 ? 1 : 0
|
||||
};
|
||||
return _paginatedResponseFixture.Create(data: books, currentPage: 1, perPage: 10, count: bookCount, numberOfPages: bookCount > 0 ? 1 : 0);
|
||||
}
|
||||
}
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Queries.CheckInitialization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement;
|
||||
using Lumina.Contracts.Responses.UsersManagement;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -23,6 +24,7 @@ public class CheckInitializationEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<CheckInitializationQuery, InitializationResponse> _mockHandler;
|
||||
private readonly CheckInitializationEndpoint _sut;
|
||||
private readonly InitializationResponseFixture _initializationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CheckInitializationEndpointTests"/> class.
|
||||
@@ -38,7 +40,7 @@ public class CheckInitializationEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
InitializationResponse expectedResponse = new(IsInitialized: true);
|
||||
InitializationResponse expectedResponse = _initializationResponseFixture.Create(isInitialized: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
@@ -56,7 +58,7 @@ public class CheckInitializationEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckInitializationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new InitializationResponse(IsInitialized: true));
|
||||
.Returns(_initializationResponseFixture.Create(isInitialized: true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(EmptyRequest.Instance, cancellationToken);
|
||||
@@ -81,7 +83,7 @@ public class CheckInitializationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new InitializationResponse(IsInitialized: true);
|
||||
return _initializationResponseFixture.Create(isInitialized: true);
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class SetupApplicationEndpointTests
|
||||
private readonly ICommandHandler<SetupApplicationCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly SetupApplicationEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetupApplicationEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class SetupApplicationEndpointTests
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
RegistrationResponse expectedResponse = _registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -88,7 +90,7 @@ public class SetupApplicationEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<SetupApplicationCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -118,7 +120,7 @@ public class SetupApplicationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class ChangePasswordEndpointTests
|
||||
private readonly ICommandHandler<ChangePasswordCommand, Result<ChangePasswordResponse>> _mockHandler;
|
||||
private readonly ChangePasswordEndpoint _sut;
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||
private readonly ChangePasswordResponseFixture _changePasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ChangePasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class ChangePasswordEndpointTests
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ChangePasswordResponse expectedResponse = new(IsPasswordChanged: true);
|
||||
ChangePasswordResponse expectedResponse = _changePasswordResponseFixture.Create(isPasswordChanged: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class ChangePasswordEndpointTests
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<ChangePasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new ChangePasswordResponse(true)));
|
||||
.Returns(Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class ChangePasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new ChangePasswordResponse(true));
|
||||
return Result.From(_changePasswordResponseFixture.Create(isPasswordChanged: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement.Users;
|
||||
using Lumina.Contracts.Responses.UsersManagement.Users;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.GetUsers;
|
||||
@@ -25,6 +26,7 @@ public class GetUsersEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUsersQuery, Result<IEnumerable<UserResponse>>> _mockHandler;
|
||||
private readonly GetUsersEndpoint _sut;
|
||||
private readonly UserResponseFixture _userResponseFixture = new();
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUsersEndpointTests"/> class.
|
||||
/// </summary>
|
||||
@@ -41,7 +43,7 @@ public class GetUsersEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<UserResponse> expectedResponse =
|
||||
[
|
||||
new UserResponse(Guid.NewGuid(), "testUser", DateTime.UtcNow, null)
|
||||
_userResponseFixture.Create(username: "testUser", createdOnUtc: DateTime.UtcNow, updatedOnUtc: null)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUsersQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
+5
-3
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +28,7 @@ public class LoginEndpointTests
|
||||
private readonly IQueryHandler<LoginUserQuery, Result<LoginResponse>> _mockHandler;
|
||||
private readonly LoginEndpoint _sut;
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
private readonly LoginResponseFixture _loginResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LoginEndpointTests"/> class.
|
||||
@@ -43,7 +45,7 @@ public class LoginEndpointTests
|
||||
// Arrange
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
LoginResponse expectedResponse = new(Guid.NewGuid(), "testUser", "jwt_token", true);
|
||||
LoginResponse expectedResponse = _loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class LoginEndpointTests
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<LoginUserQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true)));
|
||||
.Returns(Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -116,7 +118,7 @@ public class LoginEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new LoginResponse(Guid.NewGuid(), "testUser", "jwt_token", true));
|
||||
return Result.From(_loginResponseFixture.Create(username: "testUser", token: "jwt_token", usesTotp: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RecoverPasswordEndpointTests
|
||||
private readonly ICommandHandler<RecoverPasswordCommand, Result<RecoverPasswordResponse>> _mockHandler;
|
||||
private readonly RecoverPasswordEndpoint _sut;
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly RecoverPasswordResponseFixture _recoverPasswordResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RecoverPasswordEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RecoverPasswordEndpointTests
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RecoverPasswordResponse expectedResponse = new(IsPasswordReset: true);
|
||||
RecoverPasswordResponse expectedResponse = _recoverPasswordResponseFixture.Create(isPasswordReset: true);
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -86,7 +88,7 @@ public class RecoverPasswordEndpointTests
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RecoverPasswordCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RecoverPasswordResponse(true)));
|
||||
.Returns(Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true)));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -114,7 +116,7 @@ public class RecoverPasswordEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RecoverPasswordResponse(true));
|
||||
return Result.From(_recoverPasswordResponseFixture.Create(isPasswordReset: true));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+5
-3
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +27,7 @@ public class RegisterEndpointTests
|
||||
private readonly ICommandHandler<RegisterUserCommand, Result<RegistrationResponse>> _mockHandler;
|
||||
private readonly RegisterEndpoint _sut;
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RegisterEndpointTests"/> class.
|
||||
@@ -42,7 +44,7 @@ public class RegisterEndpointTests
|
||||
// Arrange
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RegistrationResponse expectedResponse = new(Guid.NewGuid(), "testUser", "TOTP123");
|
||||
RegistrationResponse expectedResponse = _registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123");
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -87,7 +89,7 @@ public class RegisterEndpointTests
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<RegisterUserCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123")));
|
||||
.Returns(Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -117,7 +119,7 @@ public class RegisterEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new RegistrationResponse(Guid.NewGuid(), "testUser", "TOTP123"));
|
||||
return Result.From(_registrationResponseFixture.Create(username: "testUser", totpSecret: "TOTP123"));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+8
-6
@@ -3,6 +3,7 @@ using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -30,6 +31,7 @@ public class GetAuthorizationEndpointTests
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly GetAuthorizationEndpoint _sut;
|
||||
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAuthorizationEndpointTests"/> class.
|
||||
@@ -46,10 +48,10 @@ public class GetAuthorizationEndpointTests
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
request.UserId!.Value,
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
userId: request.UserId!.Value,
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers });
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -97,7 +99,7 @@ public class GetAuthorizationEndpointTests
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
@@ -128,7 +130,7 @@ public class GetAuthorizationEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
request.UserId!.Value,
|
||||
string.Empty,
|
||||
new HashSet<AuthorizationPermission>().ToHashSet()
|
||||
|
||||
+10
-6
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserPermissionsQuery, Result<IEnumerable<PermissionResponse>>> _mockHandler;
|
||||
private readonly GetUserPermissionsEndpoint _sut;
|
||||
private readonly PermissionResponseFixture _permissionResponseFixture = new();
|
||||
private readonly GetUserPermissionsRequestFixture _getUserPermissionsRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserPermissionsEndpointTests"/> class.
|
||||
@@ -41,12 +45,12 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithPermissions()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<PermissionResponse> expectedResponse =
|
||||
[
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanViewUsers),
|
||||
new PermissionResponse(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanViewUsers),
|
||||
_permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanDeleteUsers)
|
||||
];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -63,7 +67,7 @@ public class GetUserPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.NewGuid());
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Permissions.NotFound", "User permissions not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -90,7 +94,7 @@ public class GetUserPermissionsEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserPermissionsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Array.Empty<PermissionResponse>() as IEnumerable<PermissionResponse>));
|
||||
@@ -122,7 +126,7 @@ public class GetUserPermissionsEndpointTests
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserPermissionsRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserPermissionsRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+11
-7
@@ -2,6 +2,8 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -25,6 +27,8 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetUserRoleQuery, Result<RoleResponse?>> _mockHandler;
|
||||
private readonly GetUserRoleEndpoint _sut;
|
||||
private readonly RoleResponseFixture _roleResponseFixture = new();
|
||||
private readonly GetUserRoleRequestFixture _getUserRoleRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetUserRoleEndpointTests"/> class.
|
||||
@@ -39,9 +43,9 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithRole()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
RoleResponse expectedResponse = new(Guid.NewGuid(), "Admin");
|
||||
RoleResponse expectedResponse = _roleResponseFixture.Create(roleName: "Admin");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(expectedResponse));
|
||||
|
||||
@@ -57,7 +61,7 @@ public class GetUserRoleEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.NewGuid());
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("User.Role.NotFound", "User role not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -84,10 +88,10 @@ public class GetUserRoleEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserRoleRequest request = new(userId);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId: userId);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetUserRoleQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin")));
|
||||
.Returns(Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin")));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -112,11 +116,11 @@ public class GetUserRoleEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From<RoleResponse?>(new RoleResponse(Guid.NewGuid(), "Admin"));
|
||||
return Result.From<RoleResponse?>(_roleResponseFixture.Create(roleName: "Admin"));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new GetUserRoleRequest(Guid.NewGuid()), cts.Token);
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(_getUserRoleRequestFixture.Create(), cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
+17
-28
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,6 +29,8 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
{
|
||||
private readonly ICommandHandler<UpdateUserRoleAndPermissionsCommand, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly UpdateUserRoleAndPermissionsEndpoint _sut;
|
||||
private readonly UpdateUserRoleAndPermissionsRequestFixture _updateUserRoleAndPermissionsRequestFixture = new();
|
||||
private readonly AuthorizationResponseFixture _authorizationResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="UpdateUserRoleAndPermissionsEndpointTests"/> class.
|
||||
@@ -41,16 +45,11 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithAuthorization()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
AuthorizationResponse expectedResponse = _authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
);
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
@@ -67,11 +66,7 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Failure("Authorization.Update.Failed", "Failed to update user role and permissions.");
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
@@ -97,17 +92,12 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendUpdateUserRoleAndPermissionsCommandToSender()
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<UpdateUserRoleAndPermissionsCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
.Returns(Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
)));
|
||||
|
||||
// Act
|
||||
@@ -136,16 +126,15 @@ public class UpdateUserRoleAndPermissionsEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
info.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(new AuthorizationResponse(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
return Result.From(_authorizationResponseFixture.Create(
|
||||
role: "Admin",
|
||||
permissions: new HashSet<AuthorizationPermission> { AuthorizationPermission.CanViewUsers }
|
||||
));
|
||||
}, info.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(
|
||||
new UpdateUserRoleAndPermissionsRequest(Guid.NewGuid(), Guid.NewGuid(), [Guid.NewGuid()]),
|
||||
_updateUserRoleAndPermissionsRequestFixture.Create(),
|
||||
cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
|
||||
Reference in new issue
Block a user