mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Centralizes and standardizes test fixtures.
This commit is contained in:
1 parent
dfc513da4f
commit
b648e2f054
294 files changed
+3807
-4437
No files matched your search
+1
-1
@@ -2,7 +2,7 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Primitives;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Common.Fixtures;
|
||||
using Lumina.Presentation.Api.Fixtures.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using System.Collections.Generic;
|
||||
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Common;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BaseEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BaseEndpointFixture : BaseEndpoint<object, object>
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a standardized error response using the <see cref="ProblemDetails"/> format.
|
||||
/// </summary>
|
||||
/// <param name="errors">A list of errors to include in the response.</param>
|
||||
/// <returns>An <see cref="IResult"/> with the problem details containing the specified errors.</returns>
|
||||
public IResult TestProblem(List<Error> errors)
|
||||
{
|
||||
return Problem(errors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a standardized validation error response using the <see cref="ValidationProblemDetails"/> format.
|
||||
/// </summary>
|
||||
/// <param name="errors">A list of validation errors to include in the response.</param>
|
||||
/// <returns>An <see cref="IResult"/> with the validation problem details containing the specified errors.</returns>
|
||||
public IResult TestValidationProblem(List<Error> errors)
|
||||
{
|
||||
return ValidationProblem(errors);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Configures the API endpoint.
|
||||
/// </summary>
|
||||
public override void Configure()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the API request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request containing the file system path for which to get the root.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public override Task<object> ExecuteAsync(object request, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.FromResult(new object());
|
||||
}
|
||||
}
|
||||
+13
-11
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,17 +27,19 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IQueryHandler<GetDirectoriesQuery, Result<IEnumerable<DirectoryResponse>>> _mockHandler;
|
||||
private readonly GetDirectoriesEndpoint _sut;
|
||||
private readonly GetDirectoriesRequestFixture _getDirectoriesRequestFixture;
|
||||
private readonly DirectoryResponseFixture _directoryResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoriesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetDirectoriesQuery, Result<IEnumerable<DirectoryResponse>>>>();
|
||||
_getDirectoriesRequestFixture = new GetDirectoriesRequestFixture();
|
||||
_directoryResponseFixture = new DirectoryResponseFixture();
|
||||
_sut = Factory.Create<GetDirectoriesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -45,9 +47,9 @@ public class GetDirectoriesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResultWithDirectoryResponses()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<DirectoryResponse> expectedResponses = [.. _fixture.CreateMany<DirectoryResponse>(3)];
|
||||
List<DirectoryResponse> expectedResponses = [.. _directoryResponseFixture.CreateMany(3)];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
@@ -63,7 +65,7 @@ public class GetDirectoriesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Directory.NotFound", "The requested directory was not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -89,7 +91,7 @@ public class GetDirectoriesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -115,7 +117,7 @@ public class GetDirectoriesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDirectoriesQueryToHandler()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<DirectoryResponse>()));
|
||||
@@ -133,7 +135,7 @@ public class GetDirectoriesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
GetDirectoriesRequest request = _getDirectoriesRequestFixture.Create();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
@@ -144,7 +146,7 @@ public class GetDirectoriesEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(_fixture.CreateMany<DirectoryResponse>(3).AsEnumerable());
|
||||
return Result.From(_directoryResponseFixture.CreateMany(3).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+1
-1
@@ -2,10 +2,10 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Drives.GetDrives;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+13
-11
@@ -1,9 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -27,17 +27,19 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IQueryHandler<GetFilesQuery, Result<IEnumerable<FileResponse>>> _mockHandler;
|
||||
private readonly GetFilesEndpoint _sut;
|
||||
private readonly GetFilesRequestFixture _getFilesRequestFixture;
|
||||
private readonly FileResponseFixture _fileResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetFilesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetFilesQuery, Result<IEnumerable<FileResponse>>>>();
|
||||
_getFilesRequestFixture = new GetFilesRequestFixture();
|
||||
_fileResponseFixture = new FileResponseFixture();
|
||||
_sut = Factory.Create<GetFilesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -45,9 +47,9 @@ public class GetFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResultWithFileResponses()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
GetFilesRequest request = _getFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileResponse> expectedResponses = [.. _fixture.CreateMany<FileResponse>(3)];
|
||||
List<FileResponse> expectedResponses = [.. _fileResponseFixture.CreateMany(3)];
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
@@ -63,7 +65,7 @@ public class GetFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
GetFilesRequest request = _getFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -89,7 +91,7 @@ public class GetFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
GetFilesRequest request = _getFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -115,7 +117,7 @@ public class GetFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetFilesQueryToSender()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
GetFilesRequest request = _getFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<FileResponse>()));
|
||||
@@ -134,7 +136,7 @@ public class GetFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
GetFilesRequest request = _getFilesRequestFixture.Create();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
@@ -145,7 +147,7 @@ public class GetFilesEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(_fixture.CreateMany<FileResponse>(3).AsEnumerable());
|
||||
return Result.From(_fileResponseFixture.CreateMany(3).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
+9
-10
@@ -1,14 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Files.GetTreeFiles;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -28,19 +27,19 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly IQueryHandler<GetTreeFilesQuery, Result<IEnumerable<FileSystemTreeNodeResponse>>> _mockHandler;
|
||||
private readonly GetTreeFilesEndpoint _sut;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
private readonly GetTreeFilesRequestFixture _getTreeFilesRequestFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeFilesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetTreeFilesQuery, Result<IEnumerable<FileSystemTreeNodeResponse>>>>();
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
_getTreeFilesRequestFixture = new GetTreeFilesRequestFixture();
|
||||
_sut = Factory.Create<GetTreeFilesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -48,7 +47,7 @@ public class GetTreeFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResultWithFileSystemTreeNodeResponses()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
GetTreeFilesRequest request = _getTreeFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5);
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -66,7 +65,7 @@ public class GetTreeFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
GetTreeFilesRequest request = _getTreeFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -92,7 +91,7 @@ public class GetTreeFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
GetTreeFilesRequest request = _getTreeFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -118,7 +117,7 @@ public class GetTreeFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetTreeFilesQueryToSender()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
GetTreeFilesRequest request = _getTreeFilesRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
@@ -137,7 +136,7 @@ public class GetTreeFilesEndpointTests
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
GetTreeFilesRequest request = _getTreeFilesRequestFixture.Create();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CheckPathExistsRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="CheckPathExistsRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to check.</param>
|
||||
/// <param name="includeHiddenElements">Whether to include hidden elements.</param>
|
||||
/// <returns>The created <see cref="CheckPathExistsRequest"/>.</returns>
|
||||
public CheckPathExistsRequest Create(string? path = null, bool? includeHiddenElements = null)
|
||||
{
|
||||
return new CheckPathExistsRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
IncludeHiddenElements: includeHiddenElements ?? _faker.Random.Bool()
|
||||
);
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="CombinePathRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="CombinePathRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="originalPath">The original path.</param>
|
||||
/// <param name="newPath">The new path to combine.</param>
|
||||
/// <returns>The created <see cref="CombinePathRequest"/>.</returns>
|
||||
public CombinePathRequest Create(string? originalPath = null, string? newPath = null)
|
||||
{
|
||||
return new CombinePathRequest(
|
||||
OriginalPath: originalPath ?? _faker.System.DirectoryPath(),
|
||||
NewPath: newPath ?? _faker.System.FileName()
|
||||
);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemTreeNodeResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeNodeResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single <see cref="FileSystemTreeNodeResponse"/> with a nested structure.
|
||||
/// </summary>
|
||||
/// <param name="currentDepth">The current depth in the tree structure. Default is 0 (root level).</param>
|
||||
/// <param name="maxDepth">The maximum depth of the tree structure. Default is 2.</param>
|
||||
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
|
||||
/// <returns>A <see cref="FileSystemTreeNodeResponse"/> with a nested structure.</returns>
|
||||
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3)
|
||||
{
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = _faker.System.FilePath(),
|
||||
Name = _faker.System.FileName(),
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = _faker.Random.Bool(),
|
||||
ChildrenLoaded = true,
|
||||
Children = []
|
||||
};
|
||||
if (currentDepth < maxDepth)
|
||||
{
|
||||
int childCount = _faker.Random.Int(1, maxChildren);
|
||||
for (int i = 0; i < childCount; i++)
|
||||
response.Children.Add(Create(currentDepth + 1, maxDepth, maxChildren));
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FileSystemTreeNodeResponse"/> objects, each with a nested structure.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of root-level nodes to create. Default is 2.</param>
|
||||
/// <param name="maxDepth">The maximum depth of the tree structure for each root node. Default is 2.</param>
|
||||
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
|
||||
/// <returns>A list of <see cref="FileSystemTreeNodeResponse"/> objects with nested structures.</returns>
|
||||
public List<FileSystemTreeNodeResponse> CreateMany(int count = 2, int maxDepth = 2, int maxChildren = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren)).ToList();
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPathParentRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="GetPathParentRequest"/> with a default or random value.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to get the parent of.</param>
|
||||
/// <returns>The created <see cref="GetPathParentRequest"/>.</returns>
|
||||
public GetPathParentRequest Create(string? path = null)
|
||||
{
|
||||
return new GetPathParentRequest(
|
||||
Path: path ?? _faker.System.FilePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetPathRootRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="GetPathRootRequest"/> with a default or random value.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to get the root of.</param>
|
||||
/// <returns>The created <see cref="GetPathRootRequest"/>.</returns>
|
||||
public GetPathRootRequest Create(string? path = null)
|
||||
{
|
||||
return new GetPathRootRequest(
|
||||
Path: path ?? _faker.System.FilePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetThumbnailRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="GetThumbnailRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the file to get the thumbnail for.</param>
|
||||
/// <param name="quality">The quality of the thumbnail.</param>
|
||||
/// <returns>The created <see cref="GetThumbnailRequest"/>.</returns>
|
||||
public GetThumbnailRequest Create(string? path = null, int? quality = null)
|
||||
{
|
||||
return new GetThumbnailRequest(
|
||||
Path: path ?? _faker.System.FilePath(),
|
||||
Quality: quality ?? _faker.Random.Int(1, 100)
|
||||
);
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSegmentResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSegmentResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PathSegmentResponse"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="PathSegmentResponse"/>.</returns>
|
||||
public PathSegmentResponse Create()
|
||||
{
|
||||
return new PathSegmentResponse(_faker.System.DirectoryPath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PathSegmentResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<PathSegmentResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="PathSeparatorResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSeparatorResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="PathSeparatorResponse"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="PathSeparatorResponse"/>.</returns>
|
||||
public PathSeparatorResponse Create()
|
||||
{
|
||||
return new PathSeparatorResponse(_faker.System.DirectoryPath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="PathSeparatorResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<PathSeparatorResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="SplitPathRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="SplitPathRequest"/> with a default or random value.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to split.</param>
|
||||
/// <returns>The created <see cref="SplitPathRequest"/>.</returns>
|
||||
public SplitPathRequest Create(string? path = null)
|
||||
{
|
||||
return new SplitPathRequest(
|
||||
Path: path ?? _faker.System.FilePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThumbnailResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailResponseFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid query to get a thumbnail.
|
||||
/// </summary>
|
||||
/// <returns>The created query.</returns>
|
||||
public static ThumbnailResponse CreateThumbnailResponse()
|
||||
{
|
||||
return new Faker<ThumbnailResponse>()
|
||||
.CustomInstantiator(f => new ThumbnailResponse(
|
||||
default,
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.Type, f => f.PickRandom<ImageType>())
|
||||
.RuleFor(x => x.Bytes, f => f.Random.Bytes(20));
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ValidatePathRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ValidatePathRequest"/> with a default or random value.
|
||||
/// </summary>
|
||||
/// <param name="path">The path to validate.</param>
|
||||
/// <returns>The created <see cref="ValidatePathRequest"/>.</returns>
|
||||
public ValidatePathRequest Create(string? path = null)
|
||||
{
|
||||
return new ValidatePathRequest(
|
||||
Path: path ?? _faker.System.FilePath()
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,11 +2,11 @@
|
||||
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.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CheckPathExists;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
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;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CombinePath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+2
-1
@@ -2,11 +2,12 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
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;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathParent;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+2
-1
@@ -2,11 +2,12 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
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;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathRoot;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+1
-1
@@ -2,9 +2,9 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
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 Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+2
-1
@@ -1,11 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
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;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.SplitPath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+1
-1
@@ -2,11 +2,11 @@
|
||||
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.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.ValidatePath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+7
-4
@@ -2,12 +2,13 @@
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
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 Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -28,6 +29,7 @@ public class GetThumbnailEndpointTests
|
||||
private readonly IQueryHandler<GetThumbnailQuery, Result<ThumbnailResponse>> _mockHandler;
|
||||
private readonly GetThumbnailEndpoint _sut;
|
||||
private readonly GetThumbnailRequestFixture _getThumbnailRequestFixture;
|
||||
private readonly ThumbnailResponseFixture _thumbnailResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThumbnailEndpointTests"/> class.
|
||||
@@ -37,6 +39,7 @@ public class GetThumbnailEndpointTests
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetThumbnailQuery, Result<ThumbnailResponse>>>();
|
||||
_sut = Factory.Create<GetThumbnailEndpoint>(_mockHandler);
|
||||
_getThumbnailRequestFixture = new GetThumbnailRequestFixture();
|
||||
_thumbnailResponseFixture = new ThumbnailResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,7 +48,7 @@ public class GetThumbnailEndpointTests
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ThumbnailResponse expectedResponse = ThumbnailResponseFixture.CreateThumbnailResponse();
|
||||
ThumbnailResponse expectedResponse = _thumbnailResponseFixture.Create();
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(expectedResponse));
|
||||
|
||||
@@ -117,7 +120,7 @@ public class GetThumbnailEndpointTests
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Result.From(ThumbnailResponseFixture.CreateThumbnailResponse()));
|
||||
.Returns(Result.From(_thumbnailResponseFixture.Create()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
@@ -141,7 +144,7 @@ public class GetThumbnailEndpointTests
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return Result.From(ThumbnailResponseFixture.CreateThumbnailResponse());
|
||||
return Result.From(_thumbnailResponseFixture.Create());
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RegistrationRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegistrationRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RegistrationRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="username">The username for registration.</param>
|
||||
/// <param name="password">The password for registration.</param>
|
||||
/// <param name="passwordConfirm">The password confirmation.</param>
|
||||
/// <param name="use2fa">Whether to use two-factor authentication.</param>
|
||||
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
|
||||
public RegistrationRequest Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
string? passwordConfirm = null,
|
||||
bool? use2fa = null)
|
||||
{
|
||||
string generatedPassword = password ?? _faker.Internet.Password();
|
||||
return new RegistrationRequest(
|
||||
Username: username ?? _faker.Internet.UserName(),
|
||||
Password: generatedPassword,
|
||||
PasswordConfirm: passwordConfirm ?? generatedPassword,
|
||||
Use2fa: use2fa ?? _faker.Random.Bool()
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.Maintenance.ApplicationSetup;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
+1
-1
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.ChangePassword;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.ChangePassword.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.ChangePassword.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ChangePasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ChangePasswordRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="username">The username for the password change.</param>
|
||||
/// <param name="currentPassword">The current password.</param>
|
||||
/// <param name="newPassword">The new password.</param>
|
||||
/// <param name="newPasswordConfirm">The new password confirmation.</param>
|
||||
/// <returns>The created <see cref="ChangePasswordRequest"/>.</returns>
|
||||
public ChangePasswordRequest Create(
|
||||
string? username = null,
|
||||
string? currentPassword = null,
|
||||
string? newPassword = null,
|
||||
string? newPasswordConfirm = null)
|
||||
{
|
||||
string generatedNewPassword = newPassword ?? _faker.Internet.Password();
|
||||
return new ChangePasswordRequest(
|
||||
Username: username ?? _faker.Internet.UserName(),
|
||||
CurrentPassword: currentPassword ?? _faker.Internet.Password(),
|
||||
NewPassword: generatedNewPassword,
|
||||
NewPasswordConfirm: newPasswordConfirm ?? generatedNewPassword
|
||||
);
|
||||
}
|
||||
}
|
||||
-35
@@ -1,35 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.Login.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="LoginRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LoginRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="username">The username for login.</param>
|
||||
/// <param name="password">The password for login.</param>
|
||||
/// <param name="totpCode">The TOTP code for two-factor authentication.</param>
|
||||
/// <returns>The created <see cref="LoginRequest"/>.</returns>
|
||||
public LoginRequest Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
string? totpCode = null)
|
||||
{
|
||||
return new LoginRequest(
|
||||
Username: username ?? _faker.Internet.UserName(),
|
||||
Password: password ?? _faker.Internet.Password(),
|
||||
TotpCode: totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,11 +2,11 @@
|
||||
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.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Login;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.Login.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.RecoverPassword.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RecoverPasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RecoverPasswordRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="username">The username for password recovery.</param>
|
||||
/// <param name="totpCode">The TOTP code for verification.</param>
|
||||
/// <returns>The created <see cref="RecoverPasswordRequest"/>.</returns>
|
||||
public RecoverPasswordRequest Create(
|
||||
string? username = null,
|
||||
string? totpCode = null)
|
||||
{
|
||||
return new RecoverPasswordRequest(
|
||||
Username: username ?? _faker.Internet.UserName(),
|
||||
TotpCode: totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.RecoverPassword;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.RecoverPassword.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authentication.Register.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="RegistrationRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegistrationRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RegistrationRequest"/> with default or random values.
|
||||
/// </summary>
|
||||
/// <param name="username">The username for registration.</param>
|
||||
/// <param name="password">The password for registration.</param>
|
||||
/// <param name="passwordConfirm">The password confirmation.</param>
|
||||
/// <param name="use2fa">Whether to use two-factor authentication.</param>
|
||||
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
|
||||
public RegistrationRequest Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
string? passwordConfirm = null,
|
||||
bool? use2fa = null)
|
||||
{
|
||||
string generatedPassword = password ?? _faker.Internet.Password();
|
||||
return new RegistrationRequest(
|
||||
Username: username ?? _faker.Internet.UserName(),
|
||||
Password: generatedPassword,
|
||||
PasswordConfirm: passwordConfirm ?? generatedPassword,
|
||||
Use2fa: use2fa ?? _faker.Random.Bool()
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.UsersManagement.Authentication.Register;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.Maintenance.ApplicationSetup.Fixtures;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authorization.GetAuthorization.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetAuthorizationRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAuthorizationRequestFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="GetAuthorizationRequest"/> with default or specified values.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional user Id to use.</param>
|
||||
/// <returns>The created <see cref="GetAuthorizationRequest"/>.</returns>
|
||||
public static GetAuthorizationRequest Create(Guid? userId = null)
|
||||
{
|
||||
return new GetAuthorizationRequest(
|
||||
UserId: userId ?? Guid.NewGuid()
|
||||
);
|
||||
}
|
||||
}
|
||||
+7
-5
@@ -2,12 +2,12 @@
|
||||
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.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
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 Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -29,6 +29,7 @@ public class GetAuthorizationEndpointTests
|
||||
{
|
||||
private readonly IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>> _mockHandler;
|
||||
private readonly GetAuthorizationEndpoint _sut;
|
||||
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetAuthorizationEndpointTests"/> class.
|
||||
@@ -36,6 +37,7 @@ public class GetAuthorizationEndpointTests
|
||||
public GetAuthorizationEndpointTests()
|
||||
{
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetAuthorizationQuery, Result<AuthorizationResponse>>>();
|
||||
_getAuthorizationRequestFixture = new GetAuthorizationRequestFixture();
|
||||
_sut = Factory.Create<GetAuthorizationEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
@@ -43,7 +45,7 @@ public class GetAuthorizationEndpointTests
|
||||
public async Task ExecuteAsync_WhenSuccessful_ShouldReturnOkResultWithAuthorizationResponse()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
AuthorizationResponse expectedResponse = new(
|
||||
request.UserId!.Value,
|
||||
@@ -65,7 +67,7 @@ public class GetAuthorizationEndpointTests
|
||||
public async Task ExecuteAsync_WhenHandlerReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Unauthorized("Authorization.Failed", "User is not authorized.");
|
||||
|
||||
@@ -92,7 +94,7 @@ public class GetAuthorizationEndpointTests
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetAuthorizationQueryToSender()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
|
||||
_mockHandler.HandleAsync(Arg.Any<GetAuthorizationQuery>(), Arg.Any<CancellationToken>())
|
||||
@@ -116,7 +118,7 @@ public class GetAuthorizationEndpointTests
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = GetAuthorizationRequestFixture.Create();
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
Reference in new issue
Block a user