mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 23:11:10 +00:00
Renames project paths from Lumina to Nemera
This commit is contained in:
1 parent
ce6fddb4c9
commit
0f659a4877
6450 files changed
No files matched your search
+271
@@ -0,0 +1,271 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaContributors;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Book"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateBook()
|
||||
{
|
||||
// Act
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(book);
|
||||
Assert.NotNull(book.Metadata);
|
||||
Assert.NotNull(book.Path);
|
||||
Assert.NotNull(book.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateContributors_WhenCalled_ShouldReplaceTheContributors()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMediaContributor firstContributor = CreateAuthorContributor();
|
||||
BookMediaContributor secondContributor = CreateAuthorContributor();
|
||||
|
||||
// Act
|
||||
book.UpdateContributors([firstContributor, secondContributor]);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, book.Contributors.Count);
|
||||
Assert.Contains(book.Contributors, contributor => contributor == firstContributor);
|
||||
Assert.Contains(book.Contributors, contributor => contributor == secondContributor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateContributors_WhenCalledAgain_ShouldReplaceTheContributors()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
book.UpdateContributors([CreateAuthorContributor()]);
|
||||
BookMediaContributor replacementContributor = CreateAuthorContributor();
|
||||
|
||||
// Act
|
||||
book.UpdateContributors([replacementContributor]);
|
||||
|
||||
// Assert
|
||||
// The previous contributors are replaced, not appended.
|
||||
BookMediaContributor contributor = Assert.Single(book.Contributors);
|
||||
Assert.Equal(replacementContributor, contributor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenContributorsContainDuplicates_ShouldKeepOnlyUniqueContributors()
|
||||
{
|
||||
// Arrange
|
||||
BookMediaContributor contributor = CreateAuthorContributor();
|
||||
|
||||
// Act
|
||||
Book book = _bookFixture.Create(contributors: [contributor, contributor]);
|
||||
|
||||
// Assert
|
||||
BookMediaContributor storedContributor = Assert.Single(book.Contributors);
|
||||
Assert.Equal(contributor, storedContributor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateContributors_WhenCalledWithDuplicates_ShouldKeepOnlyUniqueContributors()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMediaContributor contributor = CreateAuthorContributor();
|
||||
|
||||
// Act
|
||||
book.UpdateContributors([contributor, contributor]);
|
||||
|
||||
// Assert
|
||||
BookMediaContributor storedContributor = Assert.Single(book.Contributors);
|
||||
Assert.Equal(contributor, storedContributor);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndTimestamps_ShouldPreserveIdentityAndTimestamps()
|
||||
{
|
||||
// Arrange
|
||||
Book sourceBook = _bookFixture.Create();
|
||||
DateTime createdOnUtc = DateTime.UtcNow.AddDays(-1);
|
||||
DateTime updatedOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
Result<Book> result = Book.Create(
|
||||
sourceBook.Id,
|
||||
sourceBook.LibraryId,
|
||||
sourceBook.Path,
|
||||
sourceBook.Metadata,
|
||||
sourceBook.Format,
|
||||
sourceBook.Edition,
|
||||
sourceBook.VolumeNumber,
|
||||
sourceBook.Series,
|
||||
sourceBook.ASIN,
|
||||
sourceBook.GoodreadsId,
|
||||
sourceBook.LCCN,
|
||||
sourceBook.OCLCNumber,
|
||||
sourceBook.OpenLibraryId,
|
||||
sourceBook.LibraryThingId,
|
||||
sourceBook.GoogleBooksId,
|
||||
sourceBook.BarnesAndNobleId,
|
||||
sourceBook.AppleBooksId,
|
||||
createdOnUtc,
|
||||
Optional<DateTime>.Some(updatedOnUtc),
|
||||
[.. sourceBook.ISBNs],
|
||||
[.. sourceBook.Contributors],
|
||||
[.. sourceBook.Ratings]);
|
||||
|
||||
// Assert
|
||||
Book book = result.Value;
|
||||
Assert.Equal(sourceBook.Id, book.Id);
|
||||
Assert.Equal(sourceBook.LibraryId, book.LibraryId);
|
||||
Assert.Equal(sourceBook.Path, book.Path);
|
||||
Assert.Equal(sourceBook.Metadata, book.Metadata);
|
||||
Assert.Equal(createdOnUtc, book.CreatedOnUtc);
|
||||
Assert.Equal(Optional<DateTime>.Some(updatedOnUtc), book.UpdatedOnUtc);
|
||||
Assert.Equal(sourceBook.ISBNs, book.ISBNs);
|
||||
Assert.Equal(sourceBook.Ratings, book.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyEnrichedMetadata_WhenCalled_ShouldReplaceMetadataAndRelatedFields()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
Book enrichedSource = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
book.ApplyEnrichedMetadata(
|
||||
enrichedSource.Metadata,
|
||||
enrichedSource.Format,
|
||||
enrichedSource.Edition,
|
||||
enrichedSource.VolumeNumber,
|
||||
enrichedSource.Series,
|
||||
enrichedSource.ASIN,
|
||||
enrichedSource.GoodreadsId,
|
||||
enrichedSource.LCCN,
|
||||
enrichedSource.OCLCNumber,
|
||||
enrichedSource.OpenLibraryId,
|
||||
enrichedSource.LibraryThingId,
|
||||
enrichedSource.GoogleBooksId,
|
||||
enrichedSource.BarnesAndNobleId,
|
||||
enrichedSource.AppleBooksId,
|
||||
[.. enrichedSource.ISBNs],
|
||||
[.. enrichedSource.Ratings]);
|
||||
|
||||
// Assert
|
||||
// The metadata and related fields are replaced with the enriched values.
|
||||
Assert.Equal(enrichedSource.Metadata, book.Metadata);
|
||||
Assert.Equal(enrichedSource.Format, book.Format);
|
||||
Assert.Equal(enrichedSource.Edition, book.Edition);
|
||||
Assert.Equal(enrichedSource.VolumeNumber, book.VolumeNumber);
|
||||
Assert.Equal(enrichedSource.Series, book.Series);
|
||||
Assert.Equal(enrichedSource.ASIN, book.ASIN);
|
||||
Assert.Equal(enrichedSource.GoodreadsId, book.GoodreadsId);
|
||||
Assert.Equal(enrichedSource.LCCN, book.LCCN);
|
||||
Assert.Equal(enrichedSource.OCLCNumber, book.OCLCNumber);
|
||||
Assert.Equal(enrichedSource.OpenLibraryId, book.OpenLibraryId);
|
||||
Assert.Equal(enrichedSource.LibraryThingId, book.LibraryThingId);
|
||||
Assert.Equal(enrichedSource.GoogleBooksId, book.GoogleBooksId);
|
||||
Assert.Equal(enrichedSource.BarnesAndNobleId, book.BarnesAndNobleId);
|
||||
Assert.Equal(enrichedSource.AppleBooksId, book.AppleBooksId);
|
||||
Assert.Equal(enrichedSource.ISBNs, book.ISBNs);
|
||||
Assert.Equal(enrichedSource.Ratings, book.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyEnrichedMetadata_WhenCalledAgain_ShouldReplaceCollectionsWithoutAppending()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
Book firstEnrichmentSource = _bookFixture.Create();
|
||||
Book secondEnrichmentSource = _bookFixture.Create();
|
||||
book.ApplyEnrichedMetadata(
|
||||
firstEnrichmentSource.Metadata,
|
||||
firstEnrichmentSource.Format,
|
||||
firstEnrichmentSource.Edition,
|
||||
firstEnrichmentSource.VolumeNumber,
|
||||
firstEnrichmentSource.Series,
|
||||
firstEnrichmentSource.ASIN,
|
||||
firstEnrichmentSource.GoodreadsId,
|
||||
firstEnrichmentSource.LCCN,
|
||||
firstEnrichmentSource.OCLCNumber,
|
||||
firstEnrichmentSource.OpenLibraryId,
|
||||
firstEnrichmentSource.LibraryThingId,
|
||||
firstEnrichmentSource.GoogleBooksId,
|
||||
firstEnrichmentSource.BarnesAndNobleId,
|
||||
firstEnrichmentSource.AppleBooksId,
|
||||
[.. firstEnrichmentSource.ISBNs],
|
||||
[.. firstEnrichmentSource.Ratings]);
|
||||
|
||||
// Act
|
||||
book.ApplyEnrichedMetadata(
|
||||
secondEnrichmentSource.Metadata,
|
||||
secondEnrichmentSource.Format,
|
||||
secondEnrichmentSource.Edition,
|
||||
secondEnrichmentSource.VolumeNumber,
|
||||
secondEnrichmentSource.Series,
|
||||
secondEnrichmentSource.ASIN,
|
||||
secondEnrichmentSource.GoodreadsId,
|
||||
secondEnrichmentSource.LCCN,
|
||||
secondEnrichmentSource.OCLCNumber,
|
||||
secondEnrichmentSource.OpenLibraryId,
|
||||
secondEnrichmentSource.LibraryThingId,
|
||||
secondEnrichmentSource.GoogleBooksId,
|
||||
secondEnrichmentSource.BarnesAndNobleId,
|
||||
secondEnrichmentSource.AppleBooksId,
|
||||
[.. secondEnrichmentSource.ISBNs],
|
||||
[.. secondEnrichmentSource.Ratings]);
|
||||
|
||||
// Assert
|
||||
// The second enrichment replaces the first, it is not appended to it.
|
||||
Assert.Equal(secondEnrichmentSource.ISBNs.Count, book.ISBNs.Count);
|
||||
Assert.Equal(secondEnrichmentSource.ISBNs, book.ISBNs);
|
||||
Assert.Equal(secondEnrichmentSource.Ratings, book.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldNotExposeEnrichmentTracking()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
Type bookType = book.GetType();
|
||||
|
||||
// Act
|
||||
bool hasMetadataStatus = bookType.GetProperty("MetadataStatus") is not null;
|
||||
bool hasLastMetadataUpdateUtc = bookType.GetProperty("LastMetadataUpdateUtc") is not null;
|
||||
bool hasMetadataProvider = bookType.GetProperty("MetadataProvider") is not null;
|
||||
bool hasCoverImagePath = bookType.GetProperty("CoverImagePath") is not null;
|
||||
|
||||
// Assert
|
||||
// The enrichment state is a persistence concern, tracked on the repository entity by the enrichment jobs.
|
||||
Assert.False(hasMetadataStatus);
|
||||
Assert.False(hasLastMetadataUpdateUtc);
|
||||
Assert.False(hasMetadataProvider);
|
||||
Assert.False(hasCoverImagePath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="BookMediaContributor"/> of a random media contributor playing the Author role.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="BookMediaContributor"/>.</returns>
|
||||
private static BookMediaContributor CreateAuthorContributor()
|
||||
{
|
||||
return BookMediaContributor.Create(MediaContributorId.CreateUnique(), MediaContributorRole.Author).Value;
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookSeries"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookSeriesTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
|
||||
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
|
||||
private readonly BookSeriesFixture _bookSeriesFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateSeries()
|
||||
{
|
||||
// Act
|
||||
Result<BookSeries> result = BookSeries.Create(_writtenContentMetadataFixture.Create(), isComplete: false, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.IsComplete);
|
||||
Assert.Empty(result.Value.Books);
|
||||
Assert.NotEqual(default, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldCreateSeriesWithThatId()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<BookSeries> result = BookSeries.Create(_bookSeriesIdFixture.Create(id), _writtenContentMetadataFixture.Create(), isComplete: true, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
Assert.True(result.Value.IsComplete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddBook_WhenBookIsNotInSeries_ShouldAddBookAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = series.AddBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
Assert.Single(series.Books);
|
||||
Assert.Contains(book, series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddBook_WhenBookIsAlreadyInSeries_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
series.AddBook(book);
|
||||
|
||||
// Act
|
||||
Result<Created> result = series.AddBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.TheBookIsAlreadyInTheSeries, result.FirstError);
|
||||
Assert.Single(series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveBook_WhenBookIsInSeries_ShouldRemoveBookAndReturnDeleted()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
series.AddBook(book);
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = series.RemoveBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
Assert.Empty(series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveBook_WhenBookIsNotInSeries_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = series.RemoveBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.TheBookIsNotInTheSeries, result.FirstError);
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryPathPartCatalog"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryPathPartCatalogTests
|
||||
{
|
||||
private readonly BookLibraryPathPartCatalog _sut = new();
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryType_WhenCalled_ShouldReturnBook()
|
||||
{
|
||||
// Act
|
||||
LibraryType result = _sut.SupportedLibraryType;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryType.Book, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPartDefinitions_WhenCalled_ShouldReturnTheExpectedDefinitions()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPartDefinition> result = _sut.GetPartDefinitions();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(8, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[0].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[0].ValueType);
|
||||
Assert.Equal(string.Empty, result[0].DefaultRepresentation);
|
||||
Assert.False(result[0].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[1].ValueType);
|
||||
Assert.Equal(string.Empty, result[1].DefaultRepresentation);
|
||||
Assert.False(result[1].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[2].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[2].ValueType);
|
||||
Assert.Equal("{0}", result[2].DefaultRepresentation);
|
||||
Assert.False(result[2].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[3].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[3].ValueType);
|
||||
Assert.Equal("{0}", result[3].DefaultRepresentation);
|
||||
Assert.False(result[3].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Series, result[4].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[4].ValueType);
|
||||
Assert.Equal("{0}", result[4].DefaultRepresentation);
|
||||
Assert.True(result[4].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.SeriesNumber, result[5].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[5].ValueType);
|
||||
Assert.Equal("{0}", result[5].DefaultRepresentation);
|
||||
Assert.True(result[5].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.BookId, result[6].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[6].ValueType);
|
||||
Assert.Equal("{0}", result[6].DefaultRepresentation);
|
||||
Assert.False(result[6].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[7].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[7].ValueType);
|
||||
Assert.Equal("{0}", result[7].DefaultRepresentation);
|
||||
Assert.False(result[7].IsOptionalByDefault);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTemplate_WhenCalled_ShouldReturnTheExpectedParts()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPart> result = _sut.GetDefaultTemplate().Parts;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(12, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[0].Kind);
|
||||
Assert.Equal("{0}", result[0].Representation);
|
||||
Assert.False(result[0].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(string.Empty, result[1].Representation);
|
||||
Assert.False(result[1].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[2].Kind);
|
||||
Assert.Equal("{0}", result[2].Representation);
|
||||
Assert.False(result[2].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[3].Kind);
|
||||
Assert.Equal(" (", result[3].Representation);
|
||||
Assert.False(result[3].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.BookId, result[4].Kind);
|
||||
Assert.Equal("{0}", result[4].Representation);
|
||||
Assert.False(result[4].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[5].Kind);
|
||||
Assert.Equal(")", result[5].Representation);
|
||||
Assert.False(result[5].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[6].Kind);
|
||||
Assert.Equal(string.Empty, result[6].Representation);
|
||||
Assert.False(result[6].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[7].Kind);
|
||||
Assert.Equal("{0}", result[7].Representation);
|
||||
Assert.False(result[7].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[8].Kind);
|
||||
Assert.Equal(" - ", result[8].Representation);
|
||||
Assert.False(result[8].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[9].Kind);
|
||||
Assert.Equal("{0}", result[9].Representation);
|
||||
Assert.False(result[9].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[10].Kind);
|
||||
Assert.Equal(".", result[10].Representation);
|
||||
Assert.False(result[10].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[11].Kind);
|
||||
Assert.Equal("{0}", result[11].Representation);
|
||||
Assert.False(result[11].IsOptional);
|
||||
}
|
||||
}
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryTypeScanner"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryTypeScannerTests
|
||||
{
|
||||
private readonly IMediaLibraryScanJobFactory _mockJobFactory = Substitute.For<IMediaLibraryScanJobFactory>();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryType_ShouldBeBook()
|
||||
{
|
||||
// Arrange
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Equal(LibraryType.Book, sut.SupportedLibraryType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobChainWithEnrichmentJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
TestScanJob invalidationJob = CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
TestScanJob enrichmentJob = CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
TestScanJob artworkEnrichmentJob = CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
IMediaLibraryScanDiscoveryJob rootJob = sut.CreateScanJobsForLibrary(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
Assert.IsAssignableFrom<IBooksFileSystemDiscoveryJob>(rootJob);
|
||||
Assert.Contains(diffJob, discoveryJob.Children);
|
||||
Assert.Contains(discoveryJob, diffJob.Parents);
|
||||
Assert.Contains(hashJob, diffJob.Children);
|
||||
Assert.Contains(diffJob, hashJob.Parents);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(hashJob, saveJob.Parents);
|
||||
Assert.Contains(invalidationJob, saveJob.Children);
|
||||
Assert.Contains(saveJob, invalidationJob.Parents);
|
||||
Assert.Contains(enrichmentJob, invalidationJob.Children);
|
||||
Assert.Contains(invalidationJob, enrichmentJob.Parents);
|
||||
Assert.Contains(artworkEnrichmentJob, enrichmentJob.Children);
|
||||
Assert.Contains(enrichmentJob, artworkEnrichmentJob.Parents);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanArtworkEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldReturnTheFileSystemDiscoveryJobAsTheOnlyRoot()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
CreateJob<IMediaLibraryScanDiffJob>();
|
||||
CreateJob<IMediaLibraryScanHashJob>();
|
||||
CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
IMediaLibraryScanDiscoveryJob rootJob = sut.CreateScanJobsForLibrary(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
// The file system discovery job is the only top level job, so nothing else is reachable without it.
|
||||
Assert.Empty(discoveryJob.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldMakeTheWholeChainReachableFromTheRoot()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
TestScanJob invalidationJob = CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
TestScanJob enrichmentJob = CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
TestScanJob artworkEnrichmentJob = CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
IMediaLibraryScanDiscoveryJob rootJob = sut.CreateScanJobsForLibrary(libraryId);
|
||||
HashSet<IMediaLibraryScanJob> reachableJobs = GetReachableJobs(rootJob);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(7, reachableJobs.Count);
|
||||
Assert.Contains(discoveryJob, reachableJobs);
|
||||
Assert.Contains(diffJob, reachableJobs);
|
||||
Assert.Contains(hashJob, reachableJobs);
|
||||
Assert.Contains(saveJob, reachableJobs);
|
||||
Assert.Contains(invalidationJob, reachableJobs);
|
||||
Assert.Contains(enrichmentJob, reachableJobs);
|
||||
Assert.Contains(artworkEnrichmentJob, reachableJobs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobsForTheLibrary()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
CreateJob<IMediaLibraryScanDiffJob>();
|
||||
CreateJob<IMediaLibraryScanHashJob>();
|
||||
CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>();
|
||||
CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
CreateJob<IMediaLibraryScanArtworkEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
_ = sut.CreateScanJobsForLibrary(libraryId);
|
||||
|
||||
// Assert
|
||||
_mockJobFactory.Received(1).CreateJob<IBooksFileSystemDiscoveryJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanDiffJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanHashJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanResultsSaveJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanProviderConfigurationInvalidationJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanArtworkEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Collects every job that is reachable from <paramref name="rootJob"/> through the child relationships.
|
||||
/// </summary>
|
||||
/// <param name="rootJob">The root job of the job graph.</param>
|
||||
/// <returns>The set of reachable jobs.</returns>
|
||||
private static HashSet<IMediaLibraryScanJob> GetReachableJobs(IMediaLibraryScanJob rootJob)
|
||||
{
|
||||
HashSet<IMediaLibraryScanJob> reachableJobs = [];
|
||||
Queue<IMediaLibraryScanJob> jobsToVisit = new();
|
||||
jobsToVisit.Enqueue(rootJob);
|
||||
while (jobsToVisit.Count > 0)
|
||||
{
|
||||
IMediaLibraryScanJob currentJob = jobsToVisit.Dequeue();
|
||||
if (!reachableJobs.Add(currentJob))
|
||||
continue;
|
||||
foreach (IMediaLibraryScanJob childJob in currentJob.Children)
|
||||
jobsToVisit.Enqueue(childJob);
|
||||
}
|
||||
return reachableJobs;
|
||||
}
|
||||
|
||||
private TestScanJob CreateJob<TJob>() where TJob : class, IMediaLibraryScanJob
|
||||
{
|
||||
TestScanJob job = new()
|
||||
{
|
||||
ScanId = _scanIdFixture.Create(),
|
||||
UserId = _userIdFixture.Create(),
|
||||
LibraryId = _libraryIdFixture.Create()
|
||||
};
|
||||
_mockJobFactory.CreateJob<TJob>(Arg.Any<LibraryId>()).Returns((TJob)(object)job);
|
||||
return job;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concrete test implementation of the abstract <see cref="MediaLibraryScanJob"/> class that satisfies all job interfaces.
|
||||
/// </summary>
|
||||
private sealed class TestScanJob : MediaLibraryScanJob,
|
||||
IBooksFileSystemDiscoveryJob,
|
||||
IMediaLibraryScanDiffJob,
|
||||
IMediaLibraryScanHashJob,
|
||||
IMediaLibraryScanResultsSaveJob,
|
||||
IMediaLibraryScanProviderConfigurationInvalidationJob,
|
||||
IMediaLibraryScanMetadataEnrichmentJob,
|
||||
IMediaLibraryScanArtworkEnrichmentJob
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the payload of the media library scan job.
|
||||
/// </summary>
|
||||
/// <typeparam name="TInput">The type of the input parameter.</typeparam>
|
||||
/// <param name="id">The unique identifier of the media library scan job.</param>
|
||||
/// <param name="input">The input data to be processed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public override Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookIdTests
|
||||
{
|
||||
private readonly BookIdFixture _bookIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
BookId bookId = BookId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(bookId);
|
||||
Assert.NotEqual(default, bookId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
BookId bookId = BookId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, bookId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
BookId firstId = _bookIdFixture.Create(value);
|
||||
BookId secondId = _bookIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
BookId firstId = _bookIdFixture.Create();
|
||||
BookId secondId = _bookIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRating"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingTests
|
||||
{
|
||||
private readonly BookRatingFixture _bookRatingFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateRating()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
Optional<int>.Some(100));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(4.5m, result.Value.Value);
|
||||
Assert.Equal(5, result.Value.MaxValue);
|
||||
Assert.True(result.Value.Source.HasValue);
|
||||
Assert.Equal(BookRatingSource.Goodreads, result.Value.Source.Value);
|
||||
Assert.True(result.Value.VoteCount.HasValue);
|
||||
Assert.Equal(100, result.Value.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // Negative value.
|
||||
[InlineData(-0.5)] // Negative fractional value.
|
||||
public void Create_WhenValueIsNegative_ShouldReturnError(double value)
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create((decimal)value, maxValue: 5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenMaxValueIsNegative_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(value: 4.5m, maxValue: -5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenValueExceedsMaxValue_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(value: 6, maxValue: 5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueCannotBeGreaterThanMaxValue, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsPercentage_WhenCalled_ShouldReturnValueAsPercentageOfMaxValue()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(value: 4.5m, maxValue: 5);
|
||||
|
||||
// Act
|
||||
decimal result = rating.AsPercentage();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(90, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenSourceAndVoteCountArePresent_ShouldIncludeThem()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
|
||||
// Act
|
||||
string result = rating.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("4.5/5 (Goodreads) [100 votes]", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenSourceAndVoteCountAreAbsent_ShouldReturnBaseString()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.None(),
|
||||
voteCount: Optional<int>.None());
|
||||
|
||||
// Act
|
||||
string result = rating.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("4.5/5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
BookRating firstRating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
BookRating secondRating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
|
||||
// Act
|
||||
bool result = firstRating.Equals(secondRating);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookSeriesId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookSeriesIdTests
|
||||
{
|
||||
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
BookSeriesId seriesId = BookSeriesId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(seriesId);
|
||||
Assert.NotEqual(default, seriesId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
BookSeriesId seriesId = BookSeriesId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, seriesId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
BookSeriesId firstId = _bookSeriesIdFixture.Create(value);
|
||||
BookSeriesId secondId = _bookSeriesIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
BookSeriesId firstId = _bookSeriesIdFixture.Create();
|
||||
BookSeriesId secondId = _bookSeriesIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Isbn"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnTests
|
||||
{
|
||||
private readonly IsbnFixture _isbnFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidIsbn10_ShouldCreateIsbn10()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-2", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("0-306-40615-2", result.Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn10, result.Value.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidIsbn13_ShouldCreateIsbn13()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("978-0-306-40615-7", IsbnFormat.Isbn13);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("978-0-306-40615-7", result.Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn13, result.Value.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // Null ISBN value.
|
||||
[InlineData("")] // Empty ISBN value.
|
||||
[InlineData(" ")] // Whitespace ISBN value.
|
||||
public void Create_WhenValueIsNullOrWhitespace_ShouldReturnError(string? value)
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create(value!, IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.IsbnValueCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenFormatIsUnknown_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-2", (IsbnFormat)999);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.UnknownIsbnFormat, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn10HasInvalidCheckDigit_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-3", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn10Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn13HasInvalidCheckDigit_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("978-0-306-40615-8", IsbnFormat.Isbn13);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn13Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn10HasWrongLength_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("123456789", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn10Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-306-40615-2")] // Valid ISBN-10 with hyphens.
|
||||
[InlineData("0306406152")] // Valid ISBN-10 without hyphens.
|
||||
public void IsValidIsbn10_WhenValueIsValid_ShouldReturnTrue(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn10(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-306-40615-3")] // Invalid check digit.
|
||||
[InlineData("030640615")] // Too short.
|
||||
[InlineData("03064061523")] // Too long.
|
||||
[InlineData("")] // Empty value.
|
||||
[InlineData("ISBN 0-306-40615-2")] // ISBN prefix is not stripped by the checksum computation.
|
||||
public void IsValidIsbn10_WhenValueIsInvalid_ShouldReturnFalse(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn10(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("978-0-306-40615-7")] // Valid ISBN-13 with hyphens.
|
||||
[InlineData("9780306406157")] // Valid ISBN-13 without hyphens.
|
||||
[InlineData("979-0-306-40615-6")] // Valid ISBN-13 with 979 prefix.
|
||||
public void IsValidIsbn13_WhenValueIsValid_ShouldReturnTrue(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn13(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("978-0-306-40615-8")] // Invalid check digit.
|
||||
[InlineData("978030640615")] // Too short.
|
||||
[InlineData("97803064061578")] // Too long.
|
||||
[InlineData("")] // Empty value.
|
||||
[InlineData("ISBN 978-0-306-40615-7")] // ISBN prefix is not stripped by the checksum computation.
|
||||
public void IsValidIsbn13_WhenValueIsInvalid_ShouldReturnFalse(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn13(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValueAndFormat_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Isbn firstIsbn = _isbnFixture.Create(value: "0-306-40615-2", format: IsbnFormat.Isbn10);
|
||||
Isbn secondIsbn = _isbnFixture.Create(value: "0-306-40615-2", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
bool result = firstIsbn.Equals(secondIsbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
Isbn firstIsbn = _isbnFixture.Create();
|
||||
Isbn secondIsbn = _isbnFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstIsbn.Equals(secondIsbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WrittenContentMetadata"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WrittenContentMetadataTests
|
||||
{
|
||||
private readonly GenreFixture _genreFixture = new();
|
||||
private readonly TagFixture _tagFixture = new();
|
||||
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
|
||||
private readonly LanguageInfoFixture _languageInfoFixture = new();
|
||||
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateMetadataWithAllPropertiesSet()
|
||||
{
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = WrittenContentMetadata.Create(
|
||||
"Dune",
|
||||
Optional<string>.Some("Dune (Original)"),
|
||||
Optional<string>.Some("A classic science fiction novel."),
|
||||
_releaseInfoFixture.Create(),
|
||||
[_genreFixture.Create(name: "Science Fiction")],
|
||||
[_tagFixture.Create(name: "classic")],
|
||||
Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<string>.Some("Chilton Books"),
|
||||
Optional<int>.Some(412));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Dune", result.Value.Title);
|
||||
Assert.Equal("Dune (Original)", result.Value.OriginalTitle.Value);
|
||||
Assert.Equal("A classic science fiction novel.", result.Value.Description.Value);
|
||||
Assert.Single(result.Value.Genres);
|
||||
Assert.Single(result.Value.Tags);
|
||||
Assert.True(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
Assert.True(result.Value.Publisher.HasValue);
|
||||
Assert.Equal("Chilton Books", result.Value.Publisher.Value);
|
||||
Assert.True(result.Value.PageCount.HasValue);
|
||||
Assert.Equal(412, result.Value.PageCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithOptionalValuesAbsent_ShouldCreateMetadataWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = WrittenContentMetadata.Create(
|
||||
"Dune",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
_releaseInfoFixture.Create(),
|
||||
[],
|
||||
[],
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.OriginalTitle.HasValue);
|
||||
Assert.False(result.Value.Publisher.HasValue);
|
||||
Assert.False(result.Value.PageCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
WrittenContentMetadata firstResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
WrittenContentMetadata secondResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstResult, secondResult);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentPublisher_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
WrittenContentMetadata firstResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
WrittenContentMetadata secondResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.Some("Other Publisher"),
|
||||
pageCount: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstResult, secondResult);
|
||||
}
|
||||
}
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryIdTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
LibraryId libraryId = LibraryId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(libraryId);
|
||||
Assert.NotEqual(default, libraryId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
LibraryId libraryId = LibraryId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, libraryId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
LibraryId firstId = _libraryIdFixture.Create(value);
|
||||
LibraryId secondId = _libraryIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCode_WithSameValue_ShouldReturnSameHashCode()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
LibraryId firstId = _libraryIdFixture.Create(value);
|
||||
LibraryId secondId = _libraryIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
int firstHashCode = firstId.GetHashCode();
|
||||
int secondHashCode = secondId.GetHashCode();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstHashCode, secondHashCode);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId firstId = _libraryIdFixture.Create();
|
||||
LibraryId secondId = _libraryIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user