mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Replaces FluentValidation and Mediator command/queries handling with custom implementations.
This commit is contained in:
1 parent
9a5c7473f9
commit
2d1c6b1ab8
297 files changed
+3619
-3045
No files matched your search
+12
-12
@@ -3,11 +3,11 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetDirectories;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -28,7 +28,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
public class GetDirectoriesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>> _mockHandler;
|
||||
private readonly GetDirectoriesEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -37,8 +37,8 @@ public class GetDirectoriesEndpointTests
|
||||
public GetDirectoriesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetDirectoriesEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetDirectoriesQuery, ErrorOr<IEnumerable<DirectoryResponse>>>>();
|
||||
_sut = Factory.Create<GetDirectoriesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -48,7 +48,7 @@ public class GetDirectoriesEndpointTests
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<DirectoryResponse> expectedResponses = _fixture.CreateMany<DirectoryResponse>(3).ToList();
|
||||
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
@@ -66,7 +66,7 @@ public class GetDirectoriesEndpointTests
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Directory.NotFound", "The requested directory was not found.");
|
||||
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -92,7 +92,7 @@ public class GetDirectoriesEndpointTests
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -117,14 +117,14 @@ public class GetDirectoriesEndpointTests
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<DirectoryResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
Arg.Is<GetDirectoriesQuery>(q => q.Path == request.Path && q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
@@ -138,14 +138,14 @@ public class GetDirectoriesEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<DirectoryResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_fixture.CreateMany<DirectoryResponse>(3).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+11
-11
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Drives.GetDrives;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDrivesEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> _mockHandler;
|
||||
private readonly GetDrivesEndpoint _sut;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
@@ -34,9 +34,9 @@ public class GetDrivesEndpointTests
|
||||
/// </summary>
|
||||
public GetDrivesEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetDrivesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>>();
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
_sut = Factory.Create<GetDrivesEndpoint>(_mockSender);
|
||||
_sut = Factory.Create<GetDrivesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -45,7 +45,7 @@ public class GetDrivesEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 1, 1);
|
||||
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
@@ -62,7 +62,7 @@ public class GetDrivesEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Drive.NotFound", "The requested drive was not found.");
|
||||
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -86,14 +86,14 @@ public class GetDrivesEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Any<GetDrivesQuery>(), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -104,14 +104,14 @@ public class GetDrivesEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetDrivesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_fileSystemTreeNodeResponseFixture.CreateMany(3, 1, 1).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
|
||||
+11
-11
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.FileSystem.GetType;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -22,7 +22,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFileSystemTypeEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse> _mockHandler;
|
||||
private readonly GetTypeEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -30,8 +30,8 @@ public class GetFileSystemTypeEndpointTests
|
||||
/// </summary>
|
||||
public GetFileSystemTypeEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetTypeEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetFileSystemQuery, FileSystemTypeResponse>>();
|
||||
_sut = Factory.Create<GetTypeEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -40,7 +40,7 @@ public class GetFileSystemTypeEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(PlatformType.Windows);
|
||||
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
@@ -59,7 +59,7 @@ public class GetFileSystemTypeEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
FileSystemTypeResponse expectedResponse = new(platformType);
|
||||
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
@@ -75,14 +75,14 @@ public class GetFileSystemTypeEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new FileSystemTypeResponse(PlatformType.Windows));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(new EmptyRequest(), cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Any<GetFileSystemQuery>(), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -93,14 +93,14 @@ public class GetFileSystemTypeEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<FileSystemTypeResponse>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFileSystemQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new FileSystemTypeResponse(PlatformType.Windows);
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(new EmptyRequest(), cts.Token);
|
||||
|
||||
+12
-12
@@ -3,12 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Presentation.Api.Common.Http;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Files.GetFiles;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -30,7 +30,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
public class GetFilesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>> _mockHandler;
|
||||
private readonly GetFilesEndpoint _sut;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,8 +39,8 @@ public class GetFilesEndpointTests
|
||||
public GetFilesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetFilesEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetFilesQuery, ErrorOr<IEnumerable<FileResponse>>>>();
|
||||
_sut = Factory.Create<GetFilesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -50,7 +50,7 @@ public class GetFilesEndpointTests
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileResponse> expectedResponses = _fixture.CreateMany<FileResponse>(3).ToList();
|
||||
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
@@ -68,7 +68,7 @@ public class GetFilesEndpointTests
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
|
||||
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -94,7 +94,7 @@ public class GetFilesEndpointTests
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -119,14 +119,14 @@ public class GetFilesEndpointTests
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Is<GetFilesQuery>(q =>
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetFilesQuery>(q =>
|
||||
q.Path == request.Path &&
|
||||
q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
@@ -141,14 +141,14 @@ public class GetFilesEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_fixture.CreateMany<FileResponse>(3).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+12
-12
@@ -3,12 +3,12 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Files.GetTreeFiles;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -29,7 +29,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
public class GetTreeFilesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>> _mockHandler;
|
||||
private readonly GetTreeFilesEndpoint _sut;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
@@ -39,9 +39,9 @@ public class GetTreeFilesEndpointTests
|
||||
public GetTreeFilesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetTreeFilesQuery, ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>>();
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
_sut = Factory.Create<GetTreeFilesEndpoint>(_mockSender);
|
||||
_sut = Factory.Create<GetTreeFilesEndpoint>(_mockHandler);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,7 +51,7 @@ public class GetTreeFilesEndpointTests
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5);
|
||||
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
@@ -69,7 +69,7 @@ public class GetTreeFilesEndpointTests
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("File.NotFound", "The requested file was not found.");
|
||||
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -95,7 +95,7 @@ public class GetTreeFilesEndpointTests
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -120,14 +120,14 @@ public class GetTreeFilesEndpointTests
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Is<GetTreeFilesQuery>(q =>
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetTreeFilesQuery>(q =>
|
||||
q.Path == request.Path &&
|
||||
q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
@@ -142,14 +142,14 @@ public class GetTreeFilesEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetTreeFilesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5).AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+10
-10
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CheckPathExists;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CheckPathExistsEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<CheckPathExistsQuery, ErrorOr<PathExistsResponse>> _mockHandler;
|
||||
private readonly CheckPathExistsEndpoint _sut;
|
||||
private readonly CheckPathExistsRequestFixture _checkPathExistsRequestFixture;
|
||||
|
||||
@@ -33,8 +33,8 @@ public class CheckPathExistsEndpointTests
|
||||
/// </summary>
|
||||
public CheckPathExistsEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<CheckPathExistsEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<CheckPathExistsQuery, ErrorOr<PathExistsResponse>>>();
|
||||
_sut = Factory.Create<CheckPathExistsEndpoint>(_mockHandler);
|
||||
_checkPathExistsRequestFixture = new CheckPathExistsRequestFixture();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CheckPathExistsEndpointTests
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathExistsResponse expectedResponse = new(true);
|
||||
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
@@ -62,14 +62,14 @@ public class CheckPathExistsEndpointTests
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path: @"C:\Users\TestUser\Documents", includeHiddenElements: true);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathExistsResponse(true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
Arg.Is<CheckPathExistsQuery>(q => q.Path == request.Path && q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
@@ -83,14 +83,14 @@ public class CheckPathExistsEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<PathExistsResponse>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<CheckPathExistsQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(new PathExistsResponse(true));
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+12
-13
@@ -1,12 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.CombinePath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -24,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CombinePathEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly ICommandHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>> _mockHandler;
|
||||
private readonly CombinePathEndpoint _sut;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
private readonly CombinePathRequestFixture _combinePathRequestFixture;
|
||||
@@ -34,8 +33,8 @@ public class CombinePathEndpointTests
|
||||
/// </summary>
|
||||
public CombinePathEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<CombinePathEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<ICommandHandler<CombinePathCommand, ErrorOr<PathSegmentResponse>>>();
|
||||
_sut = FastEndpoints.Factory.Create<CombinePathEndpoint>(_mockHandler);
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
_combinePathRequestFixture = new CombinePathRequestFixture();
|
||||
}
|
||||
@@ -47,7 +46,7 @@ public class CombinePathEndpointTests
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("C:\\Users", "TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathSegmentResponse expectedResponse = _pathSegmentResponseFixture.Create();
|
||||
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
@@ -65,7 +64,7 @@ public class CombinePathEndpointTests
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
|
||||
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -91,7 +90,7 @@ public class CombinePathEndpointTests
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("InvalidPath", "TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -116,14 +115,14 @@ public class CombinePathEndpointTests
|
||||
// Arrange
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create("C:\\Users", "TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.Create()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
Arg.Is<CombinePathCommand>(c => c.OriginalPath == request.OriginalPath && c.NewPath == request.NewPath),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
@@ -137,14 +136,14 @@ public class CombinePathEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<CombinePathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathParent;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -26,7 +26,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathParentEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>> _mockHandler;
|
||||
private readonly GetPathParentEndpoint _sut;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
private readonly GetPathParentRequestFixture _getPathParentRequestFixture;
|
||||
@@ -36,8 +36,8 @@ public class GetPathParentEndpointTests
|
||||
/// </summary>
|
||||
public GetPathParentEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetPathParentEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetPathParentQuery, ErrorOr<IEnumerable<PathSegmentResponse>>>>();
|
||||
_sut = Factory.Create<GetPathParentEndpoint>(_mockHandler);
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
_getPathParentRequestFixture = new GetPathParentRequestFixture();
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public class GetPathParentEndpointTests
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<PathSegmentResponse> expectedResponse = _pathSegmentResponseFixture.CreateMany();
|
||||
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
@@ -67,7 +67,7 @@ public class GetPathParentEndpointTests
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
|
||||
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -93,7 +93,7 @@ public class GetPathParentEndpointTests
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"InvalidPath");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -118,14 +118,14 @@ public class GetPathParentEndpointTests
|
||||
// Arrange
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Is<GetPathParentQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetPathParentQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -137,14 +137,14 @@ public class GetPathParentEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathParentQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+12
-12
@@ -1,12 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathRoot;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -24,7 +24,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathRootEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>> _mockHandler;
|
||||
private readonly GetPathRootEndpoint _sut;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
private readonly GetPathRootRequestFixture _getPathRootRequestFixture;
|
||||
@@ -34,8 +34,8 @@ public class GetPathRootEndpointTests
|
||||
/// </summary>
|
||||
public GetPathRootEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetPathRootEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetPathRootQuery, ErrorOr<PathSegmentResponse>>>();
|
||||
_sut = Factory.Create<GetPathRootEndpoint>(_mockHandler);
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
_getPathRootRequestFixture = new GetPathRootRequestFixture();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class GetPathRootEndpointTests
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathSegmentResponse expectedResponse = _pathSegmentResponseFixture.Create();
|
||||
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
@@ -65,7 +65,7 @@ public class GetPathRootEndpointTests
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Path.NotFound", "The requested path was not found.");
|
||||
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -91,7 +91,7 @@ public class GetPathRootEndpointTests
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"InvalidPath");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -116,14 +116,14 @@ public class GetPathRootEndpointTests
|
||||
// Arrange
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(@"C:\Users\TestUser");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.Create()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Is<GetPathRootQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetPathRootQuery>(q => q.Path == request.Path), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -135,14 +135,14 @@ public class GetPathRootEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<PathSegmentResponse>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathRootQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(_pathSegmentResponseFixture.Create());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+10
-10
@@ -1,10 +1,10 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathSeparator;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.GetPathSeparator;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -22,7 +22,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPathSeparatorEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetPathSeparatorQuery, PathSeparatorResponse> _mockHandler;
|
||||
private readonly GetPathSeparatorEndpoint _sut;
|
||||
private readonly PathSeparatorResponseFixture _pathSeparatorResponseFixture;
|
||||
|
||||
@@ -31,8 +31,8 @@ public class GetPathSeparatorEndpointTests
|
||||
/// </summary>
|
||||
public GetPathSeparatorEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetPathSeparatorEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetPathSeparatorQuery, PathSeparatorResponse>>();
|
||||
_sut = Factory.Create<GetPathSeparatorEndpoint>(_mockHandler);
|
||||
_pathSeparatorResponseFixture = new PathSeparatorResponseFixture();
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class GetPathSeparatorEndpointTests
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathSeparatorResponse expectedResponse = _pathSeparatorResponseFixture.Create();
|
||||
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
@@ -58,14 +58,14 @@ public class GetPathSeparatorEndpointTests
|
||||
{
|
||||
// Arrange
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(_pathSeparatorResponseFixture.Create());
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -76,14 +76,14 @@ public class GetPathSeparatorEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<PathSeparatorResponse>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetPathSeparatorQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return _pathSeparatorResponseFixture.Create();
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(cts.Token);
|
||||
|
||||
+11
-12
@@ -1,12 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.SplitPath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -26,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SplitPathEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly ICommandHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>> _mockHandler;
|
||||
private readonly SplitPathEndpoint _sut;
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture;
|
||||
private readonly SplitPathRequestFixture _splitPathRequestFixture;
|
||||
@@ -36,8 +35,8 @@ public class SplitPathEndpointTests
|
||||
/// </summary>
|
||||
public SplitPathEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<SplitPathEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<ICommandHandler<SplitPathCommand, ErrorOr<IEnumerable<PathSegmentResponse>>>>();
|
||||
_sut = FastEndpoints.Factory.Create<SplitPathEndpoint>(_mockHandler);
|
||||
_pathSegmentResponseFixture = new PathSegmentResponseFixture();
|
||||
_splitPathRequestFixture = new SplitPathRequestFixture();
|
||||
}
|
||||
@@ -49,7 +48,7 @@ public class SplitPathEndpointTests
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
IEnumerable<PathSegmentResponse> expectedResponse = _pathSegmentResponseFixture.CreateMany();
|
||||
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
@@ -67,7 +66,7 @@ public class SplitPathEndpointTests
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(@"InvalidPath");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -93,14 +92,14 @@ public class SplitPathEndpointTests
|
||||
// Arrange
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(_pathSegmentResponseFixture.CreateMany().AsEnumerable()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
Arg.Is<SplitPathCommand>(c => c.Path == request.Path),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
@@ -114,8 +113,8 @@ public class SplitPathEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<PathSegmentResponse>>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<SplitPathCommand>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
@@ -124,7 +123,7 @@ public class SplitPathEndpointTests
|
||||
{
|
||||
_pathSegmentResponseFixture.Create()
|
||||
}.AsEnumerable());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+10
-10
@@ -1,11 +1,11 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Path.ValidatePath;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -23,7 +23,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidatePathEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<ValidatePathQuery, PathValidResponse> _mockHandler;
|
||||
private readonly ValidatePathEndpoint _sut;
|
||||
private readonly ValidatePathRequestFixture _validatePathRequestFixture;
|
||||
|
||||
@@ -32,8 +32,8 @@ public class ValidatePathEndpointTests
|
||||
/// </summary>
|
||||
public ValidatePathEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<ValidatePathEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<ValidatePathQuery, PathValidResponse>>();
|
||||
_sut = Factory.Create<ValidatePathEndpoint>(_mockHandler);
|
||||
_validatePathRequestFixture = new ValidatePathRequestFixture();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ValidatePathEndpointTests
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
PathValidResponse expectedResponse = new(true);
|
||||
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedResponse);
|
||||
|
||||
// Act
|
||||
@@ -61,14 +61,14 @@ public class ValidatePathEndpointTests
|
||||
// Arrange
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(@"C:\Users\TestUser\Documents");
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new PathValidResponse(true));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
await _mockHandler.Received(1).HandleAsync(
|
||||
Arg.Is<ValidatePathQuery>(q => q.Path == request.Path),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
@@ -82,14 +82,14 @@ public class ValidatePathEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<PathValidResponse>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<ValidatePathQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return new PathValidResponse(true);
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
+12
-12
@@ -1,13 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Presentation.Api.Common.Utilities;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Thumbnails.GetThumbnail;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
@@ -25,7 +25,7 @@ namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailEndpointTests
|
||||
{
|
||||
private readonly ISender _mockSender;
|
||||
private readonly IQueryHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>> _mockHandler;
|
||||
private readonly GetThumbnailEndpoint _sut;
|
||||
private readonly GetThumbnailRequestFixture _getThumbnailRequestFixture;
|
||||
|
||||
@@ -34,8 +34,8 @@ public class GetThumbnailEndpointTests
|
||||
/// </summary>
|
||||
public GetThumbnailEndpointTests()
|
||||
{
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetThumbnailEndpoint>(_mockSender);
|
||||
_mockHandler = Substitute.For<IQueryHandler<GetThumbnailQuery, ErrorOr<ThumbnailResponse>>>();
|
||||
_sut = Factory.Create<GetThumbnailEndpoint>(_mockHandler);
|
||||
_getThumbnailRequestFixture = new GetThumbnailRequestFixture();
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GetThumbnailEndpointTests
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
ThumbnailResponse expectedResponse = ThumbnailResponseFixture.CreateThumbnailResponse();
|
||||
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponse));
|
||||
|
||||
// Act
|
||||
@@ -65,7 +65,7 @@ public class GetThumbnailEndpointTests
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Thumbnail.NotFound", "The requested thumbnail was not found.");
|
||||
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -91,7 +91,7 @@ public class GetThumbnailEndpointTests
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/nonexistent/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
@@ -116,14 +116,14 @@ public class GetThumbnailEndpointTests
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create("/path/to/file.jpg", 80);
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(ThumbnailResponseFixture.CreateThumbnailResponse()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(Arg.Is<GetThumbnailQuery>(q => q.Path == request.Path && q.Quality == request.Quality), Arg.Is(cancellationToken));
|
||||
await _mockHandler.Received(1).HandleAsync(Arg.Is<GetThumbnailQuery>(q => q.Path == request.Path && q.Quality == request.Quality), Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -135,14 +135,14 @@ public class GetThumbnailEndpointTests
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<ThumbnailResponse>>(Task.Run(async () =>
|
||||
_mockHandler.HandleAsync(Arg.Any<GetThumbnailQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => Task.Run(async () =>
|
||||
{
|
||||
operationStarted.SetResult(true);
|
||||
await cancellationRequested.Task;
|
||||
callInfo.Arg<CancellationToken>().ThrowIfCancellationRequested();
|
||||
return ErrorOrFactory.From(ThumbnailResponseFixture.CreateThumbnailResponse());
|
||||
}, callInfo.Arg<CancellationToken>())));
|
||||
}, callInfo.Arg<CancellationToken>()));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
|
||||
Reference in new issue
Block a user