Moves repository entities to Application layer for joint access

This commit is contained in:
BinaryAlley committed 2024-11-04 19:40:11 +02:00
1 parent baf9854355
commit 7321fb89e2
120 files changed
+2606 -784

No files matched your search

@@ -2,7 +2,7 @@
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -12,24 +12,24 @@ using System.Linq;
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreEntityMapping"/> class.
/// Contains unit tests for the <see cref="GenreDtoMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreModelMappingTests
public class GenreDtoMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidGenreEntity_ShouldMapCorrectly()
public void ToDomainEntity_WhenMappingValidGenreDto_ShouldMapCorrectly()
{
// Arrange
GenreEntity genreEntity = new("Rock");
GenreDto genreDto = new("Rock");
// Act
ErrorOr<Genre> result = genreEntity.ToDomainEntity();
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
result.Value.Name.Should().Be(genreDto.Name);
}
[Theory]
@@ -37,81 +37,81 @@ public class GenreModelMappingTests
[InlineData("Jazz")]
[InlineData("Classical")]
[InlineData("Pop")]
public void ToDomainModel_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
public void ToDomainEntity_WhenMappingDifferentValidGenreDtos_ShouldMapCorrectly(string name)
{
// Arrange
GenreEntity genreEntity = new(name);
GenreDto genreDto = new(name);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainEntity();
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(genreEntity.Name);
result.Value.Name.Should().Be(genreDto.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidGenreEntity_ShouldReturnError(string? invalidName)
public void ToDomainEntity_WhenMappingInvalidGenreDto_ShouldReturnError(string? invalidName)
{
// Arrange
GenreEntity genreEntity = new(invalidName);
GenreDto genreDto = new(invalidName);
// Act
ErrorOr<Genre> result = genreEntity.ToDomainEntity();
ErrorOr<Genre> result = genreDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
public void ToDomainModels_WhenMappingMultipleValidGenreDtos_ShouldMapAllCorrectly()
{
// Arrange
List<GenreEntity> genreEntities =
List<GenreDto> genreDtos =
[
new GenreEntity("Rock"),
new GenreEntity("Jazz"),
new GenreEntity("Classical"),
new GenreEntity("Pop")
new GenreDto("Rock"),
new GenreDto("Jazz"),
new GenreDto("Classical"),
new GenreDto("Pop")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainEntities();
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
results.Should().HaveCount(genreDtos.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < genreEntities.Count; i++)
for (int i = 0; i < genreDtos.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(genreEntities[i].Name);
resultList[i].Value.Name.Should().Be(genreDtos[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidGenreEntities_ShouldReturnMixedResults()
public void ToDomainModels_WhenMappingMixedValidAndInvalidGenreDtos_ShouldReturnMixedResults()
{
// Arrange
List<GenreEntity> genreEntities =
List<GenreDto> genreDtos =
[
new GenreEntity("Rock"),
new GenreEntity(""),
new GenreEntity("Jazz"),
new GenreEntity(" ")
new GenreDto("Rock"),
new GenreDto(""),
new GenreDto("Jazz"),
new GenreDto(" ")
];
// Act
IEnumerable<ErrorOr<Genre>> results = genreEntities.ToDomainEntities();
IEnumerable<ErrorOr<Genre>> results = genreDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(genreEntities.Count);
results.Should().HaveCount(genreDtos.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
@@ -0,0 +1,154 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="GenreEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreEntityMappingTests
{
[Fact]
public void ToResponse_WhenMappingValidGenreEntity_ShouldMapCorrectly()
{
// Arrange
GenreEntity entity = new("Fiction");
// Act
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("Fiction")]
[InlineData("Science Fiction")]
[InlineData("Mystery")]
[InlineData("Romance")]
public void ToResponse_WhenMappingDifferentValidGenreEntities_ShouldMapCorrectly(string name)
{
// Arrange
GenreEntity entity = new(name);
// Act
GenreDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToResponse_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
{
// Arrange
GenreEntity entity = new(invalidName);
// Act
GenreDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
}
[Fact]
public void ToDomainEntity_WhenMappingValidGenreEntity_ShouldMapCorrectly()
{
// Arrange
GenreEntity entity = new("Fiction");
// Act
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainEntity_WhenMappingInvalidGenreEntity_ShouldMapToDefault(string? invalidName)
{
// Arrange
GenreEntity entity = new(invalidName);
// Act
ErrorOr<Genre> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.GenreNameCannotBeEmpty);
}
[Fact]
public void ToDomainEntities_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
{
// Arrange
List<GenreEntity> entities =
[
new GenreEntity("Fiction"),
new GenreEntity("Mystery"),
new GenreEntity("Romance"),
new GenreEntity("Thriller")
];
// Act
IEnumerable<ErrorOr<Genre>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<Genre>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(entities[i].Name);
}
}
[Fact]
public void ToResponses_WhenMappingMultipleValidGenreEntities_ShouldMapAllCorrectly()
{
// Arrange
List<GenreEntity> entities =
[
new GenreEntity("Fiction"),
new GenreEntity("Mystery"),
new GenreEntity("Romance"),
new GenreEntity("Thriller")
];
// Act
IEnumerable<GenreDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<GenreDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
}
}
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
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;
@@ -2,7 +2,7 @@
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.Entities.Common;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
@@ -12,24 +12,24 @@ using System.Linq;
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagEntityMapping"/> class.
/// Contains unit tests for the <see cref="TagDtoMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagModelMappingTests
public class TagDtoMappingTests
{
[Fact]
public void ToDomainModel_WhenMappingValidTagEntity_ShouldMapCorrectly()
public void ToDomainEntity_WhenMappingValidTagDto_ShouldMapCorrectly()
{
// Arrange
TagEntity tagEntity = new("indie");
TagDto tagDto = new("indie");
// Act
ErrorOr<Tag> result = tagEntity.ToDomainEntity();
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
result.Value.Name.Should().Be(tagDto.Name);
}
[Theory]
@@ -38,81 +38,81 @@ public class TagModelMappingTests
[InlineData("instrumental")]
[InlineData("live")]
[InlineData("acoustic")]
public void ToDomainModel_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
public void ToDomainEntity_WhenMappingDifferentValidTagDtos_ShouldMapCorrectly(string name)
{
// Arrange
TagEntity tagEntity = new(name);
TagDto tagDto = new(name);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainEntity();
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(tagEntity.Name);
result.Value.Name.Should().Be(tagDto.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainModel_WhenMappingInvalidTagEntity_ShouldReturnError(string? invalidName)
public void ToDomainEntity_WhenMappingInvalidTagDto_ShouldReturnError(string? invalidName)
{
// Arrange
TagEntity tagEntity = new(invalidName);
TagDto tagDto = new(invalidName);
// Act
ErrorOr<Tag> result = tagEntity.ToDomainEntity();
ErrorOr<Tag> result = tagDto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
public void ToDomainModels_WhenMappingMultipleValidTagDtos_ShouldMapAllCorrectly()
{
// Arrange
List<TagEntity> tagEntities =
List<TagDto> tagDtos =
[
new TagEntity("indie"),
new TagEntity("electronic"),
new TagEntity("instrumental"),
new TagEntity("live")
new TagDto("indie"),
new TagDto("electronic"),
new TagDto("instrumental"),
new TagDto("live")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainEntities();
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
results.Should().HaveCount(tagDtos.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < tagEntities.Count; i++)
for (int i = 0; i < tagDtos.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(tagEntities[i].Name);
resultList[i].Value.Name.Should().Be(tagDtos[i].Name);
}
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidTagEntities_ShouldReturnMixedResults()
public void ToDomainModels_WhenMappingMixedValidAndInvalidTagDtos_ShouldReturnMixedResults()
{
// Arrange
List<TagEntity> tagEntities =
List<TagDto> tagDtos =
[
new TagEntity("indie"),
new TagEntity(""),
new TagEntity("electronic"),
new TagEntity(" ")
new TagDto("indie"),
new TagDto(""),
new TagDto("electronic"),
new TagDto(" ")
];
// Act
IEnumerable<ErrorOr<Tag>> results = tagEntities.ToDomainEntities();
IEnumerable<ErrorOr<Tag>> results = tagDtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(tagEntities.Count);
results.Should().HaveCount(tagDtos.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
@@ -0,0 +1,154 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Contracts.DTO.Common;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Domain.Common.Errors;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.Common.Metadata;
/// <summary>
/// Contains unit tests for the <see cref="TagEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagEntityMappingTests
{
[Fact]
public void ToResponse_WhenMappingValidTagEntity_ShouldMapCorrectly()
{
// Arrange
TagEntity entity = new("Fantasy");
// Act
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("Fantasy")]
[InlineData("Young Adult")]
[InlineData("Historical")]
[InlineData("Coming of Age")]
public void ToResponse_WhenMappingDifferentValidTagEntities_ShouldMapCorrectly(string name)
{
// Arrange
TagEntity entity = new(name);
// Act
TagDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToResponse_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
{
// Arrange
TagEntity entity = new(invalidName);
// Act
TagDto result = entity.ToResponse();
// Assert
result.Name.Should().Be(invalidName);
}
[Fact]
public void ToDomainEntity_WhenMappingValidTagEntity_ShouldMapCorrectly()
{
// Arrange
TagEntity entity = new("Fantasy");
// Act
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Name.Should().Be(entity.Name);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainEntity_WhenMappingInvalidTagEntity_ShouldMapToDefault(string? invalidName)
{
// Arrange
TagEntity entity = new(invalidName);
// Act
ErrorOr<Tag> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
result.FirstError.Should().Be(Errors.Metadata.TagNameCannotBeEmpty);
}
[Fact]
public void ToDomainEntities_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
{
// Arrange
List<TagEntity> entities =
[
new TagEntity("Fantasy"),
new TagEntity("Young Adult"),
new TagEntity("Historical"),
new TagEntity("Coming of Age")
];
// Act
IEnumerable<ErrorOr<Tag>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<Tag>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Name.Should().Be(entities[i].Name);
}
}
[Fact]
public void ToResponses_WhenMappingMultipleValidTagEntities_ShouldMapAllCorrectly()
{
// Arrange
List<TagEntity> entities =
[
new TagEntity("Fantasy"),
new TagEntity("Young Adult"),
new TagEntity("Historical"),
new TagEntity("Coming of Age")
];
// Act
IEnumerable<TagDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<TagDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Name.Should().Be(entities[i].Name);
}
}
}
@@ -1,8 +1,8 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.Common;
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;
@@ -6,17 +6,16 @@ using Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixture
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.Domain.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.Common.Enums.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Contracts.DTO.FileSystemManagement;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.FileSystem;
@@ -57,7 +56,7 @@ public class FileSystemItemMappingTests
// Arrange
// Act
FileSystemItemEntity result = domainModel.ToFileSystemItemEntity();
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
// Assert
result.Should().NotBeNull();
@@ -147,7 +146,7 @@ public class FileSystemItemMappingTests
FileSystemItemFixture domainModel = new(id, name, type);
// Act
FileSystemItemEntity result = domainModel.ToFileSystemItemEntity();
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
// Assert
result.Should().NotBeNull();
@@ -13,17 +13,17 @@ using System.Linq;
namespace Lumina.Application.UnitTests.Common.Mapping.FileSystemManagement.Paths;
/// <summary>
/// Contains unit tests for the <see cref="CheckPathExistsQueryMapping"/> class.
/// Contains unit tests for the <see cref="CheckPathExistsRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CheckPathExistsQueryMappingTests
public class CheckPathExistsRequestMappingTests
{
private readonly IFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="CheckPathExistsQueryMappingTests"/> class.
/// Initializes a new instance of the <see cref="CheckPathExistsRequestMappingTests"/> class.
/// </summary>
public CheckPathExistsQueryMappingTests()
public CheckPathExistsRequestMappingTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
}
@@ -0,0 +1,93 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using Lumina.Domain.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="AddMediaLibraryRequestMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddMediaLibraryRequestMappingTests
{
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library",
LibraryType.Book,
["C:/Books", "D:/Media/Books"]
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(request.LibraryType);
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library",
libraryType,
["C:/Media"]
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.UserId.Should().Be(request.UserId);
result.Title.Should().Be(request.Title);
result.LibraryType.Should().Be(libraryType);
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
}
[Fact]
public void ToCommand_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
string[] contentLocations =
[
"C:/Media/Books",
"D:/Books",
"E:/Digital Library/Books",
"F:/Reading Material"
];
AddLibraryRequest request = new(
Guid.NewGuid(),
"My Library",
LibraryType.Book,
contentLocations
);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEquivalentTo(contentLocations);
}
}
@@ -0,0 +1,132 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="LibraryEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryEntityMappingTests
{
[Fact]
public void ToResponse_WhenMappingValidLibraryEntity_ShouldMapCorrectly()
{
// Arrange
LibraryEntity entity = new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "My Library",
LibraryType = LibraryType.Book,
ContentLocations =
[
new() { Path = "C:/Books" },
new() { Path = "D:/Media/Books" }
],
Created = DateTime.UtcNow,
Updated = null
};
// Act
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.UserId.Should().Be(entity.UserId);
result.Title.Should().Be(entity.Title);
result.LibraryType.Should().Be(entity.LibraryType);
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
result.Created.Should().Be(entity.Created);
result.Updated.Should().Be(entity.Updated);
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToResponse_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
LibraryEntity entity = new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "My Library",
LibraryType = libraryType,
ContentLocations = [new() { Path = "C:/Media" }],
Created = DateTime.UtcNow,
Updated = null
};
// Act
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.LibraryType.Should().Be(libraryType);
}
[Fact]
public void ToResponse_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
LibraryEntity entity = new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "My Library",
LibraryType = LibraryType.Book,
ContentLocations =
[
new() { Path = "C:/Media/Books" },
new() { Path = "D:/Books" },
new() { Path = "E:/Digital Library/Books" },
new() { Path = "F:/Reading Material" }
],
Created = DateTime.UtcNow,
Updated = null
};
// Act
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
}
[Fact]
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
{
// Arrange
DateTime updated = DateTime.UtcNow.AddDays(-1);
LibraryEntity entity = new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "My Library",
LibraryType = LibraryType.Book,
ContentLocations = [new() { Path = "C:/Books" }],
Created = DateTime.UtcNow,
Updated = updated
};
// Act
LibraryResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Updated.Should().Be(updated);
}
}
@@ -0,0 +1,123 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Domain.Common.Enums.MediaLibrary;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
/// <summary>
/// Contains unit tests for the <see cref="LibraryMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Guid.NewGuid(),
"Test Library",
LibraryType.Book,
["C:/Books", "D:/Media/Books"]
);
Library library = libraryResult.Value;
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(library.Id.Value);
result.UserId.Should().Be(library.UserId.Value);
result.Title.Should().Be(library.Title);
result.LibraryType.Should().Be(library.LibraryType);
result.ContentLocations.Select(l => l.Path)
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
result.Created.Should().Be(library.Created);
result.Updated.Should().Be(library.Updated.HasValue ? library.Updated : null);
}
[Fact]
public void ToRepositoryEntity_WhenMappingLibraryWithEmptyContentLocations_ShouldMapCorrectly()
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Guid.NewGuid(),
"Empty Library",
LibraryType.Book,
[]
);
Library library = libraryResult.Value;
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Should().BeEmpty();
}
[Theory]
[InlineData(LibraryType.Book)]
[InlineData(LibraryType.Movie)]
[InlineData(LibraryType.TvShow)]
[InlineData(LibraryType.Music)]
public void ToRepositoryEntity_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
{
// Arrange
ErrorOr<Library> libraryResult = Library.Create(
Guid.NewGuid(),
"Test Library",
libraryType,
["C:/Media"]
);
Library library = libraryResult.Value;
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.LibraryType.Should().Be(libraryType);
}
[Fact]
public void ToRepositoryEntity_WhenMappingMultipleContentLocations_ShouldMapAllCorrectly()
{
// Arrange
List<string> contentLocations =
[
"C:/Media/Books",
"D:/Books",
"E:/Digital Library/Books",
"F:/Reading Material"
];
ErrorOr<Library> libraryResult = Library.Create(
Guid.NewGuid(),
"Test Library",
LibraryType.Book,
contentLocations
);
Library library = libraryResult.Value;
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
result.Should().NotBeNull();
result.ContentLocations.Select(l => l.Path)
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
}
}
@@ -2,15 +2,15 @@
using FluentAssertions;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Core.MediaLibrary.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.MediaLibrary.WrittenContentLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Common.Enums.BookLibrary;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="AddBookRequestMapping"/> class.
@@ -63,7 +63,7 @@ public class AddBookRequestMappingTests
{
// Arrange
AddBookRequest request = new(
Metadata: new WrittenContentMetadataEntity(
Metadata: new WrittenContentMetadataDto(
Title: "Test Book",
OriginalTitle: null,
Description: null,
@@ -120,7 +120,7 @@ public class AddBookRequestMappingTests
{
// Arrange
AddBookRequest request = new(
Metadata: new WrittenContentMetadataEntity(
Metadata: new WrittenContentMetadataDto(
Title: "Test Book",
OriginalTitle: null,
Description: null,
@@ -148,8 +148,8 @@ public class AddBookRequestMappingTests
Contributors:
[
new(
new MediaContributorNameEntity("John Doe", "John Smith Doe"),
new MediaContributorRoleEntity("Author", "Writing")
new MediaContributorNameDto("John Doe", "John Smith Doe"),
new MediaContributorRoleDto("Author", "Writing")
)
],
Ratings: [new(4.5m, 5m, BookRatingSource.Goodreads, 1000)]);
@@ -3,13 +3,13 @@ using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using System.Diagnostics.CodeAnalysis;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="BookMapping"/> class.
@@ -17,14 +17,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.Book
[ExcludeFromCodeCoverage]
public class BookMappingTests
{
private readonly DomainBookFixture _bookFixture;
private readonly BookFixture _bookFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookMappingTests"/> class.
/// </summary>
public BookMappingTests()
{
_bookFixture = new DomainBookFixture();
_bookFixture = new BookFixture();
}
[Fact]
@@ -1,36 +1,36 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Books;
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Contains unit tests for the <see cref="BookEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookModelMappingTests
public class BookEntityMappingTests
{
private readonly BookEntityFixture _bookEntityFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookModelMappingTests"/> class.
/// Initializes a new instance of the <see cref="BookEntityMappingTests"/> class.
/// </summary>
public BookModelMappingTests()
public BookEntityMappingTests()
{
_bookEntityFixture = new BookEntityFixture();
}
[Fact]
public void ToDomainModel_WhenMappingValidBookEntity_ShouldMapCorrectly()
public void ToDomainEntity_WhenMappingValidBookEntity_ShouldMapCorrectly()
{
// Arrange
BookEntity bookEntity = _bookEntityFixture.CreateBook();
@@ -0,0 +1,152 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="BookRatingDtoMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingDtoMappingTests
{
private readonly BookRatingDtoFixture _bookRatingDtoFixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookRatingDtoMappingTests"/> class.
/// </summary>
public BookRatingDtoMappingTests()
{
_bookRatingDtoFixture = new BookRatingDtoFixture();
}
[Fact]
public void ToDomainEntity_WhenMappingCompleteBookRatinDto_ShouldMapAllPropertiesCorrectly()
{
// Arrange
BookRatingDto dto = _bookRatingDtoFixture.CreateComplete();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(dto.Value!.Value);
result.Value.MaxValue.Should().Be(dto.MaxValue!.Value);
if (dto.Source.HasValue)
{
result.Value.Source.HasValue.Should().BeTrue();
result.Value.Source.Value.Should().Be(dto.Source.Value);
}
else
result.Value.Source.HasValue.Should().BeFalse();
if (dto.VoteCount.HasValue)
{
result.Value.VoteCount.HasValue.Should().BeTrue();
result.Value.VoteCount.Value.Should().Be(dto.VoteCount.Value);
}
else
result.Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainEntity_WhenMappingMinimalBookRatingDto_ShouldMapRequiredPropertiesCorrectly()
{
// Arrange
BookRatingDto dto = _bookRatingDtoFixture.CreateMinimal();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(dto.Value!.Value);
result.Value.MaxValue.Should().Be(dto.MaxValue!.Value);
result.Value.Source.HasValue.Should().BeFalse();
result.Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainEntity_WhenMappingInvalidBookRatingDto_ShouldReturnError()
{
// Arrange
BookRatingDto dto = _bookRatingDtoFixture.CreateInvalid();
// Act
ErrorOr<BookRating> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidBookRatingDtos_ShouldMapAllCorrectly()
{
// Arrange
List<BookRatingDto> dtos =
[
_bookRatingDtoFixture.CreateComplete(),
_bookRatingDtoFixture.CreateMinimal()
];
// Act
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
List<ErrorOr<BookRating>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
// Complete rating
resultList[0].Value.Value.Should().Be(dtos[0].Value!.Value);
resultList[0].Value.MaxValue.Should().Be(dtos[0].MaxValue!.Value);
resultList[0].Value.Source.Value.Should().Be(dtos[0].Source!.Value);
resultList[0].Value.VoteCount.Value.Should().Be(dtos[0].VoteCount!.Value);
// Minimal rating
resultList[1].Value.Value.Should().Be(dtos[1].Value!.Value);
resultList[1].Value.MaxValue.Should().Be(dtos[1].MaxValue!.Value);
resultList[1].Value.Source.HasValue.Should().BeFalse();
resultList[1].Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidBookRatingDtos_ShouldReturnMixedResults()
{
// Arrange
List<BookRatingDto> dtos =
[
_bookRatingDtoFixture.CreateComplete(),
_bookRatingDtoFixture.CreateInvalid(),
_bookRatingDtoFixture.CreateMinimal()
];
// Act
IEnumerable<ErrorOr<BookRating>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.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,153 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="BookRatingEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingEntityMappingTests
{
private readonly BookRatingEntityFixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="BookRatingEntityMappingTests"/> class.
/// </summary>
public BookRatingEntityMappingTests()
{
_fixture = new BookRatingEntityFixture();
}
[Fact]
public void ToResponse_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
{
// Arrange
BookRatingEntity entity = _fixture.CreateBookRating();
// Act
BookRatingDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(entity.Value!.Value);
result.MaxValue.Should().Be(entity.MaxValue!.Value);
result.Source.Should().Be(entity.Source);
result.VoteCount.Should().Be(entity.VoteCount);
}
[Fact]
public void ToResponse_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
{
// Arrange
BookRatingEntity entity = _fixture.CreateInvalidBookRating();
// Act
BookRatingDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(default);
result.MaxValue.Should().Be(default);
result.Source.Should().Be(entity.Source);
result.VoteCount.Should().Be(entity.VoteCount);
}
[Fact]
public void ToResponses_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
{
// Arrange
List<BookRatingEntity> entities =
[
_fixture.CreateBookRating(),
_fixture.CreateBookRating()
];
// Act
IEnumerable<BookRatingDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
results.Should().AllSatisfy(result =>
{
result.Should().NotBeNull();
result.Value.Should().BeInRange(1, 5);
result.MaxValue.Should().Be(5);
result.VoteCount.Should().BeInRange(1, 1000);
});
}
[Fact]
public void ToDomainEntity_WhenMappingValidBookRatingEntity_ShouldMapCorrectly()
{
// Arrange
BookRatingEntity entity = _fixture.CreateBookRating();
// Act
ErrorOr<BookRating> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value);
result.Value.MaxValue.Should().Be(entity.MaxValue);
result.Value.Source.Value.Should().Be(entity.Source);
result.Value.VoteCount.Value.Should().Be(entity.VoteCount);
}
[Fact]
public void ToDomainEntity_WhenMappingInvalidBookRatingEntity_ShouldMapToDefaults()
{
// Arrange
BookRatingEntity entity = _fixture.CreateInvalidBookRating();
// Act
ErrorOr<BookRating> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(default);
result.Value.MaxValue.Should().Be(default);
result.Value.Source.HasValue.Should().BeFalse();
result.Value.VoteCount.HasValue.Should().BeFalse();
}
[Fact]
public void ToDomainEntities_WhenMappingMultipleBookRatingEntities_ShouldMapAllCorrectly()
{
// Arrange
List<BookRatingEntity> entities =
[
_fixture.CreateBookRating(),
_fixture.CreateBookRating()
];
// Act
IEnumerable<ErrorOr<BookRating>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
results.Should().AllSatisfy(result =>
{
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().BeInRange(1, 5);
result.Value.MaxValue.Should().Be(5);
result.Value.Source.HasValue.Should().BeTrue();
result.Value.VoteCount.Value.Should().BeInRange(1, 1000);
});
}
}
@@ -1,16 +1,16 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="BookRatingMapping"/> class.
@@ -0,0 +1,153 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="IsbnDtoMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnDtoMappingTests
{
private readonly IsbnDtoFixture _isbnDtoFixture;
/// <summary>
/// Initializes a new instance of the <see cref="IsbnDtoMappingTests"/> class.
/// </summary>
public IsbnDtoMappingTests()
{
_isbnDtoFixture = new IsbnDtoFixture();
}
[Fact]
public void ToDomainEntity_WhenMappingValidIsbn10Dto_ShouldMapCorrectly()
{
// Arrange
IsbnDto dto = _isbnDtoFixture.CreateIsbn10();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(dto.Value);
result.Value.Format.Should().Be(dto.Format!.Value);
}
[Fact]
public void ToDomainEntity_WhenMappingValidIsbn13Dto_ShouldMapCorrectly()
{
// Arrange
IsbnDto dto = _isbnDtoFixture.CreateIsbn13();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(dto.Value);
result.Value.Format.Should().Be(dto.Format!.Value);
}
[Fact]
public void ToDomainEntity_WhenMappingDtoWithoutFormat_ShouldUseDefaultFormat()
{
// Arrange
IsbnDto dto = _isbnDtoFixture.CreateWithoutFormat();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(dto.Value);
result.Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
}
[Fact]
public void ToDomainEntity_WhenMappingInvalidIsbnDto_ShouldReturnError()
{
// Arrange
IsbnDto dto = _isbnDtoFixture.CreateInvalid();
// Act
ErrorOr<Isbn> result = dto.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainModels_WhenMappingMultipleValidIsbnDtos_ShouldMapAllCorrectly()
{
// Arrange
List<IsbnDto> dtos =
[
_isbnDtoFixture.CreateIsbn10(),
_isbnDtoFixture.CreateIsbn13(),
_isbnDtoFixture.CreateWithoutFormat()
];
// Act
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList.Should().AllSatisfy(result => result.IsError.Should().BeFalse());
resultList[0].Value.Value.Should().Be(dtos[0].Value);
resultList[0].Value.Format.Should().Be(dtos[0].Format!.Value);
resultList[1].Value.Value.Should().Be(dtos[1].Value);
resultList[1].Value.Format.Should().Be(dtos[1].Format!.Value);
resultList[2].Value.Value.Should().Be(dtos[2].Value);
resultList[2].Value.Format.Should().Be(IsbnFormat.Isbn13); // Default format
}
[Fact]
public void ToDomainModels_WhenMappingMixedValidAndInvalidIsbnDtos_ShouldReturnMixedResults()
{
// Arrange
List<IsbnDto> dtos =
[
_isbnDtoFixture.CreateIsbn10(),
_isbnDtoFixture.CreateInvalid(),
_isbnDtoFixture.CreateIsbn13()
];
// Act
IEnumerable<ErrorOr<Isbn>> results = dtos.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(dtos.Count);
List<ErrorOr<Isbn>> resultList = results.ToList();
resultList[0].IsError.Should().BeFalse();
resultList[0].Value.Value.Should().Be(dtos[0].Value);
resultList[1].IsError.Should().BeTrue();
resultList[2].IsError.Should().BeFalse();
resultList[2].Value.Value.Should().Be(dtos[2].Value);
}
}
@@ -0,0 +1,154 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="IsbnEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnEntityMappingTests
{
[Fact]
public void ToResponse_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
{
// Arrange
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
// Act
IsbnDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(entity.Value);
result.Format.Should().Be(entity.Format);
}
[Theory]
[InlineData("0-7475-3269-9", IsbnFormat.Isbn10)]
[InlineData("978-0-7475-3269-9", IsbnFormat.Isbn13)]
public void ToResponse_WhenMappingDifferentValidIsbnEntities_ShouldMapCorrectly(string value, IsbnFormat format)
{
// Arrange
IsbnEntity entity = new(value, format);
// Act
IsbnDto result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Value.Should().Be(value);
result.Format.Should().Be(format);
}
[Theory]
[InlineData("", null)]
[InlineData(" ", null)]
[InlineData(null, null)]
public void ToResponse_WhenMappingInvalidIsbnEntity_ShouldPreserveValues(string? value, IsbnFormat? format)
{
// Arrange
IsbnEntity entity = new(value, format);
// Act
IsbnDto result = entity.ToResponse();
// Assert
result.Value.Should().Be(value);
result.Format.Should().Be(format);
}
[Fact]
public void ToDomainEntity_WhenMappingValidIsbnEntity_ShouldMapCorrectly()
{
// Arrange
IsbnEntity entity = new("0-7475-3269-9", IsbnFormat.Isbn10);
// Act
ErrorOr<Isbn> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeFalse();
result.Value.Should().NotBeNull();
result.Value.Value.Should().Be(entity.Value);
result.Value.Format.Should().Be(entity.Format);
}
[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void ToDomainEntity_WhenMappingInvalidIsbnEntity_ShouldReturnError(string? invalidValue)
{
// Arrange
IsbnEntity entity = new(invalidValue, null);
// Act
ErrorOr<Isbn> result = entity.ToDomainEntity();
// Assert
result.IsError.Should().BeTrue();
}
[Fact]
public void ToDomainEntities_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
{
// Arrange
List<IsbnEntity> entities =
[
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
];
// Act
IEnumerable<ErrorOr<Isbn>> results = entities.ToDomainEntities();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<ErrorOr<Isbn>> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].IsError.Should().BeFalse();
resultList[i].Value.Value.Should().Be(entities[i].Value);
resultList[i].Value.Format.Should().Be(entities[i].Format);
}
}
[Fact]
public void ToResponses_WhenMappingMultipleValidIsbnEntities_ShouldMapAllCorrectly()
{
// Arrange
List<IsbnEntity> entities =
[
new IsbnEntity("0-7475-3269-9", IsbnFormat.Isbn10),
new IsbnEntity("978-0-7475-3269-9", IsbnFormat.Isbn13)
];
// Act
IEnumerable<IsbnDto> results = entities.ToResponses();
// Assert
results.Should().NotBeNull();
results.Should().HaveCount(entities.Count);
List<IsbnDto> resultList = results.ToList();
for (int i = 0; i < entities.Count; i++)
{
resultList[i].Value.Should().Be(entities[i].Value);
resultList[i].Format.Should().Be(entities[i].Format);
}
}
}
@@ -1,9 +1,9 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System.Collections.Generic;
@@ -11,7 +11,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.WrittenContentLibrary.BookLibrary.Common;
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
/// <summary>
/// Contains unit tests for the <see cref="IsbnMapping"/> class.
@@ -0,0 +1,141 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.Common.Mapping.UsersManagement.Users;
using Lumina.Contracts.Responses.UsersManagement.Users;
using Lumina.Domain.Common.Enums.MediaLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
/// <summary>
/// Contains unit tests for the <see cref="UserEntityMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserEntityMappingTests
{
[Fact]
public void ToResponse_WhenMappingValidUserEntity_ShouldMapCorrectly()
{
// Arrange
UserEntity entity = new()
{
Id = Guid.NewGuid(),
Username = "testuser",
Password = "hashedpassword",
Libraries = [],
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.Username.Should().Be(entity.Username);
result.Created.Should().Be(entity.Created);
result.Updated.Should().Be(entity.Updated);
}
[Theory]
[InlineData("user1")]
[InlineData("test.user")]
[InlineData("john_doe")]
[InlineData("jane.doe@example.com")]
public void ToResponse_WhenMappingDifferentUsernames_ShouldMapCorrectly(string username)
{
// Arrange
UserEntity entity = new()
{
Id = Guid.NewGuid(),
Username = username,
Password = "hashedpassword",
Libraries = [],
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(username);
}
[Fact]
public void ToResponse_WhenMappingWithUpdatedDateTime_ShouldMapCorrectly()
{
// Arrange
DateTime updated = DateTime.UtcNow.AddDays(-1);
UserEntity entity = new()
{
Id = Guid.NewGuid(),
Username = "testuser",
Password = "hashedpassword",
Libraries = [],
Created = DateTime.UtcNow,
Updated = updated
};
// Act
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Updated.Should().Be(updated);
}
[Fact]
public void ToResponse_WhenMappingWithLibraries_ShouldNotAffectMapping()
{
// Arrange
UserEntity entity = new()
{
Id = Guid.NewGuid(),
Username = "testuser",
Password = "hashedpassword",
Libraries =
[
new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "Library 1",
LibraryType = LibraryType.Book,
ContentLocations = [],
Created = DateTime.UtcNow,
Updated = null
},
new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "Library 2",
LibraryType = LibraryType.Movie,
ContentLocations = [],
Created = DateTime.UtcNow,
Updated = null
}
],
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserResponse result = entity.ToResponse();
// Assert
result.Should().NotBeNull();
result.Id.Should().Be(entity.Id);
result.Username.Should().Be(entity.Username);
result.Created.Should().Be(entity.Created);
result.Updated.Should().Be(entity.Updated);
}
}
@@ -0,0 +1,147 @@
#region ========================================================================= USING =====================================================================================
using FluentAssertions;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.Common.Mapping.UsersManagement.Users;
using Lumina.Domain.Common.Enums.MediaLibrary;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users;
/// <summary>
/// Contains unit tests for the <see cref="UserMapping"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserMappingTests
{
[Fact]
public void ToRepositoryEntity_WhenMappingValidUser_ShouldOnlyUpdateUsername()
{
// Arrange
User domainEntity = User.Create(
UserId.Create(Guid.NewGuid()),
"newusername"
).Value;
UserEntity repositoryEntity = new()
{
Id = Guid.NewGuid(),
Username = "oldusername",
Password = "hashedpassword",
TotpSecret = "totpsecret",
VerificationToken = "verificationtoken",
VerificationTokenCreated = DateTime.UtcNow,
Libraries = [],
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
// Assert
result.Should().NotBeNull();
result.Should().BeSameAs(repositoryEntity); // Should modify the same instance
result.Username.Should().Be(domainEntity.Username); // Only username should be updated
// Verify other properties remain unchanged
result.Id.Should().Be(repositoryEntity.Id);
result.Password.Should().Be(repositoryEntity.Password);
result.TotpSecret.Should().Be(repositoryEntity.TotpSecret);
result.VerificationToken.Should().Be(repositoryEntity.VerificationToken);
result.VerificationTokenCreated.Should().Be(repositoryEntity.VerificationTokenCreated);
result.Libraries.Should().BeSameAs(repositoryEntity.Libraries);
result.Created.Should().Be(repositoryEntity.Created);
result.Updated.Should().Be(repositoryEntity.Updated);
}
[Theory]
[InlineData("user1")]
[InlineData("test.user")]
[InlineData("john_doe")]
[InlineData("jane.doe@example.com")]
public void ToRepositoryEntity_WhenMappingDifferentUsernames_ShouldUpdateCorrectly(string newUsername)
{
// Arrange
User domainEntity = User.Create(
UserId.Create(Guid.NewGuid()),
newUsername
).Value;
UserEntity repositoryEntity = new()
{
Id = Guid.NewGuid(),
Username = "oldusername",
Password = "hashedpassword",
Libraries = [],
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
// Assert
result.Should().NotBeNull();
result.Username.Should().Be(newUsername);
}
[Fact]
public void ToRepositoryEntity_WhenRepositoryEntityHasLibraries_ShouldPreserveLibraries()
{
// Arrange
User domainEntity = User.Create(
UserId.Create(Guid.NewGuid()),
"newusername"
).Value;
List<LibraryEntity> libraries =
[
new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "Library 1",
LibraryType = LibraryType.Book,
ContentLocations = [],
Created = DateTime.UtcNow,
Updated = null
},
new()
{
Id = Guid.NewGuid(),
UserId = Guid.NewGuid(),
Title = "Library 2",
LibraryType = LibraryType.Movie,
ContentLocations = [],
Created = DateTime.UtcNow,
Updated = null
}
];
UserEntity repositoryEntity = new()
{
Id = Guid.NewGuid(),
Username = "oldusername",
Password = "hashedpassword",
Libraries = libraries,
Created = DateTime.UtcNow,
Updated = null
};
// Act
UserEntity result = domainEntity.ToRepositoryEntity(repositoryEntity);
// Assert
result.Should().NotBeNull();
result.Libraries.Should().BeSameAs(libraries);
result.Libraries.Should().HaveCount(2);
}
}
@@ -1,152 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.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="BookRatingEntityMapping"/> 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.ToDomainEntity();
// 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.ToDomainEntity();
// 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.ToDomainEntity();
// 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.ToDomainEntities();
// 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.ToDomainEntities();
// 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();
}
}
@@ -1,153 +0,0 @@
#region ========================================================================= USING =====================================================================================
using ErrorOr;
using FluentAssertions;
using Lumina.Application.Common.Mapping.Common.Metadata;
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Common;
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.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="IsbnEntityMapping"/> 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.ToDomainEntity();
// 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.ToDomainEntity();
// 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.ToDomainEntity();
// 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.ToDomainEntity();
// 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.ToDomainEntities();
// 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.ToDomainEntities();
// 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);
}
}