mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 03:11:10 +00:00
Moves repository entities to Application layer for joint access
This commit is contained in:
1 parent
baf9854355
commit
7321fb89e2
120 files changed
+2606
-784
No files matched your search
+32
-32
@@ -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();
|
||||
+154
@@ -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
-1
@@ -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;
|
||||
|
||||
+32
-32
@@ -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();
|
||||
+154
@@ -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
-1
@@ -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;
|
||||
|
||||
+4
-5
@@ -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();
|
||||
|
||||
+4
-4
@@ -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());
|
||||
}
|
||||
+93
@@ -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);
|
||||
}
|
||||
}
|
||||
+132
@@ -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);
|
||||
}
|
||||
}
|
||||
+123
@@ -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));
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -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)]);
|
||||
+5
-5
@@ -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]
|
||||
+7
-7
@@ -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();
|
||||
+152
@@ -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();
|
||||
}
|
||||
}
|
||||
+153
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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.
|
||||
+153
@@ -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);
|
||||
}
|
||||
}
|
||||
+154
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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.
|
||||
+141
@@ -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);
|
||||
}
|
||||
}
|
||||
+147
@@ -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);
|
||||
}
|
||||
}
|
||||
-152
@@ -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();
|
||||
}
|
||||
}
|
||||
-153
@@ -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);
|
||||
}
|
||||
}
|
||||
+8
-8
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Entities.FileSystemManagement;
|
||||
using Lumina.Contracts.DTO.FileSystemManagement;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="FileSystemItemEntity"/> class.
|
||||
/// Fixture class for the <see cref="FileSystemItemDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemItemModelFixture
|
||||
@@ -17,12 +17,12 @@ public class FileSystemItemModelFixture
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="FileSystemItemEntity"/>.
|
||||
/// Creates a random valid <see cref="FileSystemItemDto"/>.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="FileSystemItemEntity"/>.</returns>
|
||||
public FileSystemItemEntity Create()
|
||||
/// <returns>The created <see cref="FileSystemItemDto"/>.</returns>
|
||||
public FileSystemItemDto Create()
|
||||
{
|
||||
return new FileSystemItemEntity(
|
||||
return new FileSystemItemDto(
|
||||
_faker.System.FilePath(),
|
||||
_faker.System.FileName(),
|
||||
_faker.Date.Past(),
|
||||
@@ -31,11 +31,11 @@ public class FileSystemItemModelFixture
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="FileSystemItemEntity"/>.
|
||||
/// Creates a list of <see cref="FileSystemItemDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<FileSystemItemEntity> CreateMany(int count = 3)
|
||||
public List<FileSystemItemDto> CreateMany(int count = 3)
|
||||
{
|
||||
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
|
||||
}
|
||||
|
||||
-1
@@ -11,7 +11,6 @@ using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.File
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using ErrorOr;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.Management.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Library"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DomainLibraryFixture
|
||||
{
|
||||
private readonly Faker _faker;
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DomainLibraryFixture"/> class.
|
||||
/// </summary>
|
||||
public DomainLibraryFixture()
|
||||
{
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a media library domain entity.
|
||||
/// </summary>
|
||||
/// <returns>The created media library entity.</returns>
|
||||
public Library CreateLibrary()
|
||||
{
|
||||
List<string> validPaths =
|
||||
[
|
||||
"C:/Media",
|
||||
"D:/Books",
|
||||
"E:/Digital Library",
|
||||
"F:/Content"
|
||||
];
|
||||
|
||||
ErrorOr<Library> library = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
_faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
_faker.PickRandom<LibraryType>(),
|
||||
validPaths.Take(_random.Next(1, validPaths.Count))
|
||||
);
|
||||
|
||||
return library.Value;
|
||||
}
|
||||
|
||||
public Library CreateLibraryWithSpecificValues(
|
||||
Guid? id = null,
|
||||
Guid? userId = null,
|
||||
string? title = null,
|
||||
LibraryType? libraryType = null,
|
||||
IEnumerable<string>? contentLocations = null)
|
||||
{
|
||||
ErrorOr<Library> library = id is null ?
|
||||
Library.Create(
|
||||
userId ?? Guid.NewGuid(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? LibraryType.Book,
|
||||
contentLocations ?? ["C:/Media"]
|
||||
) :
|
||||
Library.Create(
|
||||
LibraryId.Create(id.Value),
|
||||
userId ?? Guid.NewGuid(),
|
||||
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
|
||||
libraryType ?? LibraryType.Book,
|
||||
contentLocations ?? ["C:/Media"]
|
||||
);
|
||||
|
||||
return library.Value;
|
||||
}
|
||||
}
|
||||
+13
-12
@@ -3,15 +3,16 @@ using AutoFixture;
|
||||
using AutoFixture.AutoNSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -20,7 +21,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddBookCommandHandler"/> class.
|
||||
@@ -112,7 +113,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnEntity("invalid", IsbnFormat.Isbn13)] };
|
||||
bookCommand = bookCommand with { ISBNs = [new IsbnDto("invalid", IsbnFormat.Isbn13)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
@@ -129,7 +130,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
// Arrange
|
||||
AddBookCommand bookCommand = _commandBookFixture.CreateCommandBook();
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingEntity(-1, 5, null, null)] };
|
||||
bookCommand = bookCommand with { Ratings = [new BookRatingDto(-1, 5, null, null)] };
|
||||
|
||||
// Act
|
||||
ErrorOr<BookResponse> result = await _sut.Handle(bookCommand, CancellationToken.None);
|
||||
@@ -150,7 +151,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Genres = [new GenreEntity("")]
|
||||
Genres = [new GenreDto("")]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -173,7 +174,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Tags = [new TagEntity("")]
|
||||
Tags = [new TagDto("")]
|
||||
}
|
||||
};
|
||||
|
||||
@@ -196,7 +197,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
ReleaseInfo = new ReleaseInfoEntity(
|
||||
ReleaseInfo = new ReleaseInfoDto(
|
||||
OriginalReleaseDate: new DateOnly(2025, 1, 1),
|
||||
ReReleaseDate: new DateOnly(2024, 1, 1),
|
||||
OriginalReleaseYear: null,
|
||||
@@ -226,7 +227,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
Language = new LanguageInfoEntity("", "English", null)
|
||||
Language = new LanguageInfoDto("", "English", null)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -249,7 +250,7 @@ public class AddBookCommandHandlerTests
|
||||
{
|
||||
Metadata = bookCommand.Metadata! with
|
||||
{
|
||||
OriginalLanguage = new LanguageInfoEntity("", "English", null)
|
||||
OriginalLanguage = new LanguageInfoDto("", "English", null)
|
||||
}
|
||||
};
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
using Bogus;
|
||||
using FluentValidation.TestHelper;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using System;
|
||||
@@ -10,7 +10,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddBookCommandValidator"/> class.
|
||||
+47
-47
@@ -3,10 +3,10 @@ using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,7 +14,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddBookCommand"/> class.
|
||||
@@ -46,8 +46,8 @@ public class AddBookCommandFixture
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoEntity releaseInfo = new Faker<ReleaseInfoEntity>()
|
||||
.CustomInstantiator(f => new ReleaseInfoEntity(
|
||||
ReleaseInfoDto releaseInfo = new Faker<ReleaseInfoDto>()
|
||||
.CustomInstantiator(f => new ReleaseInfoDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -63,42 +63,42 @@ public class AddBookCommandFixture
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreEntity> genre = new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(
|
||||
Faker<GenreDto> genre = new Faker<GenreDto>()
|
||||
.CustomInstantiator(f => new GenreDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagEntity> tag = new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(
|
||||
Faker<TagDto> tag = new Faker<TagDto>()
|
||||
.CustomInstantiator(f => new TagDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleEntity> mediaContributorRole = new Faker<MediaContributorRoleEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleEntity(
|
||||
Faker<MediaContributorRoleDto> mediaContributorRole = new Faker<MediaContributorRoleDto>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
Faker<MediaContributorNameEntity> mediaContributorName = new Faker<MediaContributorNameEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorNameEntity(
|
||||
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
Faker<MediaContributorEntity> mediaContributor = new Faker<MediaContributorEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorEntity(
|
||||
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingEntity> rating = new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
|
||||
.CustomInstantiator(f => new BookRatingDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -109,8 +109,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoEntity> language = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -119,8 +119,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoEntity> originalLanguage = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
Faker<LanguageInfoDto> originalLanguage = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -129,8 +129,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataEntity> metadata = new Faker<WrittenContentMetadataEntity>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataEntity(
|
||||
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataDto(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
@@ -153,8 +153,8 @@ public class AddBookCommandFixture
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnEntity> isbn = new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(
|
||||
Faker<IsbnDto> isbn = new Faker<IsbnDto>()
|
||||
.CustomInstantiator(f => new IsbnDto(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
@@ -171,7 +171,7 @@ public class AddBookCommandFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
@@ -182,7 +182,7 @@ public class AddBookCommandFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
@@ -276,7 +276,7 @@ public class AddBookCommandFixture
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
_fixture.Register(() => new ReleaseInfoEntity(
|
||||
_fixture.Register(() => new ReleaseInfoDto(
|
||||
_faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)),
|
||||
releaseYear,
|
||||
_faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)),
|
||||
@@ -284,53 +284,53 @@ public class AddBookCommandFixture
|
||||
_fixture.Create<string>()[2..],
|
||||
_fixture.Create<string?>()));
|
||||
|
||||
_fixture.Register(() => new GenreEntity(
|
||||
_fixture.Register(() => new GenreDto(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new TagEntity(
|
||||
_fixture.Register(() => new TagDto(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new LanguageInfoEntity(
|
||||
_fixture.Register(() => new LanguageInfoDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new IsbnEntity(
|
||||
_fixture.Register(() => new IsbnDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<IsbnFormat>()
|
||||
));
|
||||
_fixture.Register(() => new BookRatingEntity(
|
||||
_fixture.Register(() => new BookRatingDto(
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<decimal>(),
|
||||
_fixture.Create<BookRatingSource?>(),
|
||||
_fixture.Create<int?>()
|
||||
));
|
||||
_fixture.Register(() => new WrittenContentMetadataEntity(
|
||||
_fixture.Register(() => new WrittenContentMetadataDto(
|
||||
_fixture.Create<string>()[255..],
|
||||
LimitStringLength(_fixture.Create<string?>(), 255),
|
||||
LimitStringLength(_fixture.Create<string?>(), 2000),
|
||||
_fixture.Create<ReleaseInfoEntity>(),
|
||||
_fixture.Create<List<GenreEntity>>(),
|
||||
_fixture.Create<List<TagEntity>>(),
|
||||
_fixture.Create<LanguageInfoEntity?>(),
|
||||
_fixture.Create<LanguageInfoEntity?>(),
|
||||
_fixture.Create<ReleaseInfoDto>(),
|
||||
_fixture.Create<List<GenreDto>>(),
|
||||
_fixture.Create<List<TagDto>>(),
|
||||
_fixture.Create<LanguageInfoDto?>(),
|
||||
_fixture.Create<LanguageInfoDto?>(),
|
||||
_fixture.Create<string?>(),
|
||||
_fixture.Create<int?>()
|
||||
));
|
||||
_fixture.Register(() => new BookSeriesEntity(
|
||||
_fixture.Register(() => new BookSeriesDto(
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorRoleEntity(
|
||||
_fixture.Register(() => new MediaContributorRoleDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorNameEntity(
|
||||
_fixture.Register(() => new MediaContributorNameDto(
|
||||
_fixture.Create<string>(),
|
||||
_fixture.Create<string?>()
|
||||
));
|
||||
_fixture.Register(() => new MediaContributorEntity(
|
||||
_fixture.Create<MediaContributorNameEntity>(),
|
||||
_fixture.Create<MediaContributorRoleEntity>()
|
||||
_fixture.Register(() => new MediaContributorDto(
|
||||
_fixture.Create<MediaContributorNameDto>(),
|
||||
_fixture.Create<MediaContributorRoleDto>()
|
||||
));
|
||||
}
|
||||
|
||||
+29
-29
@@ -2,18 +2,18 @@
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaContributors;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="AddBookRequest"/> class.
|
||||
@@ -45,8 +45,8 @@ public class AddBookRequestFixture
|
||||
int releaseYear = _random.Next(2000, 2010);
|
||||
int reReleaseYear = _random.Next(2010, 2020);
|
||||
|
||||
ReleaseInfoEntity releaseInfo = new Faker<ReleaseInfoEntity>()
|
||||
.CustomInstantiator(f => new ReleaseInfoEntity(
|
||||
ReleaseInfoDto releaseInfo = new Faker<ReleaseInfoDto>()
|
||||
.CustomInstantiator(f => new ReleaseInfoDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -62,44 +62,44 @@ public class AddBookRequestFixture
|
||||
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.Generate();
|
||||
|
||||
Faker<GenreEntity> genre = new Faker<GenreEntity>()
|
||||
.CustomInstantiator(f => new GenreEntity(
|
||||
Faker<GenreDto> genre = new Faker<GenreDto>()
|
||||
.CustomInstantiator(f => new GenreDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<TagEntity> tag = new Faker<TagEntity>()
|
||||
.CustomInstantiator(f => new TagEntity(
|
||||
Faker<TagDto> tag = new Faker<TagDto>()
|
||||
.CustomInstantiator(f => new TagDto(
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorRoleEntity> mediaContributorRole = new Faker<MediaContributorRoleEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleEntity(
|
||||
Faker<MediaContributorRoleDto> mediaContributorRole = new Faker<MediaContributorRoleDto>()
|
||||
.CustomInstantiator(f => new MediaContributorRoleDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorNameEntity> mediaContributorName = new Faker<MediaContributorNameEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorNameEntity(
|
||||
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
|
||||
.CustomInstantiator(f => new MediaContributorNameDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
|
||||
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<MediaContributorEntity> mediaContributor = new Faker<MediaContributorEntity>()
|
||||
.CustomInstantiator(f => new MediaContributorEntity(
|
||||
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
|
||||
.CustomInstantiator(f => new MediaContributorDto(
|
||||
default!,
|
||||
default!
|
||||
))
|
||||
.RuleFor(e => e.Name, mediaContributorName)
|
||||
.RuleFor(e => e.Role, mediaContributorRole);
|
||||
|
||||
Faker<BookRatingEntity> rating = new Faker<BookRatingEntity>()
|
||||
.CustomInstantiator(f => new BookRatingEntity(
|
||||
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
|
||||
.CustomInstantiator(f => new BookRatingDto(
|
||||
default,
|
||||
default,
|
||||
default,
|
||||
@@ -110,8 +110,8 @@ public class AddBookRequestFixture
|
||||
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
|
||||
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
|
||||
|
||||
Faker<LanguageInfoEntity> language = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -120,8 +120,8 @@ public class AddBookRequestFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<LanguageInfoEntity> originalLanguage = new Faker<LanguageInfoEntity>()
|
||||
.CustomInstantiator(f => new LanguageInfoEntity(
|
||||
Faker<LanguageInfoDto> originalLanguage = new Faker<LanguageInfoDto>()
|
||||
.CustomInstantiator(f => new LanguageInfoDto(
|
||||
default!,
|
||||
default!,
|
||||
default
|
||||
@@ -130,8 +130,8 @@ public class AddBookRequestFixture
|
||||
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
|
||||
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
|
||||
|
||||
Faker<WrittenContentMetadataEntity> metadata = new Faker<WrittenContentMetadataEntity>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataEntity(
|
||||
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
|
||||
.CustomInstantiator(f => new WrittenContentMetadataDto(
|
||||
default!,
|
||||
default,
|
||||
default,
|
||||
@@ -154,8 +154,8 @@ public class AddBookRequestFixture
|
||||
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
|
||||
.RuleFor(x => x.PageCount, _random.Next(100, 300));
|
||||
|
||||
Faker<IsbnEntity> isbn = new Faker<IsbnEntity>()
|
||||
.CustomInstantiator(f => new IsbnEntity(
|
||||
Faker<IsbnDto> isbn = new Faker<IsbnDto>()
|
||||
.CustomInstantiator(f => new IsbnDto(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
@@ -172,7 +172,7 @@ public class AddBookRequestFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
@@ -183,7 +183,7 @@ public class AddBookRequestFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
+5
-5
@@ -1,16 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.UnitTests.Common.Setup;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookEntity"/> class.
|
||||
@@ -84,7 +84,7 @@ public class BookEntityFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
else
|
||||
@@ -95,7 +95,7 @@ public class BookEntityFixture
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
}
|
||||
+9
-5
@@ -14,20 +14,20 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Book"/> domain entity.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DomainBookFixture
|
||||
public class BookFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="DomainBookFixture"/> class.
|
||||
/// Initializes a new instance of the <see cref="BookFixture"/> class.
|
||||
/// </summary>
|
||||
public DomainBookFixture()
|
||||
public BookFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
|
||||
@@ -35,6 +35,10 @@ public class DomainBookFixture
|
||||
ConfigureCustomDomainTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid book domain entity.
|
||||
/// </summary>
|
||||
/// <returns>The created book domain entity.</returns>
|
||||
public Book CreateDomainBook()
|
||||
{
|
||||
return Book.Create(
|
||||
@@ -69,7 +73,7 @@ public class DomainBookFixture
|
||||
int reReleaseYear = _fixture.Create<Generator<int>>().First(y => y >= originalYear && y <= 2025);
|
||||
|
||||
return ReleaseInfo.Create(
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(originalYear, 1, 1))),
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(originalYear, 1, 1))),
|
||||
Optional<int>.Some(originalYear),
|
||||
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(reReleaseYear, 1, 1))),
|
||||
Optional<int>.Some(reReleaseYear),
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRatingDto"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingDtoFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRatingDtoFixture"/> class.
|
||||
/// </summary>
|
||||
public BookRatingDtoFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a complete book rating DTO with all properties.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating DTO.</returns>
|
||||
public BookRatingDto CreateComplete()
|
||||
{
|
||||
return new BookRatingDto(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a minimal book rating DTO with only required properties.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating DTO.</returns>
|
||||
public BookRatingDto CreateMinimal()
|
||||
{
|
||||
return new BookRatingDto(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an invalid book rating DTO.
|
||||
/// </summary>
|
||||
/// <returns>The created invalid book rating DTO.</returns>
|
||||
public BookRatingDto CreateInvalid()
|
||||
{
|
||||
return new BookRatingDto(
|
||||
10, // invalid: value > maxValue
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
);
|
||||
}
|
||||
}
|
||||
+10
-27
@@ -1,13 +1,12 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRatingEntity"/>.
|
||||
@@ -15,7 +14,6 @@ namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.C
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingEntityFixture
|
||||
{
|
||||
private readonly Fixture _fixture;
|
||||
private readonly Random _random = new();
|
||||
private readonly Faker _faker;
|
||||
|
||||
@@ -24,49 +22,34 @@ public class BookRatingEntityFixture
|
||||
/// </summary>
|
||||
public BookRatingEntityFixture()
|
||||
{
|
||||
_fixture = new Fixture();
|
||||
_faker = new Faker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a complete book rating entity with all properties.
|
||||
/// Creates a book rating entity.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating entity.</returns>
|
||||
public BookRatingEntity CreateComplete()
|
||||
public BookRatingEntity CreateBookRating()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_faker.PickRandom<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a minimal book rating entity with only required properties.
|
||||
/// </summary>
|
||||
/// <returns>The created book rating entity.</returns>
|
||||
public BookRatingEntity CreateMinimal()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
_random.Next(1, 5),
|
||||
5,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an invalid book rating entity.
|
||||
/// </summary>
|
||||
/// <returns>The created invalid book rating entity.</returns>
|
||||
public BookRatingEntity CreateInvalid()
|
||||
public BookRatingEntity CreateInvalidBookRating()
|
||||
{
|
||||
return new BookRatingEntity(
|
||||
10, // invalid: value > maxValue
|
||||
5,
|
||||
_fixture.Create<BookRatingSource>(),
|
||||
_random.Next(1, 1000)
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="BookRating"/> domain entity.
|
||||
+20
-20
@@ -1,51 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="IsbnEntity"/>.
|
||||
/// Fixture class for the <see cref="IsbnDto"/>.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnEntityFixture
|
||||
public class IsbnDtoFixture
|
||||
{
|
||||
private readonly Random _random = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-10 entity.
|
||||
/// Creates a valid ISBN-10 DTO.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateIsbn10()
|
||||
/// <returns>The created ISBN DTO.</returns>
|
||||
public IsbnDto CreateIsbn10()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
return new IsbnDto(
|
||||
GenerateValidIsbn10(),
|
||||
IsbnFormat.Isbn10
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid ISBN-13 entity.
|
||||
/// Creates a valid ISBN-13 DTO.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateIsbn13()
|
||||
/// <returns>The created ISBN DTO.</returns>
|
||||
public IsbnDto CreateIsbn13()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
return new IsbnDto(
|
||||
GenerateValidIsbn13(),
|
||||
IsbnFormat.Isbn13
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an invalid ISBN entity.
|
||||
/// Creates an invalid ISBN DTO.
|
||||
/// </summary>
|
||||
/// <returns>The created invalid ISBN entity.</returns>
|
||||
public IsbnEntity CreateInvalid()
|
||||
/// <returns>The created invalid ISBN DTO.</returns>
|
||||
public IsbnDto CreateInvalid()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
return new IsbnDto(
|
||||
"invalid-isbn",
|
||||
IsbnFormat.Isbn13
|
||||
);
|
||||
@@ -55,9 +55,9 @@ public class IsbnEntityFixture
|
||||
/// Creates an ISBN entity without format.
|
||||
/// </summary>
|
||||
/// <returns>The created ISBN entity.</returns>
|
||||
public IsbnEntity CreateWithoutFormat()
|
||||
public IsbnDto CreateWithoutFormat()
|
||||
{
|
||||
return new IsbnEntity(
|
||||
return new IsbnDto(
|
||||
GenerateValidIsbn13(),
|
||||
null
|
||||
);
|
||||
@@ -73,7 +73,7 @@ public class IsbnEntityFixture
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
@@ -91,7 +91,7 @@ public class IsbnEntityFixture
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
+3
-3
@@ -5,7 +5,7 @@ using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Core.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="Isbn"/> domain entity.
|
||||
@@ -45,7 +45,7 @@ public class IsbnFixture
|
||||
for (int i = 0; i < 9; i++)
|
||||
sum += (10 - i) * digits[i];
|
||||
|
||||
int checkDigit = (11 - (sum % 11)) % 11;
|
||||
int checkDigit = (11 - sum % 11) % 11;
|
||||
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
|
||||
|
||||
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
|
||||
@@ -63,7 +63,7 @@ public class IsbnFixture
|
||||
for (int i = 0; i < 12; i++)
|
||||
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
|
||||
|
||||
int checkDigit = (10 - (sum % 10)) % 10;
|
||||
int checkDigit = (10 - sum % 10) % 10;
|
||||
|
||||
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
|
||||
}
|
||||
+3
-2
@@ -2,8 +2,8 @@
|
||||
using EntityFrameworkCore.Testing.NSubstitute;
|
||||
using ErrorOr;
|
||||
using FluentAssertions;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.DataAccess.Core.Repositories.Books;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -16,6 +16,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books;
|
||||
|
||||
+4
-2
@@ -1,14 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using AutoFixture;
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Enums.BookLibrary;
|
||||
using Lumina.DataAccess.UnitTests.Common.Setup;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
|
||||
|
||||
-3
@@ -8,7 +8,6 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
|
||||
using Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.ValueObjects.Fixtures;
|
||||
using NSubstitute;
|
||||
using NSubstitute.ExceptionExtensions;
|
||||
@@ -19,8 +18,6 @@ using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Services;
|
||||
|
||||
Reference in new issue
Block a user