Replaces MVC with FastEndpoints in Lumina.Presentation.Api

This commit is contained in:
BinaryAlley committed 2024-10-23 21:34:10 +03:00
1 parent b1a20716df
commit c7b8bc2f1c
519 files changed
+15329 -8539

No files matched your search

@@ -0,0 +1,33 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
/// <summary>
/// Fixture class for the <see cref="UnixRootItem"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UnixRootItemFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UnixRootItem"/>.
/// </summary>
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
public UnixRootItem Create()
{
ErrorOr<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
_faker.PickRandom<FileSystemItemStatus>()
);
if (unixRootItemResult.IsError)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", unixRootItemResult.Errors));
return unixRootItemResult.Value;
}
}
@@ -0,0 +1,35 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using ErrorOr;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
/// <summary>
/// Fixture class for the <see cref="WindowsRootItem"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class WindowsRootItemFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="WindowsRootItem"/>.
/// </summary>
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
public WindowsRootItem Create()
{
ErrorOr<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.PickRandom<FileSystemItemStatus>()
);
if (windowsRootItemResult.IsError)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", windowsRootItemResult.Errors));
return windowsRootItemResult.Value;
}
}
@@ -0,0 +1,108 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using Lumina.Contracts.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Strategies.Platform;
using NSubstitute;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
/// <summary>
/// Contains unit tests for the <see cref="GetFileSystemQueryHandler"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetFileSystemQueryHandlerTests
{
private readonly IFixture _fixture;
private readonly IPlatformContextManager _mockPlatformContextManager;
private readonly IPlatformContext _mockPlatformContext;
private readonly GetFileSystemQueryHandler _sut;
/// <summary>
/// Initializes a new instance of the <see cref="GetFileSystemQueryHandlerTests"/> class.
/// </summary>
public GetFileSystemQueryHandlerTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockPlatformContextManager = Substitute.For<IPlatformContextManager>();
_mockPlatformContext = Substitute.For<IPlatformContext>();
_mockPlatformContextManager.GetCurrentContext().Returns(_mockPlatformContext);
_sut = new GetFileSystemQueryHandler(_mockPlatformContextManager);
}
[Theory]
[InlineData(PlatformType.Unix)]
[InlineData(PlatformType.Windows)]
public async Task Handle_WhenCalled_ShouldReturnCorrectFileSystemTypeResponse(PlatformType platformType)
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
_mockPlatformContext.Platform.Returns(platformType);
// Act
FileSystemTypeResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Should().NotBeNull();
result.PlatformType.Should().Be(platformType);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
[Fact]
public async Task Handle_WhenCalled_ShouldReturnValueTaskResult()
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
// Act
ValueTask<FileSystemTypeResponse> resultTask = _sut.Handle(query, CancellationToken.None);
// Assert
resultTask.IsCompleted.Should().BeTrue();
FileSystemTypeResponse result = await resultTask;
result.Should().NotBeNull();
result.PlatformType.Should().Be(PlatformType.Unix);
}
[Fact]
public async Task Handle_WhenCalled_ShouldNotDependOnQueryContent()
{
// Arrange
GetFileSystemQuery query1 = _fixture.Create<GetFileSystemQuery>();
GetFileSystemQuery query2 = _fixture.Create<GetFileSystemQuery>();
_mockPlatformContext.Platform.Returns(PlatformType.Windows);
// Act
FileSystemTypeResponse result1 = await _sut.Handle(query1, CancellationToken.None);
FileSystemTypeResponse result2 = await _sut.Handle(query2, CancellationToken.None);
// Assert
result1.Should().BeEquivalentTo(result2);
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
[Fact]
public async Task Handle_WhenCalled_ShouldIgnoreCancellationToken()
{
// Arrange
GetFileSystemQuery query = _fixture.Create<GetFileSystemQuery>();
_mockPlatformContext.Platform.Returns(PlatformType.Unix);
CancellationToken cancellationToken = new(true);
// Act
Func<Task> act = async () => await _sut.Handle(query, cancellationToken);
// Assert
await act.Should().NotThrowAsync();
_mockPlatformContextManager.Received(1).GetCurrentContext();
}
}