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

@@ -1,13 +0,0 @@
#region ========================================================================= USING =====================================================================================
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Converters.Fixtures;
/// <summary>
/// Fixture class for the <see cref="OptionalJsonConverterFactory"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionalJsonConverterFactoryFixture
{
}
@@ -1,111 +0,0 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Converters;
using Lumina.Application.UnitTests.Common.Converters.Fixtures;
using Lumina.Domain.Common.Primitives;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
using System.Text.Json.Serialization;
#endregion
namespace Lumina.Application.UnitTests.Common.Converters;
/// <summary>
/// Contains unit tests for the <see cref="GetFilesQueryHandler"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionalJsonConverterFactoryTests
{
private readonly OptionalJsonConverterFactory _factory;
/// <summary>
/// Initializes a new instance of the <see cref="OptionalJsonConverterFactoryTests"/> class.
/// </summary>
public OptionalJsonConverterFactoryTests()
{
_factory = new OptionalJsonConverterFactory();
}
[Fact]
public void CanConvert_WhenTypeIsOptional_ShouldReturnTrue()
{
// Arrange
Type typeToConvert = typeof(Optional<string>);
// Act
bool result = _factory.CanConvert(typeToConvert);
// Assert
result.Should().BeTrue();
}
[Fact]
public void CanConvert_WhenTypeIsNotOptional_ShouldReturnFalse()
{
// Arrange
Type typeToConvert = typeof(string);
// Act
bool result = _factory.CanConvert(typeToConvert);
// Assert
result.Should().BeFalse();
}
[Fact]
public void CanConvert_WhenTypeIsGenericButNotOptional_ShouldReturnFalse()
{
// Arrange
Type typeToConvert = typeof(List<string>);
// Act
bool result = _factory.CanConvert(typeToConvert);
// Assert
result.Should().BeFalse();
}
[Fact]
public void CreateConverter_WhenTypeIsOptionalString_ShouldReturnCorrectConverterType()
{
// Arrange
Type typeToConvert = typeof(Optional<string>);
JsonSerializerOptions options = new();
// Act
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
// Assert
converter.Should().BeOfType<OptionalJsonConverter<string>>();
}
[Fact]
public void CreateConverter_WhenTypeIsOptionalInt_ShouldReturnCorrectConverterType()
{
// Arrange
Type typeToConvert = typeof(Optional<int>);
JsonSerializerOptions options = new();
// Act
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
// Assert
converter.Should().BeOfType<OptionalJsonConverter<int>>();
}
[Fact]
public void CreateConverter_WhenTypeIsOptionalCustomClass_ShouldReturnCorrectConverterType()
{
// Arrange
Type typeToConvert = typeof(Optional<OptionalJsonConverterFactoryFixture>);
JsonSerializerOptions options = new();
// Act
JsonConverter converter = _factory.CreateConverter(typeToConvert, options);
// Assert
converter.Should().BeOfType<OptionalJsonConverter<OptionalJsonConverterFactoryFixture>>();
}
}
@@ -1,136 +0,0 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Converters;
using Lumina.Domain.Common.Primitives;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Application.UnitTests.Common.Converters;
/// <summary>
/// Contains unit tests for the <see cref="OptionalJsonConverter"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionalJsonConverterTests
{
private readonly JsonSerializerOptions _options;
/// <summary>
/// Initializes a new instance of the <see cref="OptionalJsonConverterTests"/> class.
/// </summary>
public OptionalJsonConverterTests()
{
_options = new JsonSerializerOptions();
_options.Converters.Add(new OptionalJsonConverter<string>());
_options.Converters.Add(new OptionalJsonConverter<int>());
}
[Fact]
public void Read_WhenJsonIsNull_ShouldReturnNone()
{
// Arrange
string json = "null";
// Act
Optional<string> result = JsonSerializer.Deserialize<Optional<string>>(json, _options);
// Assert
result.HasValue.Should().BeFalse();
}
[Fact]
public void Read_WhenJsonHasStringValue_ShouldReturnSomeWithCorrectValue()
{
// Arrange
string json = "\"test\"";
// Act
Optional<string> result = JsonSerializer.Deserialize<Optional<string>>(json, _options);
// Assert
result.HasValue.Should().BeTrue();
result.Value.Should().Be("test");
}
[Fact]
public void Read_WhenJsonHasIntValue_ShouldReturnSomeWithCorrectValue()
{
// Arrange
string json = "42";
// Act
Optional<int> result = JsonSerializer.Deserialize<Optional<int>>(json, _options);
// Assert
result.HasValue.Should().BeTrue();
result.Value.Should().Be(42);
}
[Fact]
public void Write_WhenOptionalHasNoValue_ShouldWriteNull()
{
// Arrange
Optional<string> optional = Optional<string>.None();
// Act
string json = JsonSerializer.Serialize(optional, _options);
// Assert
json.Should().Be("null");
}
[Fact]
public void Write_WhenOptionalHasStringValue_ShouldWriteCorrectJson()
{
// Arrange
Optional<string> optional = Optional<string>.Some("test");
// Act
string json = JsonSerializer.Serialize(optional, _options);
// Assert
json.Should().Be("\"test\"");
}
[Fact]
public void Write_WhenOptionalHasIntValue_ShouldWriteCorrectJson()
{
// Arrange
Optional<int> optional = Optional<int>.Some(42);
// Act
string json = JsonSerializer.Serialize(optional, _options);
// Assert
json.Should().Be("42");
}
[Fact]
public void ReadWrite_WhenSerializingAndDeserializingSomeValue_ShouldPreserveValue()
{
// Arrange
Optional<string> original = Optional<string>.Some("test");
// Act
string json = JsonSerializer.Serialize(original, _options);
Optional<string> deserialized = JsonSerializer.Deserialize<Optional<string>>(json, _options);
// Assert
deserialized.Should().Be(original);
}
[Fact]
public void ReadWrite_WhenSerializingAndDeserializingNone_ShouldPreserveNone()
{
// Arrange
Optional<string> original = Optional<string>.None();
// Act
string json = JsonSerializer.Serialize(original, _options);
Optional<string> deserialized = JsonSerializer.Deserialize<Optional<string>>(json, _options);
// Assert
deserialized.Should().Be(original);
}
}
@@ -0,0 +1,78 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingGenre_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create("Rock");
createResult.IsError.Should().BeFalse();
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
}
[Theory]
[InlineData("Rock")]
[InlineData("Jazz")]
[InlineData("Classical")]
[InlineData("Pop")]
public void ToRepositoryEntity_WhenMappingDifferentGenres_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Genre> createResult = Genre.Create(name);
createResult.IsError.Should().BeFalse();
Genre genre = createResult.Value;
// Act
GenreEntity result = genre.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(genre.Name);
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleGenres_ShouldMapAllCorrectly()
{
// Arrange
List<Genre> genres =
[
Genre.Create("Rock").Value,
Genre.Create("Jazz").Value,
Genre.Create("Classical").Value,
Genre.Create("Pop").Value
];
// Act
IEnumerable<GenreEntity> results = genres.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genres.Count);
List<GenreEntity> resultList = results.ToList();
for (int i = 0; i < genres.Count; i++)
resultList[i].Name.Should().Be(genres[i].Name);
}
}
@@ -0,0 +1,127 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreModelMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidGenreEntity_ShouldMapCorrectly()
{
// Arrange
GenreEntity genreEntity = new("Rock");
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
}
[Theory]
[InlineData("Rock")]
[InlineData("Jazz")]
[InlineData("Classical")]
[InlineData("Pop")]
public void ToDomainModel_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
{
// Arrange
GenreEntity genreEntity = new(name);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidGenreEntity_ShouldReturnError(string? invalidName)
{
// Arrange
GenreEntity genreEntity = new(invalidName);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
{
// Arrange
List<GenreEntity> genreEntities =
[
new GenreEntity("Rock"),
new GenreEntity("Jazz"),
new GenreEntity("Classical"),
new GenreEntity("Pop")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < genreEntities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(genreEntities[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidGenreEntities_ShouldReturnMixedResults()
{
// Arrange
List<GenreEntity> genreEntities =
[
new GenreEntity("Rock"),
new GenreEntity(""),
new GenreEntity("Jazz"),
new GenreEntity(" ")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("Rock");
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("Jazz");
resultList[3].IsError.Should().BeTrue();
}
}
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingTag_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create("indie");
createResult.IsError.Should().BeFalse();
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
}
[Theory]
[InlineData("indie")]
[InlineData("electronic")]
[InlineData("instrumental")]
[InlineData("live")]
[InlineData("acoustic")]
public void ToRepositoryEntity_WhenMappingDifferentTags_ShouldMapCorrectly(string name)
{
// Arrange
ErrorOr<Tag> createResult = Tag.Create(name);
createResult.IsError.Should().BeFalse();
Tag tag = createResult.Value;
// Act
TagEntity result = tag.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(tag.Name);
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleTags_ShouldMapAllCorrectly()
{
// Arrange
List<Tag> tags =
[
Tag.Create("indie").Value,
Tag.Create("electronic").Value,
Tag.Create("instrumental").Value,
Tag.Create("live").Value,
Tag.Create("acoustic").Value
];
// Act
IEnumerable<TagEntity> results = tags.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tags.Count);
List<TagEntity> resultList = results.ToList();
for (int i = 0; i < tags.Count; i++)
resultList[i].Name.Should().Be(tags[i].Name);
}
}
@@ -0,0 +1,128 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagModelMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidTagEntity_ShouldMapCorrectly()
{
// Arrange
TagEntity tagEntity = new("indie");
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
}
[Theory]
[InlineData("indie")]
[InlineData("electronic")]
[InlineData("instrumental")]
[InlineData("live")]
[InlineData("acoustic")]
public void ToDomainModel_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
{
// Arrange
TagEntity tagEntity = new(name);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidTagEntity_ShouldReturnError(string? invalidName)
{
// Arrange
TagEntity tagEntity = new(invalidName);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
{
// Arrange
List<TagEntity> tagEntities =
[
new TagEntity("indie"),
new TagEntity("electronic"),
new TagEntity("instrumental"),
new TagEntity("live")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < tagEntities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(tagEntities[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidTagEntities_ShouldReturnMixedResults()
{
// Arrange
List<TagEntity> tagEntities =
[
new TagEntity("indie"),
new TagEntity(""),
new TagEntity("electronic"),
new TagEntity(" ")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Name.Should().Be("indie");
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Name.Should().Be("electronic");
resultList[3].IsError.Should().BeTrue();
}
}
@@ -1,113 +0,0 @@
#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
{
private readonly TypeAdapterConfig _config;
private readonly DirectoryMappingConfig _directoryMappingConfig;
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
public DirectoryMappingConfigTests()
{
_config = new TypeAdapterConfig();
_directoryMappingConfig = new DirectoryMappingConfig();
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
_directoryMappingConfig.Register(_config);
_fileSystemTreeMappingConfig.Register(_config);
}
[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);
}
}
@@ -1,89 +0,0 @@
#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
{
private readonly TypeAdapterConfig _config;
private readonly FileMappingConfig _fileMappingConfig;
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
public FileMappingConfigTests()
{
_config = new TypeAdapterConfig();
_fileMappingConfig = new FileMappingConfig();
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
_fileMappingConfig.Register(_config);
_fileSystemTreeMappingConfig.Register(_config);
}
[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);
}
}
@@ -1,158 +0,0 @@
#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
{
private readonly TypeAdapterConfig _config;
private readonly FileSystemTreeMappingConfig _fileSystemTreeMappingConfig;
public FileSystemTreeMappingConfigTests()
{
_config = new TypeAdapterConfig();
_fileSystemTreeMappingConfig = new FileSystemTreeMappingConfig();
_fileSystemTreeMappingConfig.Register(_config);
}
[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();
}
}
@@ -1,109 +0,0 @@
#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
{
private readonly TypeAdapterConfig _config;
private readonly ThumbnailMappingConfig _thumbnailMappingConfig;
private readonly Faker _faker;
public ThumbnailMappingConfigTests()
{
_config = new TypeAdapterConfig();
_thumbnailMappingConfig = new ThumbnailMappingConfig();
_thumbnailMappingConfig.Register(_config);
_faker = new Faker();
}
[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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
}
}
@@ -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)
{
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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);
}
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
}
@@ -1,34 +1,24 @@
#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 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.FileManagement;
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="PathSegmentMappingConfig"/> class.
/// Contains unit tests for the <see cref="PathSegmentMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PathSegmentMappingConfigTests
public class PathSegmentMappingTests
{
private readonly TypeAdapterConfig _config;
private readonly PathSegmentMappingConfig _pathSegmentMappingConfig;
public PathSegmentMappingConfigTests()
{
_config = new TypeAdapterConfig();
_pathSegmentMappingConfig = new PathSegmentMappingConfig();
_pathSegmentMappingConfig.Register(_config);
}
[Fact]
public void Register_WhenMappingPathSegmentToPathSegmentResponse_ShouldMapCorrectly()
public void ToResponse_WhenMappingPathSegment_ShouldMapCorrectly()
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create("TestSegment", true, false);
@@ -36,7 +26,7 @@ public class PathSegmentMappingConfigTests
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.Adapt<PathSegmentResponse>(_config);
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
@@ -47,7 +37,7 @@ public class PathSegmentMappingConfigTests
[InlineData("Folder", true, false)]
[InlineData("File.txt", false, false)]
[InlineData("C:", false, true)]
public void Register_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
public void ToResponse_WhenMappingDifferentPathSegmentTypes_ShouldMapCorrectly(string name, bool isDirectory, bool isDrive)
{
// Arrange
ErrorOr<PathSegment> createResult = PathSegment.Create(name, isDirectory, isDrive);
@@ -55,7 +45,7 @@ public class PathSegmentMappingConfigTests
PathSegment pathSegment = createResult.Value;
// Act
PathSegmentResponse result = pathSegment.Adapt<PathSegmentResponse>(_config);
PathSegmentResponse result = pathSegment.ToResponse();
// Assert
result.Should().NotBeNull();
@@ -63,7 +53,7 @@ public class PathSegmentMappingConfigTests
}
[Fact]
public void Register_WhenMappingMultiplePathSegments_ShouldMapAllCorrectly()
public void ToResponses_WhenMappingMultiplePathSegments_ShouldMapAllCorrectly()
{
// Arrange
List<PathSegment> pathSegments =
@@ -75,14 +65,13 @@ public class PathSegmentMappingConfigTests
];
// Act
List<PathSegmentResponse> results = pathSegments.Adapt<List<PathSegmentResponse>>(_config);
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++)
{
results[i].Path.Should().Be(pathSegments[i].Name);
}
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);
}
}
@@ -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);
}
}
}
@@ -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);
}
}
}
@@ -0,0 +1,166 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Entities.MediaContributors;
using Lumina.Contracts.Entities.WrittenContentLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Requests.WrittenContentLibrary.BookLibrary.Books;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="AddBookRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddBookRequestMappingTests
{
private readonly AddBookRequestFixture _requestFixture;
/// <summary>
/// Initializes a new instance of the <see cref="AddBookRequestMappingTests"/> class.
/// </summary>
public AddBookRequestMappingTests()
{
_requestFixture = new AddBookRequestFixture();
}
[Fact]
public void ToCommand_WhenMappingCompleteRequest_ShouldMapAllPropertiesCorrectly()
{
// Arrange
AddBookRequest request = _requestFixture.CreateRequestBook();
// Act
AddBookCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Metadata.Should().BeEquivalentTo(request.Metadata);
result.Format.Should().Be(request.Format);
result.Edition.Should().Be(request.Edition);
result.VolumeNumber.Should().Be(request.VolumeNumber);
result.Series.Should().BeEquivalentTo(request.Series);
result.ASIN.Should().Be(request.ASIN);
result.GoodreadsId.Should().Be(request.GoodreadsId);
result.LCCN.Should().Be(request.LCCN);
result.OCLCNumber.Should().Be(request.OCLCNumber);
result.OpenLibraryId.Should().Be(request.OpenLibraryId);
result.LibraryThingId.Should().Be(request.LibraryThingId);
result.GoogleBooksId.Should().Be(request.GoogleBooksId);
result.BarnesAndNobleId.Should().Be(request.BarnesAndNobleId);
result.AppleBooksId.Should().Be(request.AppleBooksId);
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
result.Contributors.Should().BeEquivalentTo(request.Contributors);
result.Ratings.Should().BeEquivalentTo(request.Ratings);
}
[Fact]
public void ToCommand_WhenMappingMinimalRequest_ShouldMapCorrectly()
{
// Arrange
AddBookRequest request = new(
Metadata: new WrittenContentMetadataEntity(
Title: "Test Book",
OriginalTitle: null,
Description: null,
ReleaseInfo: null,
Genres: null,
Tags: null,
Language: null,
OriginalLanguage: null,
Publisher: null,
PageCount: null),
Format: null,
Edition: null,
VolumeNumber: null,
Series: null,
ASIN: null,
GoodreadsId: null,
LCCN: null,
OCLCNumber: null,
OpenLibraryId: null,
LibraryThingId: null,
GoogleBooksId: null,
BarnesAndNobleId: null,
AppleBooksId: null,
ISBNs: null,
Contributors: null,
Ratings: null);
// Act
AddBookCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.Metadata.Should().BeEquivalentTo(request.Metadata);
result.Format.Should().BeNull();
result.Edition.Should().BeNull();
result.VolumeNumber.Should().BeNull();
result.Series.Should().BeNull();
result.ASIN.Should().BeNull();
result.GoodreadsId.Should().BeNull();
result.LCCN.Should().BeNull();
result.OCLCNumber.Should().BeNull();
result.OpenLibraryId.Should().BeNull();
result.LibraryThingId.Should().BeNull();
result.GoogleBooksId.Should().BeNull();
result.BarnesAndNobleId.Should().BeNull();
result.AppleBooksId.Should().BeNull();
result.ISBNs.Should().BeNull();
result.Contributors.Should().BeNull();
result.Ratings.Should().BeNull();
}
[Fact]
public void ToCommand_WhenMappingRequestWithCollections_ShouldMapCollectionsCorrectly()
{
// Arrange
AddBookRequest request = new(
Metadata: new WrittenContentMetadataEntity(
Title: "Test Book",
OriginalTitle: null,
Description: null,
ReleaseInfo: null,
Genres: null,
Tags: null,
Language: null,
OriginalLanguage: null,
Publisher: null,
PageCount: null),
Format: null,
Edition: null,
VolumeNumber: null,
Series: null,
ASIN: null,
GoodreadsId: null,
LCCN: null,
OCLCNumber: null,
OpenLibraryId: null,
LibraryThingId: null,
GoogleBooksId: null,
BarnesAndNobleId: null,
AppleBooksId: null,
ISBNs: [new("978-0-123456-78-9", IsbnFormat.Isbn13)],
Contributors:
[
new(
new MediaContributorNameEntity("John Doe", "John Smith Doe"),
new MediaContributorRoleEntity("Author", "Writing")
)
],
Ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)]);
// Act
AddBookCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.ISBNs.Should().BeEquivalentTo(request.ISBNs);
result.Contributors.Should().BeEquivalentTo(request.Contributors);
result.Ratings.Should().BeEquivalentTo(request.Ratings);
}
}
@@ -0,0 +1,78 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="BookMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookMappingTests
{
private readonly DomainBookFixture _bookFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookMappingTests"/> class.
/// </summary>
public BookMappingTests()
{
_bookFixture = new DomainBookFixture();
}
[Fact]
public void ToRepositoryEntity_WhenMappingCompleteBook_ShouldMapAllPropertiesCorrectly()
{
// Arrange
Book book = _bookFixture.CreateDomainBook();
// Act
BookEntity result = book.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(book.Id.Value);
result.Title.Should().Be(book.Metadata.Title);
result.OriginalTitle.Should().Be(book.Metadata.OriginalTitle.HasValue ? book.Metadata.OriginalTitle.Value : null);
result.Description.Should().Be(book.Metadata.Description.HasValue ? book.Metadata.Description.Value : null);
result.OriginalReleaseDate.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseDate.Value : null);
result.OriginalReleaseYear.Should().Be(book.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue ? book.Metadata.ReleaseInfo.OriginalReleaseYear.Value : null);
result.ReReleaseDate.Should().Be(book.Metadata.ReleaseInfo.ReReleaseDate.HasValue ? book.Metadata.ReleaseInfo.ReReleaseDate.Value : null);
result.ReReleaseYear.Should().Be(book.Metadata.ReleaseInfo.ReReleaseYear.HasValue ? book.Metadata.ReleaseInfo.ReReleaseYear.Value : null);
result.ReleaseCountry.Should().Be(book.Metadata.ReleaseInfo.ReleaseCountry.HasValue ? book.Metadata.ReleaseInfo.ReleaseCountry.Value : null);
result.ReleaseVersion.Should().Be(book.Metadata.ReleaseInfo.ReleaseVersion.HasValue ? book.Metadata.ReleaseInfo.ReleaseVersion.Value : null);
result.LanguageCode.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageCode : null);
result.LanguageName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.LanguageName : null);
result.LanguageNativeName.Should().Be(book.Metadata.Language.HasValue ? book.Metadata.Language.Value.NativeName.Value : null);
result.OriginalLanguageCode.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageCode : null);
result.OriginalLanguageName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.LanguageName : null);
result.OriginalLanguageNativeName.Should().Be(book.Metadata.OriginalLanguage.HasValue ? book.Metadata.OriginalLanguage.Value.NativeName.Value : null);
result.Tags.Should().BeEquivalentTo(book.Metadata.Tags.ToRepositoryEntities());
result.Genres.Should().BeEquivalentTo(book.Metadata.Genres.ToRepositoryEntities());
result.Publisher.Should().Be(book.Metadata.Publisher.HasValue ? book.Metadata.Publisher.Value : null);
result.PageCount.Should().Be(book.Metadata.PageCount.HasValue ? book.Metadata.PageCount.Value : null);
result.Format.Should().Be(book.Format.ToString());
result.Edition.Should().Be(book.Edition.HasValue ? book.Edition.Value : null);
result.VolumeNumber.Should().Be(book.VolumeNumber.HasValue ? book.VolumeNumber.Value : null);
result.ASIN.Should().Be(book.ASIN.HasValue ? book.ASIN.Value : null);
result.GoodreadsId.Should().Be(book.GoodreadsId.HasValue ? book.GoodreadsId.Value : null);
result.LCCN.Should().Be(book.LCCN.HasValue ? book.LCCN.Value : null);
result.OCLCNumber.Should().Be(book.OCLCNumber.HasValue ? book.OCLCNumber.Value : null);
result.OpenLibraryId.Should().Be(book.OpenLibraryId.HasValue ? book.OpenLibraryId.Value : null);
result.LibraryThingId.Should().Be(book.LibraryThingId.HasValue ? book.LibraryThingId.Value : null);
result.GoogleBooksId.Should().Be(book.GoogleBooksId.HasValue ? book.GoogleBooksId.Value : null);
result.BarnesAndNobleId.Should().Be(book.BarnesAndNobleId.HasValue ? book.BarnesAndNobleId.Value : null);
result.AppleBooksId.Should().Be(book.AppleBooksId.HasValue ? book.AppleBooksId.Value : null);
result.ISBNs.Should().BeEquivalentTo(book.ISBNs.ToRepositoryEntities());
result.Ratings.Should().BeEquivalentTo(book.Ratings.ToRepositoryEntities());
result.Created.Should().Be(book.Created);
result.Updated.Should().Be(book.Updated.HasValue ? book.Updated.Value : null);
}
}
@@ -0,0 +1,350 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Contracts.Responses.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="BookModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookModelMappingTests
{
private readonly BookEntityFixture _bookEntityFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookModelMappingTests"/> class.
/// </summary>
public BookModelMappingTests()
{
_bookEntityFixture = new BookEntityFixture();
}
[Fact]
public void ToDomainModel_WhenMappingValidBookEntity_ShouldMapCorrectly()
{
// Arrange
BookEntity bookEntity = _bookEntityFixture.CreateBook();
// Act
ErrorOr<Book> result = bookEntity.ToDomainModel();
// Assert
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Id.Value.Should().Be(bookEntity.Id);
result.Value.Metadata.Title.Should().Be(bookEntity.Title);
if (bookEntity.OriginalTitle is not null)
{
result.Value.Metadata.OriginalTitle.HasValue.Should().BeTrue();
result.Value.Metadata.OriginalTitle.Value.Should().Be(bookEntity.OriginalTitle);
}
else
result.Value.Metadata.OriginalTitle.HasValue.Should().BeFalse();
if (bookEntity.Description is not null)
{
result.Value.Metadata.Description.HasValue.Should().BeTrue();
result.Value.Metadata.Description.Value.Should().Be(bookEntity.Description);
}
else
result.Value.Metadata.Description.HasValue.Should().BeFalse();
if (bookEntity.OriginalReleaseDate.HasValue)
{
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.Value.Should().Be(bookEntity.OriginalReleaseDate.Value);
}
else
result.Value.Metadata.ReleaseInfo.OriginalReleaseDate.HasValue.Should().BeFalse();
if (bookEntity.OriginalReleaseYear.HasValue)
{
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.Value.Should().Be(bookEntity.OriginalReleaseYear.Value);
}
else
result.Value.Metadata.ReleaseInfo.OriginalReleaseYear.HasValue.Should().BeFalse();
if (bookEntity.ReReleaseDate.HasValue)
{
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReReleaseDate.Value.Should().Be(bookEntity.ReReleaseDate.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReReleaseDate.HasValue.Should().BeFalse();
if (bookEntity.ReReleaseYear.HasValue)
{
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReReleaseYear.Value.Should().Be(bookEntity.ReReleaseYear.Value);
}
else
result.Value.Metadata.ReleaseInfo.ReReleaseYear.HasValue.Should().BeFalse();
if (bookEntity.ReleaseCountry is not null)
{
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReleaseCountry.Value.Should().Be(bookEntity.ReleaseCountry);
}
else
result.Value.Metadata.ReleaseInfo.ReleaseCountry.HasValue.Should().BeFalse();
if (bookEntity.ReleaseVersion is not null)
{
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeTrue();
result.Value.Metadata.ReleaseInfo.ReleaseVersion.Value.Should().Be(bookEntity.ReleaseVersion);
}
else
result.Value.Metadata.ReleaseInfo.ReleaseVersion.HasValue.Should().BeFalse();
if (bookEntity.LanguageCode is not null)
{
result.Value.Metadata.Language.HasValue.Should().BeTrue();
result.Value.Metadata.Language.Value.LanguageCode.Should().Be(bookEntity.LanguageCode);
result.Value.Metadata.Language.Value.LanguageName.Should().Be(bookEntity.LanguageName);
if (bookEntity.LanguageNativeName is not null)
{
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeTrue();
result.Value.Metadata.Language.Value.NativeName.Value.Should().Be(bookEntity.LanguageNativeName);
}
else
result.Value.Metadata.Language.Value.NativeName.HasValue.Should().BeFalse();
}
else
result.Value.Metadata.Language.HasValue.Should().BeFalse();
if (bookEntity.OriginalLanguageCode is not null)
{
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeTrue();
result.Value.Metadata.OriginalLanguage.Value.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
result.Value.Metadata.OriginalLanguage.Value.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
if (bookEntity.OriginalLanguageNativeName is not null)
{
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeTrue();
result.Value.Metadata.OriginalLanguage.Value.NativeName.Value.Should().Be(bookEntity.OriginalLanguageNativeName);
}
else
result.Value.Metadata.OriginalLanguage.Value.NativeName.HasValue.Should().BeFalse();
}
else
result.Value.Metadata.OriginalLanguage.HasValue.Should().BeFalse();
if (bookEntity.Publisher is not null)
{
result.Value.Metadata.Publisher.HasValue.Should().BeTrue();
result.Value.Metadata.Publisher.Value.Should().Be(bookEntity.Publisher);
}
else
result.Value.Metadata.Publisher.HasValue.Should().BeFalse();
if (bookEntity.PageCount.HasValue)
{
result.Value.Metadata.PageCount.HasValue.Should().BeTrue();
result.Value.Metadata.PageCount.Value.Should().Be(bookEntity.PageCount.Value);
}
else
result.Value.Metadata.PageCount.HasValue.Should().BeFalse();
result.Value.Format.Value.Should().Be(Enum.Parse<BookFormat>(bookEntity.Format));
if (bookEntity.Edition is not null)
{
result.Value.Edition.HasValue.Should().BeTrue();
result.Value.Edition.Value.Should().Be(bookEntity.Edition);
}
else
result.Value.Edition.HasValue.Should().BeFalse();
if (bookEntity.VolumeNumber.HasValue)
{
result.Value.VolumeNumber.HasValue.Should().BeTrue();
result.Value.VolumeNumber.Value.Should().Be(bookEntity.VolumeNumber.Value);
}
else
result.Value.VolumeNumber.HasValue.Should().BeFalse();
if (bookEntity.ASIN is not null)
{
result.Value.ASIN.HasValue.Should().BeTrue();
result.Value.ASIN.Value.Should().Be(bookEntity.ASIN);
}
else
result.Value.ASIN.HasValue.Should().BeFalse();
if (bookEntity.GoodreadsId is not null)
{
result.Value.GoodreadsId.HasValue.Should().BeTrue();
result.Value.GoodreadsId.Value.Should().Be(bookEntity.GoodreadsId);
}
else
result.Value.GoodreadsId.HasValue.Should().BeFalse();
if (bookEntity.LCCN is not null)
{
result.Value.LCCN.HasValue.Should().BeTrue();
result.Value.LCCN.Value.Should().Be(bookEntity.LCCN);
}
else
result.Value.LCCN.HasValue.Should().BeFalse();
if (bookEntity.OCLCNumber is not null)
{
result.Value.OCLCNumber.HasValue.Should().BeTrue();
result.Value.OCLCNumber.Value.Should().Be(bookEntity.OCLCNumber);
}
else
result.Value.OCLCNumber.HasValue.Should().BeFalse();
if (bookEntity.OpenLibraryId is not null)
{
result.Value.OpenLibraryId.HasValue.Should().BeTrue();
result.Value.OpenLibraryId.Value.Should().Be(bookEntity.OpenLibraryId);
}
else
result.Value.OpenLibraryId.HasValue.Should().BeFalse();
if (bookEntity.LibraryThingId is not null)
{
result.Value.LibraryThingId.HasValue.Should().BeTrue();
result.Value.LibraryThingId.Value.Should().Be(bookEntity.LibraryThingId);
}
else
result.Value.LibraryThingId.HasValue.Should().BeFalse();
if (bookEntity.GoogleBooksId is not null)
{
result.Value.GoogleBooksId.HasValue.Should().BeTrue();
result.Value.GoogleBooksId.Value.Should().Be(bookEntity.GoogleBooksId);
}
else
result.Value.GoogleBooksId.HasValue.Should().BeFalse();
if (bookEntity.BarnesAndNobleId is not null)
{
result.Value.BarnesAndNobleId.HasValue.Should().BeTrue();
result.Value.BarnesAndNobleId.Value.Should().Be(bookEntity.BarnesAndNobleId);
}
else
result.Value.BarnesAndNobleId.HasValue.Should().BeFalse();
if (bookEntity.AppleBooksId is not null)
{
result.Value.AppleBooksId.HasValue.Should().BeTrue();
result.Value.AppleBooksId.Value.Should().Be(bookEntity.AppleBooksId);
}
else
result.Value.AppleBooksId.HasValue.Should().BeFalse();
result.Value.Created.Should().Be(bookEntity.Created);
if (bookEntity.Updated.HasValue)
{
result.Value.Updated.HasValue.Should().BeTrue();
result.Value.Updated!.Value.Should().Be(bookEntity.Updated.Value);
}
else
result.Value.Updated.HasValue.Should().BeFalse();
}
[Fact]
public void ToResponse_WhenMappingBookEntity_ShouldMapAllPropertiesCorrectly()
{
// Arrange
BookEntity bookEntity = _bookEntityFixture.CreateBook();
// Act
BookResponse result = bookEntity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(bookEntity.Id);
result.Metadata.Title.Should().Be(bookEntity.Title);
result.Metadata.OriginalTitle.Should().Be(bookEntity.OriginalTitle);
result.Metadata.Description.Should().Be(bookEntity.Description);
result.Metadata.ReleaseInfo!.OriginalReleaseDate.Should().Be(bookEntity.OriginalReleaseDate);
result.Metadata.ReleaseInfo.OriginalReleaseYear.Should().Be(bookEntity.OriginalReleaseYear);
result.Metadata.ReleaseInfo.ReReleaseDate.Should().Be(bookEntity.ReReleaseDate);
result.Metadata.ReleaseInfo.ReReleaseYear.Should().Be(bookEntity.ReReleaseYear);
result.Metadata.ReleaseInfo.ReleaseCountry.Should().Be(bookEntity.ReleaseCountry);
result.Metadata.ReleaseInfo.ReleaseVersion.Should().Be(bookEntity.ReleaseVersion);
result.Metadata.Language.Should().NotBeNull();
result.Metadata.Language!.LanguageCode.Should().Be(bookEntity.LanguageCode);
result.Metadata.Language.LanguageName.Should().Be(bookEntity.LanguageName);
result.Metadata.Language.NativeName.Should().Be(bookEntity.LanguageNativeName);
result.Metadata.OriginalLanguage.Should().NotBeNull();
result.Metadata.OriginalLanguage!.LanguageCode.Should().Be(bookEntity.OriginalLanguageCode);
result.Metadata.OriginalLanguage.LanguageName.Should().Be(bookEntity.OriginalLanguageName);
result.Metadata.OriginalLanguage.NativeName.Should().Be(bookEntity.OriginalLanguageNativeName);
result.Metadata.Publisher.Should().Be(bookEntity.Publisher);
result.Metadata.PageCount.Should().Be(bookEntity.PageCount);
result.Format.Should().Be(Enum.Parse<BookFormat>(bookEntity.Format));
result.Edition.Should().Be(bookEntity.Edition);
result.VolumeNumber.Should().Be(bookEntity.VolumeNumber);
result.ASIN.Should().Be(bookEntity.ASIN);
result.GoodreadsId.Should().Be(bookEntity.GoodreadsId);
result.LCCN.Should().Be(bookEntity.LCCN);
result.OCLCNumber.Should().Be(bookEntity.OCLCNumber);
result.OpenLibraryId.Should().Be(bookEntity.OpenLibraryId);
result.LibraryThingId.Should().Be(bookEntity.LibraryThingId);
result.GoogleBooksId.Should().Be(bookEntity.GoogleBooksId);
result.BarnesAndNobleId.Should().Be(bookEntity.BarnesAndNobleId);
result.AppleBooksId.Should().Be(bookEntity.AppleBooksId);
result.ISBNs.Should().BeEquivalentTo(bookEntity.ISBNs);
result.Ratings.Should().BeEquivalentTo(bookEntity.Ratings);
result.Created.Should().Be(bookEntity.Created);
result.Updated.Should().Be(bookEntity.Updated);
}
[Fact]
public void ToDomainModels_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
{
// Arrange
List<BookEntity> bookEntities =
[
_bookEntityFixture.CreateBook(),
_bookEntityFixture.CreateBook()
];
// Act
IEnumerable<ErrorOr<Book>> results = bookEntities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookEntities.Count);
results.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
}
[Fact]
public void ToResponses_WhenMappingMultipleBookEntities_ShouldMapAllCorrectly()
{
// Arrange
List<BookEntity> bookEntities =
[
_bookEntityFixture.CreateBook(),
_bookEntityFixture.CreateBook()
];
// Act
IEnumerable<BookResponse> results = bookEntities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookEntities.Count);
}
}
@@ -0,0 +1,121 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="BookRatingMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingMappingTests
{
private readonly BookRatingFixture _bookRatingFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookRatingMappingTests"/> class.
/// </summary>
public BookRatingMappingTests()
{
_bookRatingFixture = new BookRatingFixture();
}
[Fact]
public void ToRepositoryEntity_WhenMappingCompleteBookRating_ShouldMapAllPropertiesCorrectly()
{
// Arrange
BookRating bookRating = _bookRatingFixture.CreateBookRating();
// Act
BookRatingEntity result = bookRating.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(bookRating.Value);
result.MaxValue.Should().Be(bookRating.MaxValue);
result.Source.Should().Be(bookRating.Source.Value);
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
}
[Fact]
public void ToRepositoryEntity_WhenMappingBookRatingWithoutSource_ShouldMapCorrectly()
{
// Arrange
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutSource();
// Act
BookRatingEntity result = bookRating.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(bookRating.Value);
result.MaxValue.Should().Be(bookRating.MaxValue);
result.Source.Should().BeNull();
result.VoteCount.Should().Be(bookRating.VoteCount.Value);
}
[Fact]
public void ToRepositoryEntity_WhenMappingBookRatingWithoutVoteCount_ShouldMapCorrectly()
{
// Arrange
BookRating bookRating = _bookRatingFixture.CreateBookRatingWithoutVoteCount();
// Act
BookRatingEntity result = bookRating.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(bookRating.Value);
result.MaxValue.Should().Be(bookRating.MaxValue);
result.Source.Should().Be(bookRating.Source.Value);
result.VoteCount.Should().BeNull();
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleBookRatings_ShouldMapAllCorrectly()
{
// Arrange
List<BookRating> bookRatings =
[
_bookRatingFixture.CreateBookRating(),
_bookRatingFixture.CreateBookRatingWithoutSource(),
_bookRatingFixture.CreateBookRatingWithoutVoteCount()
];
// Act
IEnumerable<BookRatingEntity> results = bookRatings.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(bookRatings.Count);
List<BookRatingEntity> resultList = results.ToList();
// Complete rating
resultList[0].Value.Should().Be(bookRatings[0].Value);
resultList[0].MaxValue.Should().Be(bookRatings[0].MaxValue);
resultList[0].Source.Should().Be(bookRatings[0].Source.Value);
resultList[0].VoteCount.Should().Be(bookRatings[0].VoteCount.Value);
// Rating without source
resultList[1].Value.Should().Be(bookRatings[1].Value);
resultList[1].MaxValue.Should().Be(bookRatings[1].MaxValue);
resultList[1].Source.Should().BeNull();
resultList[1].VoteCount.Should().Be(bookRatings[1].VoteCount.Value);
// Rating without vote count
resultList[2].Value.Should().Be(bookRatings[2].Value);
resultList[2].MaxValue.Should().Be(bookRatings[2].MaxValue);
resultList[2].Source.Should().Be(bookRatings[2].Source.Value);
resultList[2].VoteCount.Should().BeNull();
}
}
@@ -0,0 +1,153 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="BookRatingModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingModelMappingTests
{
private readonly BookRatingEntityFixture _bookRatingEntityFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookRatingModelMappingTests"/> class.
/// </summary>
public BookRatingModelMappingTests()
{
_bookRatingEntityFixture = new BookRatingEntityFixture();
}
[Fact]
public void ToDomainModel_WhenMappingCompleteBookRatingEntity_ShouldMapAllPropertiesCorrectly()
{
// Arrange
BookRatingEntity entity = _bookRatingEntityFixture.CreateComplete();
// Act
ErrorOr<BookRating> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value!.Value);
result.Value.MaxValue.Should().Be(entity.MaxValue!.Value);
if (entity.Source.HasValue)
{
result.Value.Source.HasValue.Should().BeTrue();
result.Value.Source.Value.Should().Be(entity.Source.Value);
}
else
result.Value.Source.HasValue.Should().BeFalse();
if (entity.VoteCount.HasValue)
{
result.Value.VoteCount.HasValue.Should().BeTrue();
result.Value.VoteCount.Value.Should().Be(entity.VoteCount.Value);
}
else
result.Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainModel_WhenMappingMinimalBookRatingEntity_ShouldMapRequiredPropertiesCorrectly()
{
// Arrange
BookRatingEntity entity = _bookRatingEntityFixture.CreateMinimal();
// Act
ErrorOr<BookRating> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value!.Value);
result.Value.MaxValue.Should().Be(entity.MaxValue!.Value);
result.Value.Source.HasValue.Should().BeFalse();
result.Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainModel_WhenMappingInvalidBookRatingEntity_ShouldReturnError()
{
// Arrange
BookRatingEntity entity = _bookRatingEntityFixture.CreateInvalid();
// Act
ErrorOr<BookRating> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidBookRatingEntities_ShouldMapAllCorrectly()
{
// Arrange
List<BookRatingEntity> entities =
[
_bookRatingEntityFixture.CreateComplete(),
_bookRatingEntityFixture.CreateMinimal()
];
// Act
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<BookRating>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
// Complete rating
resultList[0].Value.Value.Should().Be(entities[0].Value!.Value);
resultList[0].Value.MaxValue.Should().Be(entities[0].MaxValue!.Value);
resultList[0].Value.Source.Value.Should().Be(entities[0].Source!.Value);
resultList[0].Value.VoteCount.Value.Should().Be(entities[0].VoteCount!.Value);
// Minimal rating
resultList[1].Value.Value.Should().Be(entities[1].Value!.Value);
resultList[1].Value.MaxValue.Should().Be(entities[1].MaxValue!.Value);
resultList[1].Value.Source.HasValue.Should().BeFalse();
resultList[1].Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidBookRatingEntities_ShouldReturnMixedResults()
{
// Arrange
List<BookRatingEntity> entities =
[
_bookRatingEntityFixture.CreateComplete(),
_bookRatingEntityFixture.CreateInvalid(),
_bookRatingEntityFixture.CreateMinimal()
];
// Act
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<BookRating>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
}
}
@@ -0,0 +1,102 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="IsbnMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnMappingTests
{
private readonly IsbnFixture _isbnFixture;
/// <summary>
/// Initializes a new instance of the <see cref="IsbnMappingTests"/> class.
/// </summary>
public IsbnMappingTests()
{
_isbnFixture = new IsbnFixture();
}
[Fact]
public void ToRepositoryEntity_WhenMappingIsbn10_ShouldMapCorrectly()
{
// Arrange
Isbn isbn = _isbnFixture.CreateIsbn10();
// Act
IsbnEntity result = isbn.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(isbn.Value);
result.Format.Should().Be(IsbnFormat.Isbn10);
}
[Fact]
public void ToRepositoryEntity_WhenMappingIsbn13_ShouldMapCorrectly()
{
// Arrange
Isbn isbn = _isbnFixture.CreateIsbn13();
// Act
IsbnEntity result = isbn.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(isbn.Value);
result.Format.Should().Be(IsbnFormat.Isbn13);
}
[Fact]
public void ToRepositoryEntities_WhenMappingMultipleIsbns_ShouldMapAllCorrectly()
{
// Arrange
List<Isbn> isbns =
[
_isbnFixture.CreateIsbn10(),
_isbnFixture.CreateIsbn13(),
_isbnFixture.CreateIsbn10()
];
// Act
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(isbns.Count);
List<IsbnEntity> resultList = results.ToList();
for (int i = 0; i < isbns.Count; i++)
{
resultList[i].Value.Should().Be(isbns[i].Value);
resultList[i].Format.Should().Be(isbns[i].Format);
}
}
[Fact]
public void ToRepositoryEntities_WhenMappingEmptyCollection_ShouldReturnEmptyCollection()
{
// Arrange
List<Isbn> isbns = [];
// Act
IEnumerable<IsbnEntity> results = isbns.ToRepositoryEntities();
// Assert
results.Should().NotBeNull();
results.Should().BeEmpty();
}
}
@@ -0,0 +1,154 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Enums.BookLibrary;
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="IsbnModelMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnModelMappingTests
{
private readonly IsbnEntityFixture _isbnEntityFixture;
/// <summary>
/// Initializes a new instance of the <see cref="IsbnModelMappingTests"/> class.
/// </summary>
public IsbnModelMappingTests()
{
_isbnEntityFixture = new IsbnEntityFixture();
}
[Fact]
public void ToDomainModel_WhenMappingValidIsbn10Entity_ShouldMapCorrectly()
{
// Arrange
IsbnEntity entity = _isbnEntityFixture.CreateIsbn10();
// Act
ErrorOr<Isbn> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value);
result.Value.Format.Should().Be(entity.Format!.Value);
}
[Fact]
public void ToDomainModel_WhenMappingValidIsbn13Entity_ShouldMapCorrectly()
{
// Arrange
IsbnEntity entity = _isbnEntityFixture.CreateIsbn13();
// Act
ErrorOr<Isbn> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value);
result.Value.Format.Should().Be(entity.Format!.Value);
}
[Fact]
public void ToDomainModel_WhenMappingEntityWithoutFormat_ShouldUseDefaultFormat()
{
// Arrange
IsbnEntity entity = _isbnEntityFixture.CreateWithoutFormat();
// Act
ErrorOr<Isbn> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value);
result.Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
}
[Fact]
public void ToDomainModel_WhenMappingInvalidIsbnEntity_ShouldReturnError()
{
// Arrange
IsbnEntity entity = _isbnEntityFixture.CreateInvalid();
// Act
ErrorOr<Isbn> result = entity.ToDomainModel();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
{
// Arrange
List<IsbnEntity> entities =
[
_isbnEntityFixture.CreateIsbn10(),
_isbnEntityFixture.CreateIsbn13(),
_isbnEntityFixture.CreateWithoutFormat()
];
// Act
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
resultList[0].Value.Value.Should().Be(entities[0].Value);
resultList[0].Value.Format.Should().Be(entities[0].Format!.Value);
resultList[1].Value.Value.Should().Be(entities[1].Value);
resultList[1].Value.Format.Should().Be(entities[1].Format!.Value);
resultList[2].Value.Value.Should().Be(entities[2].Value);
resultList[2].Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidIsbnEntities_ShouldReturnMixedResults()
{
// Arrange
List<IsbnEntity> entities =
[
_isbnEntityFixture.CreateIsbn10(),
_isbnEntityFixture.CreateInvalid(),
_isbnEntityFixture.CreateIsbn13()
];
// Act
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainModels();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Value.Should().Be(entities[0].Value);
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Value.Should().Be(entities[2].Value);
}
}