mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 19:11:10 +00:00
Replaces MVC with FastEndpoints in Lumina.Presentation.Api
This commit is contained in:
1 parent
b1a20716df
commit
c7b8bc2f1c
519 files changed
+15329
-8539
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Common;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTreeNodeResponseMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeNodeResponseMappingTests
|
||||
{
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemTreeNodeResponseMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileSystemTreeNodeResponseMappingTests()
|
||||
{
|
||||
_fileSystemTreeNodeResponseFixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToWindowsRootItem_WhenMappingFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
ErrorOr<WindowsRootItem> result = response.ToWindowsRootItem();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Id.Path.Should().Be(response.Path);
|
||||
result.Value.Name.Should().Be(response.Name);
|
||||
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToUnixRootItem_WhenMappingFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = _fileSystemTreeNodeResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
ErrorOr<UnixRootItem> result = response.ToUnixRootItem();
|
||||
|
||||
// Assert
|
||||
result.IsError.Should().BeFalse();
|
||||
result.Value.Should().NotBeNull();
|
||||
result.Value.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DirectoryMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryMappingTests
|
||||
{
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DirectoryMappingTests"/> class.
|
||||
/// </summary>
|
||||
public DirectoryMappingTests()
|
||||
{
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.ToFileSystemTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().HaveCount(childItems.Count);
|
||||
|
||||
for (int i = 0; i < childItems.Count; i++)
|
||||
{
|
||||
result.Children[i].Name.Should().Be(childItems[i].Name);
|
||||
result.Children[i].Path.Should().Be(childItems[i].Id.Path);
|
||||
result.Children[i].ItemType.Should().Be(childItems[i].Type);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Directory> directories = _directoryFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = directories.ToFileSystemTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(directories.Count);
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < directories.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(directories[i].Name);
|
||||
resultList[i].Path.Should().Be(directories[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(directories[i].Type);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
DirectoryResponse result = directory.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.DateCreated.Should().Be(directory.DateCreated.Value);
|
||||
result.DateModified.Should().Be(directory.DateModified.Value);
|
||||
result.Items.Should().NotBeNull();
|
||||
result.Items.Should().HaveCount(childItems.Count);
|
||||
|
||||
for (int i = 0; i < childItems.Count; i++)
|
||||
{
|
||||
result.Items[i].Name.Should().Be(childItems[i].Name);
|
||||
result.Items[i].Path.Should().Be(childItems[i].Id.Path);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Directory> directories = _directoryFixture.CreateMany(2);
|
||||
|
||||
// Act
|
||||
IEnumerable<DirectoryResponse> result = directories.ToResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(directories.Count);
|
||||
|
||||
List<DirectoryResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < directories.Count; i++)
|
||||
{
|
||||
resultList[i].Path.Should().Be(directories[i].Id.Path);
|
||||
resultList[i].Name.Should().Be(directories[i].Name);
|
||||
resultList[i].DateCreated.Should().Be(directories[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(directories[i].DateModified.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoriesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoriesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoriesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoriesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetDirectoriesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoriesRequest request = _fixture.Create<GetDirectoriesRequest>();
|
||||
|
||||
// Act
|
||||
GetDirectoriesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectoryTree;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetDirectoryTreeRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetDirectoryTreeRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetDirectoryTreeRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetDirectoryTreeRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetDirectoryTreeRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetDirectoryTreeRequest request = _fixture.Create<GetDirectoryTreeRequest>();
|
||||
|
||||
// Act
|
||||
GetDirectoryTreeQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeFiles.Should().Be(request.IncludeFiles);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Directories;
|
||||
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetTreeDirectories;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeDirectoriesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeDirectoriesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeDirectoriesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeDirectoriesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetTreeDirectoriesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeDirectoriesRequest request = _fixture.Create<GetTreeDirectoriesRequest>();
|
||||
|
||||
// Act
|
||||
GetTreeDirectoriesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
|
||||
using Lumina.Contracts.Entities.FileSystemManagement;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemMappingTests
|
||||
{
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture;
|
||||
private readonly DirectoryFixture _directoryFixture;
|
||||
private readonly FileFixture _fileFixture;
|
||||
private readonly WindowsRootItemFixture _windowsRootItemFixture;
|
||||
private readonly UnixRootItemFixture _unixRootItemFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemItemMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileSystemItemMappingTests()
|
||||
{
|
||||
_fileSystemPathIdFixture = new FileSystemPathIdFixture();
|
||||
_directoryFixture = new DirectoryFixture();
|
||||
_fileFixture = new FileFixture();
|
||||
_windowsRootItemFixture = new WindowsRootItemFixture();
|
||||
_unixRootItemFixture = new UnixRootItemFixture();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemItemModel_WhenMappingFileSystemItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
string name = "TestItem";
|
||||
FileSystemItemType type = FileSystemItemType.File;
|
||||
FileSystemItemFixture domainModel = new(id, name, type);
|
||||
|
||||
// Arrange
|
||||
|
||||
// Act
|
||||
FileSystemItemEntity result = domainModel.ToFileSystemItemModel();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Directory directory = _directoryFixture.CreateDirectory();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.ItemType.Should().Be(directory.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File file = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WindowsRootItem windowsRootItem = _windowsRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = windowsRootItem.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(windowsRootItem.Name);
|
||||
result.Path.Should().Be(windowsRootItem.Id.Path);
|
||||
result.ItemType.Should().Be(windowsRootItem.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UnixRootItem unixRootItem = _unixRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = unixRootItem.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(unixRootItem.Name);
|
||||
result.Path.Should().Be(unixRootItem.Id.Path);
|
||||
result.ItemType.Should().Be(unixRootItem.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("TestFile.txt", FileSystemItemType.File)]
|
||||
[InlineData("TestFolder", FileSystemItemType.Directory)]
|
||||
public void ToFileSystemItemModel_WhenMappingDifferentFileSystemItems_ShouldMapCorrectly(string name, FileSystemItemType type)
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
FileSystemItemFixture domainModel = new(id, name, type);
|
||||
|
||||
// Act
|
||||
FileSystemItemEntity result = domainModel.ToFileSystemItemModel();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
result.DateModified.Should().BeCloseTo(DateTime.Now, TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponses_WhenMappingMixedFileSystemItems_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<FileSystemItem> domainModels =
|
||||
[
|
||||
_directoryFixture.CreateDirectory(),
|
||||
_fileFixture.CreateFile(),
|
||||
_windowsRootItemFixture.Create(),
|
||||
_unixRootItemFixture.Create()
|
||||
];
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count);
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModels[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModels[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModels[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingInvalidFileSystemItem_ShouldThrowArgumentException()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemPathId id = _fileSystemPathIdFixture.CreateFileSystemPathId();
|
||||
string name = "TestItem";
|
||||
FileSystemItemType type = FileSystemItemType.File;
|
||||
FileSystemItemFixture invalidItem = new(id, name, type);
|
||||
|
||||
// Act & Assert
|
||||
invalidItem.Invoking(item => item.ToTreeNodeResponse())
|
||||
.Should().Throw<ArgumentException>()
|
||||
.WithMessage("Invalid FileSystemItem");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponses_WhenMappingMultipleFileSystemItems_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<FileSystemItem> domainModels = _directoryFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
List<FileSystemItem> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemItem"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemFixture : FileSystemItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileSystemItemFixture"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The unique identifier for the file system path.</param>
|
||||
/// <param name="name">The name of the file system item.</param>
|
||||
/// <param name="fileSystemItemType">The type of the file system item.</param>
|
||||
public FileSystemItemFixture(FileSystemPathId id, string name, FileSystemItemType fileSystemItemType)
|
||||
: base(id, name, fileSystemItemType)
|
||||
{
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UnixRootItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<UnixRootItem> createResult = UnixRootItem.Create();
|
||||
createResult.IsError.Should().BeFalse();
|
||||
UnixRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WindowsRootItemMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WindowsRootItemMappingTests
|
||||
{
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string path = "C:\\";
|
||||
string name = "C:";
|
||||
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
WindowsRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToTreeNodeResponse_WhenMappingWindowsRootItemWithCustomStatus_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string path = "D:\\";
|
||||
string name = "D:";
|
||||
FileSystemItemStatus customStatus = FileSystemItemStatus.Inaccessible;
|
||||
ErrorOr<WindowsRootItem> createResult = WindowsRootItem.Create(path, name, customStatus);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
WindowsRootItem domainModel = createResult.Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.Aggregates.FileSystemManagement.FileSystemManagementAggregate.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileMappingTests
|
||||
{
|
||||
private readonly FileFixture _fileFixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FileMappingTests"/> class.
|
||||
/// </summary>
|
||||
public FileMappingTests()
|
||||
{
|
||||
_fileFixture = new();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File domainModel = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = domainModel.ToFileSystemTreeNodeResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.ItemType.Should().Be(domainModel.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<File> domainModels = _fileFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileSystemTreeNodeResponse> resultList = result.ToList();
|
||||
List<File> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].ItemType.Should().Be(domainModelsList[i].Type);
|
||||
resultList[i].IsExpanded.Should().BeFalse();
|
||||
resultList[i].ChildrenLoaded.Should().BeFalse();
|
||||
resultList[i].Children.Should().BeEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingFile_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
File domainModel = _fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(domainModel.Id.Path);
|
||||
result.Name.Should().Be(domainModel.Name);
|
||||
result.DateCreated.Should().Be(domainModel.DateCreated.Value);
|
||||
result.DateModified.Should().Be(domainModel.DateModified.Value);
|
||||
result.Size.Should().Be(domainModel.Size);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
IEnumerable<File> domainModels = _fileFixture.CreateMany();
|
||||
|
||||
// Act
|
||||
IEnumerable<FileResponse> result = domainModels.ToResponses();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Should().HaveCount(domainModels.Count());
|
||||
|
||||
List<FileResponse> resultList = result.ToList();
|
||||
List<File> domainModelsList = domainModels.ToList();
|
||||
for (int i = 0; i < resultList.Count; i++)
|
||||
{
|
||||
resultList[i].Name.Should().Be(domainModelsList[i].Name);
|
||||
resultList[i].Path.Should().Be(domainModelsList[i].Id.Path);
|
||||
resultList[i].Size.Should().Be(domainModelsList[i].Size);
|
||||
resultList[i].DateCreated.Should().Be(domainModelsList[i].DateCreated.Value);
|
||||
resultList[i].DateModified.Should().Be(domainModelsList[i].DateModified.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetFilesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetFilesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetFilesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetFilesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetFilesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetFilesRequest request = _fixture.Create<GetFilesRequest>();
|
||||
|
||||
// Act
|
||||
GetFilesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Files;
|
||||
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Files;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetTreeFilesRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetTreeFilesRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetTreeFilesRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetTreeFilesRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetTreeFilesRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetTreeFilesRequest request = _fixture.Create<GetTreeFilesRequest>();
|
||||
|
||||
// Act
|
||||
GetTreeFilesQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.IncludeHiddenElements.Should().Be(request.IncludeHiddenElements);
|
||||
}
|
||||
}
|
||||
+82
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+79
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+80
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+77
@@ -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);
|
||||
}
|
||||
}
|
||||
+78
@@ -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);
|
||||
}
|
||||
}
|
||||
+80
@@ -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);
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
|
||||
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetThumbnailRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThumbnailRequestMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GetThumbnailRequestMappingTests"/> class.
|
||||
/// </summary>
|
||||
public GetThumbnailRequestMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingGetThumbnailRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = _fixture.Create<GetThumbnailRequest>();
|
||||
|
||||
// Act
|
||||
GetThumbnailQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(request.Path);
|
||||
result.Quality.Should().Be(request.Quality);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("C:\\test\\image.jpg", 50)]
|
||||
[InlineData("/home/user/image.png", 100)]
|
||||
[InlineData("D:\\photos\\vacation\\pic.gif", 75)]
|
||||
public void ToQuery_WhenMappingWithDifferentPathsAndQualities_ShouldMapCorrectly(string path, int quality)
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = new(path, quality);
|
||||
|
||||
// Act
|
||||
GetThumbnailQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(path);
|
||||
result.Quality.Should().Be(quality);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingMultipleRequests_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<GetThumbnailRequest> requests = _fixture.CreateMany<GetThumbnailRequest>().ToList();
|
||||
|
||||
// Act
|
||||
List<GetThumbnailQuery> 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].Quality.Should().Be(requests[i].Quality);
|
||||
}
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
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.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThumbnailMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailMappingTests
|
||||
{
|
||||
private readonly IFixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ThumbnailMappingTests"/> class.
|
||||
/// </summary>
|
||||
public ThumbnailMappingTests()
|
||||
{
|
||||
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingThumbnail_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Thumbnail domainModel = _fixture.Create<Thumbnail>();
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(domainModel.Type);
|
||||
result.Bytes.Should().BeEquivalentTo(domainModel.Bytes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageType.JPEG)]
|
||||
[InlineData(ImageType.PNG)]
|
||||
[InlineData(ImageType.GIF)]
|
||||
public void ToResponse_WhenMappingDifferentImageTypes_ShouldMapCorrectly(ImageType imageType)
|
||||
{
|
||||
// Arrange
|
||||
byte[] bytes = _fixture.CreateMany<byte>(100).ToArray();
|
||||
Thumbnail domainModel = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEquivalentTo(bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingThumbnailWithEmptyBytes_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _fixture.Create<ImageType>();
|
||||
byte[] emptyBytes = [];
|
||||
Thumbnail domainModel = new(imageType, emptyBytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingMultipleThumbnails_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Thumbnail> thumbnails = _fixture.CreateMany<Thumbnail>(3).ToList();
|
||||
|
||||
// Act
|
||||
List<ThumbnailResponse> results = thumbnails.Select(t => t.ToResponse()).ToList();
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(thumbnails.Count);
|
||||
for (int i = 0; i < thumbnails.Count; i++)
|
||||
{
|
||||
results[i].Type.Should().Be(thumbnails[i].Type);
|
||||
results[i].Bytes.Should().BeEquivalentTo(thumbnails[i].Bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user