mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Adds Application layer unit tests for file system browser dialog
This commit is contained in:
1 parent
1f5322fa1d
commit
0e3e688eb7
79 files changed
+5484
-91
No files matched your search
+119
@@ -0,0 +1,119 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Contracts.Models.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DirectoryMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryMappingConfigTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly DirectoryMappingConfig _directoryMappingConfig;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
public DirectoryMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_directoryMappingConfig = new DirectoryMappingConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_directoryMappingConfig.Register(_config);
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
|
||||
// create some child items
|
||||
List<FileSystemItem> childItems =
|
||||
[
|
||||
directoryFixture.CreateDirectory(),
|
||||
directoryFixture.CreateDirectory()
|
||||
];
|
||||
foreach (FileSystemItem item in childItems)
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// 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);
|
||||
|
||||
// Verify that each child item is correctly mapped
|
||||
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 Register_WhenMappingDirectoryToDirectoryResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
|
||||
// Act
|
||||
DirectoryResponse result = directory.Adapt<DirectoryResponse>(_config);
|
||||
|
||||
// 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().BeAssignableTo<List<FileSystemItemModel>>();
|
||||
result.Items.Should().HaveCount(directory.Items.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemItemModel_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
DateTime beforeMapping = DateTime.Now;
|
||||
|
||||
// Act
|
||||
FileSystemItemModel result = directory.Adapt<FileSystemItemModel>(_config);
|
||||
DateTime afterMapping = DateTime.Now;
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(directory.Id.Path);
|
||||
result.Name.Should().Be(directory.Name);
|
||||
result.DateCreated.Should().BeOnOrAfter(beforeMapping).And.BeOnOrBefore(afterMapping);
|
||||
result.DateModified.Should().BeOnOrAfter(beforeMapping).And.BeOnOrBefore(afterMapping);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileMappingConfigTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly FileMappingConfig _fileMappingConfig;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
public FileMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_fileMappingConfig = new FileMappingConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_fileMappingConfig.Register(_config);
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileResponse result = file.Adapt<FileResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.DateCreated.Should().Be(file.DateCreated.Value);
|
||||
result.DateModified.Should().Be(file.DateModified.Value);
|
||||
result.Size.Should().Be(file.Size);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileResponseWithoutDates_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = FileFixture.CreateFileWithoutDates();
|
||||
|
||||
// Act
|
||||
FileResponse result = file.Adapt<FileResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.DateCreated.Should().Be(default);
|
||||
result.DateModified.Should().Be(default);
|
||||
result.Size.Should().Be(file.Size);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Directories.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.FileManagement.Files.Fixtures;
|
||||
using Lumina.Contracts.Enums.FileSystem;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.Entities;
|
||||
using Mapster;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTreeMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeMappingConfigTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
public FileSystemTreeMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
|
||||
_fileSystemTreeMappingConfig.Register(_config);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Register_WhenMappingWindowsRootItemToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
WindowsRootItem windowsRoot = WindowsRootItem.Create("C:", "C:").Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = windowsRoot.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(windowsRoot.Id.Path);
|
||||
result.Name.Should().Be(windowsRoot.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileSystemTreeNodeResponseToWindowsRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = "D:",
|
||||
Name = "D:",
|
||||
ItemType = FileSystemItemType.Root,
|
||||
IsExpanded = false
|
||||
};
|
||||
|
||||
// Act
|
||||
WindowsRootItem result = response.Adapt<WindowsRootItem>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Path.Should().Be(response.Path);
|
||||
result.Name.Should().Be(response.Name);
|
||||
result.Type.Should().Be(FileSystemItemType.Root);
|
||||
result.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingUnixRootItemToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UnixRootItem unixRoot = UnixRootItem.Create().Value;
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = unixRoot.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(unixRoot.Id.Path);
|
||||
result.Name.Should().Be(unixRoot.Name);
|
||||
result.ItemType.Should().Be(FileSystemItemType.Root);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().NotBeNull();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileSystemTreeNodeResponseToUnixRootItem_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse response = new()
|
||||
{
|
||||
Path = "/",
|
||||
Name = "/",
|
||||
ItemType = FileSystemItemType.Root,
|
||||
IsExpanded = false
|
||||
};
|
||||
|
||||
// Act
|
||||
UnixRootItem result = response.Adapt<UnixRootItem>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Id.Path.Should().Be("/");
|
||||
result.Name.Should().Be("/");
|
||||
result.Type.Should().Be(FileSystemItemType.Root);
|
||||
result.Status.Should().Be(FileSystemItemStatus.Accessible);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingDirectoryToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryFixture directoryFixture = new();
|
||||
Directory directory = directoryFixture.CreateDirectory();
|
||||
directory.AddItem(directoryFixture.CreateDirectory());
|
||||
directory.AddItem(directoryFixture.CreateDirectory());
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = directory.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// 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(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingFileToFileSystemTreeNodeResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
FileFixture fileFixture = new();
|
||||
File file = fileFixture.CreateFile();
|
||||
|
||||
// Act
|
||||
FileSystemTreeNodeResponse result = file.Adapt<FileSystemTreeNodeResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Name.Should().Be(file.Name);
|
||||
result.Path.Should().Be(file.Id.Path);
|
||||
result.ItemType.Should().Be(file.Type);
|
||||
result.IsExpanded.Should().BeFalse();
|
||||
result.ChildrenLoaded.Should().BeFalse();
|
||||
result.Children.Should().BeEmpty();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathSegmentMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSegmentMappingConfigTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly PathSegmentMappingConfig _pathSegmentMappingConfig;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
public PathSegmentMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_pathSegmentMappingConfig = new PathSegmentMappingConfig();
|
||||
_pathSegmentMappingConfig.Register(_config);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Register_WhenMappingPathSegmentToPathSegmentResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
|
||||
createResult.IsError.Should().BeFalse();
|
||||
PathSegment pathSegment = createResult.Value;
|
||||
|
||||
// Act
|
||||
PathSegmentResponse result = pathSegment.Adapt<PathSegmentResponse>(_config);
|
||||
|
||||
// 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 Register_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.Adapt<PathSegmentResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Path.Should().Be(pathSegment.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_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
|
||||
List<PathSegmentResponse> results = pathSegments.Adapt<List<PathSegmentResponse>>(_config);
|
||||
|
||||
// Assert
|
||||
results.Should().NotBeNull();
|
||||
results.Should().HaveCount(pathSegments.Count);
|
||||
for (int i = 0; i < pathSegments.Count; i++)
|
||||
{
|
||||
results[i].Path.Should().Be(pathSegments[i].Name);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.Mapping.FileManagement;
|
||||
using Lumina.Contracts.Enums.PhotoLibrary;
|
||||
using Lumina.Contracts.Responses.FileManagement;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using Mapster;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.FileManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThumbnailMappingConfig"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailMappingConfigTests
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly TypeAdapterConfig _config;
|
||||
private readonly ThumbnailMappingConfig _thumbnailMappingConfig;
|
||||
private readonly Faker _faker;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
public ThumbnailMappingConfigTests()
|
||||
{
|
||||
_config = new TypeAdapterConfig();
|
||||
_thumbnailMappingConfig = new ThumbnailMappingConfig();
|
||||
_thumbnailMappingConfig.Register(_config);
|
||||
_faker = new Faker();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
[Fact]
|
||||
public void Register_WhenMappingThumbnailToThumbnailResponse_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _faker.PickRandom<ImageType>();
|
||||
byte[] bytes = _faker.Random.Bytes(100);
|
||||
Thumbnail thumbnail = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(thumbnail.Type);
|
||||
result.Bytes.Should().BeEquivalentTo(thumbnail.Bytes);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(ImageType.JPEG)]
|
||||
[InlineData(ImageType.PNG)]
|
||||
[InlineData(ImageType.GIF)]
|
||||
public void Register_WhenMappingDifferentImageTypes_ShouldMapCorrectly(ImageType imageType)
|
||||
{
|
||||
// Arrange
|
||||
byte[] bytes = _faker.Random.Bytes(100);
|
||||
Thumbnail thumbnail = new(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEquivalentTo(bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingThumbnailWithEmptyBytes_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ImageType imageType = _faker.PickRandom<ImageType>();
|
||||
byte[] emptyBytes = [];
|
||||
Thumbnail thumbnail = new(imageType, emptyBytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = thumbnail.Adapt<ThumbnailResponse>(_config);
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.Type.Should().Be(imageType);
|
||||
result.Bytes.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Register_WhenMappingMultipleThumbnails_ShouldMapAllCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Thumbnail> thumbnails =
|
||||
[
|
||||
new Thumbnail(ImageType.JPEG, _faker.Random.Bytes(100)),
|
||||
new Thumbnail(ImageType.PNG, _faker.Random.Bytes(200)),
|
||||
new Thumbnail(ImageType.GIF, _faker.Random.Bytes(150))
|
||||
];
|
||||
|
||||
// Act
|
||||
List<ThumbnailResponse> results = thumbnails.Adapt<List<ThumbnailResponse>>(_config);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user