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,82 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="CheckPathExistsQueryMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CheckPathExistsQueryMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="CheckPathExistsQueryMappingTests"/> class.
/// </summary>
public CheckPathExistsQueryMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToQuery_WhenMappingCheckPathExistsRequest_ShouldMapCorrectly()
{
// Arrange
CheckPathExistsRequest request = _fixture.Create<CheckPathExistsRequest>();
// Act
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
}
[Theory]
[InlineData("/home/user/documents", true)]
[InlineData("C:\\Users\\Documents", false)]
[InlineData("/var/www/html", true)]
public void ToQuery_WhenMappingWithDifferentPathsAndHiddenElementsFlag_ShouldMapCorrectly(string path, bool includeHiddenElements)
{
// Arrange
CheckPathExistsRequest request = new(path, includeHiddenElements);
// Act
CheckPathExistsQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
result.IncludeHiddenElements.Should().Be(includeHiddenElements);
}
[Fact]
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<CheckPathExistsRequest> requests = _fixture.CreateMany<CheckPathExistsRequest>().ToList();
// Act
List<CheckPathExistsQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
results[i].IncludeHiddenElements.Should().Be(requests[i].IncludeHiddenElements);
}
}
}
@@ -0,0 +1,82 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="CombinePathRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CombinePathRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="CombinePathRequestMappingTests"/> class.
/// </summary>
public CombinePathRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToCommand_WhenMappingCombinePathRequest_ShouldMapCorrectly()
{
// Arrange
CombinePathRequest request = _fixture.Create<CombinePathRequest>();
// Act
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(request.OriginalPath);
result.NewPath.Should().Be(request.NewPath);
}
[Theory]
[InlineData("/home/user", "documents")]
[InlineData("C:\\Users", "Documents")]
[InlineData("/var/www", "html")]
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string originalPath, string newPath)
{
// Arrange
CombinePathRequest request = new(originalPath, newPath);
// Act
CombinePathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.OriginalPath.Should().Be(originalPath);
result.NewPath.Should().Be(newPath);
}
[Fact]
public void ToCommand_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<CombinePathRequest> requests = _fixture.CreateMany<CombinePathRequest>().ToList();
// Act
List<CombinePathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].OriginalPath.Should().Be(requests[i].OriginalPath);
results[i].NewPath.Should().Be(requests[i].NewPath);
}
}
}
@@ -0,0 +1,79 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="GetPathParentRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathParentRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetPathParentRequestMappingTests"/> class.
/// </summary>
public GetPathParentRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToQuery_WhenMappingGetPathParentRequest_ShouldMapCorrectly()
{
// Arrange
GetPathParentRequest request = _fixture.Create<GetPathParentRequest>();
// Act
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
}
[Theory]
[InlineData("/home/user/documents")]
[InlineData("C:\\Users\\Documents")]
[InlineData("/var/www/html")]
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
{
// Arrange
GetPathParentRequest request = new(path);
// Act
GetPathParentQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
}
[Fact]
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<GetPathParentRequest> requests = _fixture.CreateMany<GetPathParentRequest>().ToList();
// Act
List<GetPathParentQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
}
}
}
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="GetPathRootRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathRootRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="GetPathRootRequestMappingTests"/> class.
/// </summary>
public GetPathRootRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToQuery_WhenMappingGetPathRootRequest_ShouldMapCorrectly()
{
// Arrange
GetPathRootRequest request = _fixture.Create<GetPathRootRequest>();
// Act
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
}
[Theory]
[InlineData("/home/user/documents")]
[InlineData("C:\\Users\\Documents")]
[InlineData("/var/www/html")]
[InlineData("D:\\Projects\\MyProject")]
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
{
// Arrange
GetPathRootRequest request = new(path);
// Act
GetPathRootQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
}
[Fact]
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<GetPathRootRequest> requests = _fixture.CreateMany<GetPathRootRequest>().ToList();
// Act
List<GetPathRootQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
{
results[i].Path.Should().Be(requests[i].Path);
}
}
}
@@ -0,0 +1,77 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Contracts.Responses.FileSystemManagement.Path;
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="PathSegmentMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PathSegmentMappingTests
{
[Fact]
public void ToResponse_WhenMappingPathSegment_ShouldMapCorrectly()
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
createResult.IsError.Should().BeFalse();
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
}
[Theory]
[InlineData("Folder", true, false)]
[InlineData("File.txt", false, false)]
[InlineData("C:", false, true)]
public void ToResponse_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
createResult.IsError.Should().BeFalse();
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(pathSegment.Name);
}
[Fact]
public void ToResponses_WhenMappingMultiplePathSegments_ShouldMapAllCorrectly()
{
// Arrange
List<PathSegment> pathSegments =
[
PathSegment.Create("C:", false, true).Value,
PathSegment.Create("Users", true, false).Value,
PathSegment.Create("Documents", true, false).Value,
PathSegment.Create("file.txt", false, false).Value
];
// Act
IEnumerable<PathSegmentResponse> results = pathSegments.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(pathSegments.Count);
List<PathSegmentResponse> resultList = results.ToList();
for (int i = 0; i < pathSegments.Count; i++)
resultList[i].Path.Should().Be(pathSegments[i].Name);
}
}
@@ -0,0 +1,78 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="SplitPathRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SplitPathRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="SplitPathRequestMappingTests"/> class.
/// </summary>
public SplitPathRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToCommand_WhenMappingSplitPathRequest_ShouldMapCorrectly()
{
// Arrange
SplitPathRequest request = _fixture.Create<SplitPathRequest>();
// Act
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
}
[Theory]
[InlineData("/home/user/documents")]
[InlineData("C:\\Users\\Documents")]
[InlineData("/var/www/html")]
[InlineData("D:\\Projects\\MyProject\\file.txt")]
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
{
// Arrange
SplitPathRequest request = new(path);
// Act
SplitPathCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
}
[Fact]
public void ToCommand_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<SplitPathRequest> requests = _fixture.CreateMany<SplitPathRequest>().ToList();
// Act
List<SplitPathCommand> results = requests.Select(r => r.ToCommand()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
results[i].Path.Should().Be(requests[i].Path);
}
}
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using FluentAssertions;
using Lumina.Application.Common.Mapping.FileSystemManagement.Paths;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="ValidatePathRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidatePathRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="ValidatePathRequestMappingTests"/> class.
/// </summary>
public ValidatePathRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
[Fact]
public void ToQuery_WhenMappingValidatePathRequest_ShouldMapCorrectly()
{
// Arrange
ValidatePathRequest request = _fixture.Create<ValidatePathRequest>();
// Act
ValidatePathQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(request.Path);
}
[Theory]
[InlineData("/home/user/documents")]
[InlineData("C:\\Users\\Documents")]
[InlineData("/var/www/html")]
[InlineData("D:\\Projects\\MyProject\\file.txt")]
[InlineData("\\\\NetworkShare\\Folder")]
[InlineData("relative/path/to/file.txt")]
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
{
// Arrange
ValidatePathRequest request = new(path);
// Act
ValidatePathQuery result = request.ToQuery();
// Assert
result.Should().NotBeNull();
result.Path.Should().Be(path);
}
[Fact]
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
{
// Arrange
List<ValidatePathRequest> requests = _fixture.CreateMany<ValidatePathRequest>().ToList();
// Act
List<ValidatePathQuery> results = requests.Select(r => r.ToQuery()).ToList();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(requests.Count);
for (int i = 0; i < requests.Count; i++)
results[i].Path.Should().Be(requests[i].Path);
}
}