mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 17:11:10 +00:00
Removes unused file system API endpoints
This commit is contained in:
1 parent
8c579cd4bd
commit
532322eab2
35 files changed
-3111
No files matched your search
-170
@@ -1,170 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetDirectoryTree;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoryTreeEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoryTreeEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly ISender _mockSender;
|
||||
private readonly GetDirectoryTreeEndpoint _sut;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoryTreeEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetDirectoryTreeEndpoint>(_mockSender);
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResultWithFileSystemTreeNodeResponses()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5);
|
||||
_mockSender.Send(Arg.Any<GetDirectoryTreeQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
IEnumerable<FileSystemTreeNodeResponse> actualResponses = result.Should().BeOfType<Ok<IEnumerable<FileSystemTreeNodeResponse>>>().Subject.Value!;
|
||||
actualResponses.Should().BeEquivalentTo(expectedResponses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Directory.NotFound", "The requested directory was not found.");
|
||||
_mockSender.Send(Arg.Any<GetDirectoryTreeQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ProblemHttpResult>();
|
||||
ProblemHttpResult problemDetails = (ProblemHttpResult)result;
|
||||
problemDetails.StatusCode.Should().Be(StatusCodes.Status404NotFound);
|
||||
problemDetails.ContentType.Should().Be("application/problem+json");
|
||||
problemDetails.ProblemDetails.Should().BeOfType<Microsoft.AspNetCore.Mvc.ProblemDetails>();
|
||||
|
||||
problemDetails.ProblemDetails.Title.Should().Be("Directory.NotFound");
|
||||
problemDetails.ProblemDetails.Detail.Should().Be("The requested directory was not found.");
|
||||
problemDetails.ProblemDetails.Status.Should().Be(StatusCodes.Status404NotFound);
|
||||
problemDetails.ProblemDetails.Type.Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
|
||||
problemDetails.ProblemDetails.Extensions["traceId"].Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetDirectoryTreeQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ProblemHttpResult>();
|
||||
ProblemHttpResult problemDetails = (ProblemHttpResult)result;
|
||||
problemDetails.StatusCode.Should().Be(StatusCodes.Status422UnprocessableEntity);
|
||||
problemDetails.ContentType.Should().Be("application/problem+json");
|
||||
problemDetails.ProblemDetails.Should().BeOfType<HttpValidationProblemDetails>();
|
||||
HttpValidationProblemDetails validationProblemDetails = (HttpValidationProblemDetails)problemDetails.ProblemDetails;
|
||||
validationProblemDetails.Status.Should().Be(StatusCodes.Status422UnprocessableEntity);
|
||||
validationProblemDetails.Title.Should().Be("General.Validation");
|
||||
validationProblemDetails.Detail.Should().Be("OneOrMoreValidationErrorsOccurred");
|
||||
validationProblemDetails.Type.Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
|
||||
validationProblemDetails.Errors.Should().ContainSingle()
|
||||
.Which.Should().BeEquivalentTo(new
|
||||
{
|
||||
Key = "Path.Invalid",
|
||||
Value = new[] { "The provided path is invalid." }
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetDirectoryTreeQueryToMediator()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetDirectoryTreeQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
Arg.Is<GetDirectoryTreeQuery>(q => q.Path == request.Path && q.IncludeFiles == request.IncludeFiles && q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetDirectoryTreeQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(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>())));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
-170
@@ -1,170 +0,0 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FastEndpoints;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Presentation.Api.Core.Endpoints.FileSystemManagement.Directories.GetTreeDirectories;
|
||||
using Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
|
||||
using Mediator;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesEndpoint"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesEndpointTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
private readonly ISender _mockSender;
|
||||
private readonly GetTreeDirectoriesEndpoint _sut;
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesEndpointTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesEndpointTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
_mockSender = Substitute.For<ISender>();
|
||||
_sut = Factory.Create<GetTreeDirectoriesEndpoint>(_mockSender);
|
||||
_fileSystemTreeNodeResponseFixture = new FileSystemTreeNodeResponseFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldReturnOkResultWithFileSystemTreeNodeResponses()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
List<FileSystemTreeNodeResponse> expectedResponses = _fileSystemTreeNodeResponseFixture.CreateMany(3, 3, 5);
|
||||
_mockSender.Send(Arg.Any<GetTreeDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(expectedResponses.AsEnumerable()));
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
IEnumerable<FileSystemTreeNodeResponse> actualResponses = result.Should().BeOfType<Ok<IEnumerable<FileSystemTreeNodeResponse>>>().Subject.Value!;
|
||||
actualResponses.Should().BeEquivalentTo(expectedResponses);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsError_ShouldReturnProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.NotFound("Directory.NotFound", "The requested directory was not found.");
|
||||
_mockSender.Send(Arg.Any<GetTreeDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ProblemHttpResult>();
|
||||
ProblemHttpResult problemDetails = (ProblemHttpResult)result;
|
||||
problemDetails.StatusCode.Should().Be(StatusCodes.Status404NotFound);
|
||||
problemDetails.ContentType.Should().Be("application/problem+json");
|
||||
problemDetails.ProblemDetails.Should().BeOfType<Microsoft.AspNetCore.Mvc.ProblemDetails>();
|
||||
|
||||
problemDetails.ProblemDetails.Title.Should().Be("Directory.NotFound");
|
||||
problemDetails.ProblemDetails.Detail.Should().Be("The requested directory was not found.");
|
||||
problemDetails.ProblemDetails.Status.Should().Be(StatusCodes.Status404NotFound);
|
||||
problemDetails.ProblemDetails.Type.Should().Be("https://tools.ietf.org/html/rfc9110#section-15.5.5");
|
||||
problemDetails.ProblemDetails.Extensions["traceId"].Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenMediatorReturnsValidationError_ShouldReturnValidationProblemResult()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
Error expectedError = Error.Validation("Path.Invalid", "The provided path is invalid.");
|
||||
_mockSender.Send(Arg.Any<GetTreeDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(expectedError);
|
||||
|
||||
// Act
|
||||
IResult result = await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
result.Should().BeOfType<ProblemHttpResult>();
|
||||
ProblemHttpResult problemDetails = (ProblemHttpResult)result;
|
||||
problemDetails.StatusCode.Should().Be(StatusCodes.Status422UnprocessableEntity);
|
||||
problemDetails.ContentType.Should().Be("application/problem+json");
|
||||
problemDetails.ProblemDetails.Should().BeOfType<HttpValidationProblemDetails>();
|
||||
HttpValidationProblemDetails validationProblemDetails = (HttpValidationProblemDetails)problemDetails.ProblemDetails;
|
||||
validationProblemDetails.Status.Should().Be(StatusCodes.Status422UnprocessableEntity);
|
||||
validationProblemDetails.Title.Should().Be("General.Validation");
|
||||
validationProblemDetails.Detail.Should().Be("OneOrMoreValidationErrorsOccurred");
|
||||
validationProblemDetails.Type.Should().Be("https://tools.ietf.org/html/rfc4918#section-11.2");
|
||||
validationProblemDetails.Errors.Should().ContainSingle()
|
||||
.Which.Should().BeEquivalentTo(new
|
||||
{
|
||||
Key = "Path.Invalid",
|
||||
Value = new[] { "The provided path is invalid." }
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldSendGetTreeDirectoriesQueryToMediator()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
CancellationToken cancellationToken = CancellationToken.None;
|
||||
_mockSender.Send(Arg.Any<GetTreeDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(ErrorOrFactory.From(Enumerable.Empty<FileSystemTreeNodeResponse>()));
|
||||
|
||||
// Act
|
||||
await _sut.ExecuteAsync(request, cancellationToken);
|
||||
|
||||
// Assert
|
||||
await _mockSender.Received(1).Send(
|
||||
Arg.Is<GetTreeDirectoriesQuery>(q => q.Path == request.Path && q.IncludeHiddenElements == request.IncludeHiddenElements),
|
||||
Arg.Is(cancellationToken));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCancellationRequested_ShouldCancelOperation()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
CancellationTokenSource cts = new();
|
||||
TaskCompletionSource<bool> operationStarted = new();
|
||||
TaskCompletionSource<bool> cancellationRequested = new();
|
||||
|
||||
_mockSender.Send(Arg.Any<GetTreeDirectoriesQuery>(), Arg.Any<CancellationToken>())
|
||||
.Returns(callInfo => new ValueTask<ErrorOr<IEnumerable<FileSystemTreeNodeResponse>>>(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>())));
|
||||
|
||||
// Act
|
||||
Task<IResult> operationTask = _sut.ExecuteAsync(request, cts.Token);
|
||||
await operationStarted.Task;
|
||||
cts.Cancel();
|
||||
cancellationRequested.SetResult(true);
|
||||
|
||||
// Assert
|
||||
await Assert.ThrowsAnyAsync<OperationCanceledException>(() => operationTask);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user