mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Adds unit tests improving application project code coverage
This commit is contained in:
1 parent
0ec6eb7ab4
commit
ca2e7f9d97
15 files changed
+785
No files matched your search
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.CancelLibraryScan;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CancelLibraryScanRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CancelLibraryScanRequestMappingTests
|
||||
{
|
||||
private readonly CancelLibraryScanRequestFixture _cancelLibraryScanRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
CancelLibraryScanRequest request = _cancelLibraryScanRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
CancelLibraryScanCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.LibraryId, result.LibraryId);
|
||||
Assert.Equal(request.ScanId, result.ScanId);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.DeleteLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DeleteLibraryRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteLibraryRequestMappingTests
|
||||
{
|
||||
private readonly DeleteLibraryRequestFixture _deleteLibraryRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
DeleteLibraryRequest request = _deleteLibraryRequestFixture.Create(id);
|
||||
|
||||
// Act
|
||||
DeleteLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.Id, result.Id);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetLibraryRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryRequestMappingTests
|
||||
{
|
||||
private readonly GetLibraryRequestFixture _getLibraryRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
GetLibraryRequest request = _getLibraryRequestFixture.Create(id);
|
||||
|
||||
// Act
|
||||
GetLibraryQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.Id, result.Id);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Queries.GetLibraryScanProgress;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetLibraryScanProgressRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryScanProgressRequestMappingTests
|
||||
{
|
||||
private readonly GetLibraryScanProgressRequestFixture _getLibraryScanProgressRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryScanProgressRequest request = _getLibraryScanProgressRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
GetLibraryScanProgressQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.LibraryId, result.LibraryId);
|
||||
Assert.Equal(request.ScanId, result.ScanId);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanJobProgressMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanJobProgressMappingTests
|
||||
{
|
||||
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidValueObject_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgress progress = _mediaLibraryScanJobProgressFixture.Create(
|
||||
completedItems: 3,
|
||||
totalItems: 10,
|
||||
currentOperation: "Hashing files");
|
||||
|
||||
// Act
|
||||
MediaLibraryScanJobProgressResponse result = progress.ToResponse();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(progress.CompletedItems, result.CompletedItems);
|
||||
Assert.Equal(progress.TotalItems, result.TotalItems);
|
||||
Assert.Equal(progress.CurrentOperation, result.CurrentOperation);
|
||||
Assert.Equal(progress.ProgressPercentage, result.ProgressPercentage);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.ScanLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ScanLibraryRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScanLibraryRequestMappingTests
|
||||
{
|
||||
private readonly ScanLibraryRequestFixture _scanLibraryRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
ScanLibraryRequest request = _scanLibraryRequestFixture.Create(id);
|
||||
|
||||
// Act
|
||||
ScanLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.Id, result.Id);
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.UpdateLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UpdateLibraryRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateLibraryRequestMappingTests
|
||||
{
|
||||
private readonly UpdateLibraryRequestFixture _updateLibraryRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
|
||||
title: "My Library",
|
||||
libraryType: "Book",
|
||||
contentLocations: ["C:/Books", "D:/Media/Books"],
|
||||
coverImage: "D:/poster.jpg",
|
||||
isEnabled: true,
|
||||
isLocked: false,
|
||||
canDownloadMetadataFromWeb: true,
|
||||
shouldSaveMetadataInMediaDirectories: false,
|
||||
shouldSkipUnchangedDirectoriesDuringScan: false);
|
||||
|
||||
// Act
|
||||
UpdateLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.Id, result.Id);
|
||||
Assert.Equal(request.Title, result.Title);
|
||||
Assert.Equal(request.LibraryType, result.LibraryType);
|
||||
Assert.Equal(request.ContentLocations, result.ContentLocations);
|
||||
Assert.Equal(request.CoverImage, result.CoverImage);
|
||||
Assert.Equal(request.IsEnabled, result.IsEnabled);
|
||||
Assert.Equal(request.IsLocked, result.IsLocked);
|
||||
Assert.Equal(request.CanDownloadMetadataFromWeb, result.CanDownloadMetadataFromWeb);
|
||||
Assert.Equal(request.ShouldSaveMetadataInMediaDirectories, result.ShouldSaveMetadataInMediaDirectories);
|
||||
Assert.Equal(request.ShouldSkipUnchangedDirectoriesDuringScan, result.ShouldSkipUnchangedDirectoriesDuringScan);
|
||||
}
|
||||
}
|
||||
+72
@@ -3,8 +3,10 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentL
|
||||
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.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
@@ -18,6 +20,7 @@ namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenConten
|
||||
public class BookMappingTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookEntityFixture _bookEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingCompleteBook_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -67,4 +70,73 @@ public class BookMappingTests
|
||||
Assert.Equal(book.CreatedOnUtc, result.CreatedOnUtc);
|
||||
Assert.Equal(book.UpdatedOnUtc.HasValue ? book.UpdatedOnUtc.Value : null, result.UpdatedOnUtc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadataToEntity_WhenApplyingCompleteBook_ShouldOverwriteTheMetadataFields()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookEntity entity = _bookEntityFixture.Create();
|
||||
BookEntity expectedEntity = book.ToRepositoryEntity();
|
||||
|
||||
// Act
|
||||
entity.ApplyMetadataToEntity(book);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(book.Metadata.Title, entity.Title);
|
||||
Assert.Equal(expectedEntity.OriginalTitle, entity.OriginalTitle);
|
||||
Assert.Equal(expectedEntity.Description, entity.Description);
|
||||
Assert.Equal(expectedEntity.OriginalReleaseDate, entity.OriginalReleaseDate);
|
||||
Assert.Equal(expectedEntity.OriginalReleaseYear, entity.OriginalReleaseYear);
|
||||
Assert.Equal(expectedEntity.ReReleaseDate, entity.ReReleaseDate);
|
||||
Assert.Equal(expectedEntity.ReReleaseYear, entity.ReReleaseYear);
|
||||
Assert.Equal(expectedEntity.ReleaseCountry, entity.ReleaseCountry);
|
||||
Assert.Equal(expectedEntity.ReleaseVersion, entity.ReleaseVersion);
|
||||
Assert.Equal(expectedEntity.LanguageCode, entity.LanguageCode);
|
||||
Assert.Equal(expectedEntity.LanguageName, entity.LanguageName);
|
||||
Assert.Equal(expectedEntity.LanguageNativeName, entity.LanguageNativeName);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageCode, entity.OriginalLanguageCode);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageName, entity.OriginalLanguageName);
|
||||
Assert.Equal(expectedEntity.OriginalLanguageNativeName, entity.OriginalLanguageNativeName);
|
||||
Assert.Equal(expectedEntity.Publisher, entity.Publisher);
|
||||
Assert.Equal(expectedEntity.PageCount, entity.PageCount);
|
||||
Assert.Equal(expectedEntity.Format, entity.Format);
|
||||
Assert.Equal(expectedEntity.Edition, entity.Edition);
|
||||
Assert.Equal(expectedEntity.VolumeNumber, entity.VolumeNumber);
|
||||
Assert.Equal(expectedEntity.ASIN, entity.ASIN);
|
||||
Assert.Equal(expectedEntity.GoodreadsId, entity.GoodreadsId);
|
||||
Assert.Equal(expectedEntity.LCCN, entity.LCCN);
|
||||
Assert.Equal(expectedEntity.OCLCNumber, entity.OCLCNumber);
|
||||
Assert.Equal(expectedEntity.OpenLibraryId, entity.OpenLibraryId);
|
||||
Assert.Equal(expectedEntity.LibraryThingId, entity.LibraryThingId);
|
||||
Assert.Equal(expectedEntity.GoogleBooksId, entity.GoogleBooksId);
|
||||
Assert.Equal(expectedEntity.BarnesAndNobleId, entity.BarnesAndNobleId);
|
||||
Assert.Equal(expectedEntity.AppleBooksId, entity.AppleBooksId);
|
||||
Assert.NotNull(entity.UpdatedOnUtc);
|
||||
Assert.NotNull(entity.UpdatedBy);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadataToEntity_WhenApplyingBook_ShouldPreserveIdentityAndCollectionColumns()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookEntity entity = _bookEntityFixture.Create();
|
||||
Guid entityId = entity.Id;
|
||||
Guid libraryId = entity.LibraryId;
|
||||
string path = entity.Path;
|
||||
int isbnsCount = entity.ISBNs.Count;
|
||||
int ratingsCount = entity.Ratings.Count;
|
||||
|
||||
// Act
|
||||
entity.ApplyMetadataToEntity(book);
|
||||
|
||||
// Assert
|
||||
// the identity and the collection columns are not part of the metadata application
|
||||
Assert.Equal(entityId, entity.Id);
|
||||
Assert.Equal(libraryId, entity.LibraryId);
|
||||
Assert.Equal(path, entity.Path);
|
||||
Assert.Equal(isbnsCount, entity.ISBNs.Count);
|
||||
Assert.Equal(ratingsCount, entity.Ratings.Count);
|
||||
}
|
||||
}
|
||||
+170
@@ -1,12 +1,15 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -66,4 +69,171 @@ public class BookMetadataDtoMappingTests
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.NotEqual("The Fellowship of the Ring", book.Metadata.Title);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // missing title
|
||||
[InlineData("")] // empty title
|
||||
[InlineData(" ")] // whitespace title
|
||||
public void ApplyMetadata_WhenTitleIsNullOrWhitespace_ShouldReturnTitleCannotBeEmptyError(string? title)
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(title: title, includeOptionalProperties: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.TitleCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenReleaseInfoIsNull_ShouldReturnReleaseInfoCannotBeNullError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(title: "A valid title", includeOptionalProperties: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.ReleaseInfoCannotBeNull, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenReleaseInfoIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
releaseInfo: new ReleaseInfoDto(new DateOnly(2000, 1, 1), 1999, null, null, null, null));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Metadata.OriginalReleaseDateAndYearMustMatch, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenTagsAreInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
tags: [new TagDto(" ")]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenLanguageIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
language: new LanguageInfoDto("", "English", "English"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenOriginalLanguageIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
originalLanguage: new LanguageInfoDto("", "English", "English"));
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenIsbnIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [new IsbnDto("not-an-isbn", IsbnFormat.Isbn13)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenRatingIsInvalid_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
ratings: [new BookRatingDto(-1m, 5m, null, null)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenOptionalCollectionsAreNull_ShouldApplyMetadataWithoutCollections()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
releaseInfo: new ReleaseInfoDto(new DateOnly(2000, 1, 1), 2000, null, null, null, null),
|
||||
includeOptionalProperties: false);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("A valid title", book.Metadata.Title);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenIsbnsAndRatingsAreValid_ShouldApplyMetadataWithTheCollections()
|
||||
{
|
||||
// Arrange
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [new IsbnDto("9780306406157", IsbnFormat.Isbn13)],
|
||||
ratings: [new BookRatingDto(4m, 5m, null, 10)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Single(book.ISBNs);
|
||||
Assert.Single(book.Ratings);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading.Queries.GetReadingAvailability;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books.Reading;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetReadingAvailabilityRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetReadingAvailabilityRequestMappingTests
|
||||
{
|
||||
private readonly GetReadingAvailabilityRequestFixture _getReadingAvailabilityRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetReadingAvailabilityRequest request = _getReadingAvailabilityRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
GetReadingAvailabilityQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.BookId, result.BookId);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryArtworkProviders;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetLibraryArtworkProvidersRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryArtworkProvidersRequestMappingTests
|
||||
{
|
||||
private readonly GetLibraryArtworkProvidersRequestFixture _getLibraryArtworkProvidersRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryArtworkProvidersRequest request = _getLibraryArtworkProvidersRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
GetLibraryArtworkProvidersQuery result = request.ToQuery();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.LibraryId, result.LibraryId);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryArtworkProviders;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ReorderLibraryArtworkProvidersRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReorderLibraryArtworkProvidersRequestMappingTests
|
||||
{
|
||||
private readonly ReorderLibraryArtworkProvidersRequestFixture _reorderLibraryArtworkProvidersRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ReorderLibraryArtworkProvidersRequest request = _reorderLibraryArtworkProvidersRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
ReorderLibraryArtworkProvidersCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.LibraryId, result.LibraryId);
|
||||
Assert.Equal(request.PluginIds, result.PluginIds);
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryArtworkProviderEnabled;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SetLibraryArtworkProviderEnabledRequestMapping"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetLibraryArtworkProviderEnabledRequestMappingTests
|
||||
{
|
||||
private readonly SetLibraryArtworkProviderEnabledRequestFixture _setLibraryArtworkProviderEnabledRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
SetLibraryArtworkProviderEnabledRequest request = _setLibraryArtworkProviderEnabledRequestFixture.Create(isEnabled: true);
|
||||
|
||||
// Act
|
||||
SetLibraryArtworkProviderEnabledCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(request.LibraryId, result.LibraryId);
|
||||
Assert.Equal(request.PluginId, result.PluginId);
|
||||
Assert.Equal(request.IsEnabled, result.IsEnabled);
|
||||
}
|
||||
}
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Telemetry;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Telemetry;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="HandlerOutcomeDetector"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class HandlerOutcomeDetectorTests
|
||||
{
|
||||
[Fact]
|
||||
public void IsSuccessful_WhenResultIsNull_ShouldReturnTrue()
|
||||
{
|
||||
// Act
|
||||
bool result = HandlerOutcomeDetector.IsSuccessful(null);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSuccessful_WhenResultExposesNoSuccessFlag_ShouldReturnTrue()
|
||||
{
|
||||
// Act
|
||||
bool result = HandlerOutcomeDetector.IsSuccessful("a plain dto");
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSuccessful_WhenResultIsSuccessful_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Result<string> resultValue = Result<string>.Success("value");
|
||||
|
||||
// Act
|
||||
bool result = HandlerOutcomeDetector.IsSuccessful(resultValue);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IsSuccessful_WhenResultIsFailed_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
Result<string> resultValue = Result<string>.Failure(Error.Validation("Test.Code", "Test description"));
|
||||
|
||||
// Act
|
||||
bool result = HandlerOutcomeDetector.IsSuccessful(resultValue);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetErrorDescription_WhenResultIsNull_ShouldReturnNull()
|
||||
{
|
||||
// Act
|
||||
string? result = HandlerOutcomeDetector.GetErrorDescription(null);
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetErrorDescription_WhenResultExposesNoFirstError_ShouldReturnNull()
|
||||
{
|
||||
// Act
|
||||
string? result = HandlerOutcomeDetector.GetErrorDescription("a plain dto");
|
||||
|
||||
// Assert
|
||||
Assert.Null(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetErrorDescription_WhenResultIsFailed_ShouldReturnFirstErrorDescription()
|
||||
{
|
||||
// Arrange
|
||||
Result<string> resultValue = Result<string>.Failure(Error.Validation("Test.Code", "Test description"));
|
||||
|
||||
// Act
|
||||
string? result = HandlerOutcomeDetector.GetErrorDescription(resultValue);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Test description", result);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.CQRS;
|
||||
using Lumina.Application.Common.Telemetry;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.UnitTests.Common.Telemetry;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TelemetryDecoratorFactory"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TelemetryDecoratorFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void GetDecoratorType_WhenContractIsQueryHandler_ShouldReturnQueryDecoratorType()
|
||||
{
|
||||
// Arrange
|
||||
Type contract = typeof(IQueryHandler<GetRolePermissionsQuery, Result<RolePermissionsResponse>>);
|
||||
|
||||
// Act
|
||||
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(typeof(TelemetryQueryHandlerDecorator<GetRolePermissionsQuery, Result<RolePermissionsResponse>>), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDecoratorType_WhenContractIsCommandHandler_ShouldReturnCommandDecoratorType()
|
||||
{
|
||||
// Arrange
|
||||
Type contract = typeof(ICommandHandler<AddRoleCommand, Result<RolePermissionsResponse>>);
|
||||
|
||||
// Act
|
||||
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(typeof(TelemetryCommandHandlerDecorator<AddRoleCommand, Result<RolePermissionsResponse>>), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDecoratorType_WhenContractIsDomainEventHandler_ShouldReturnDomainEventHandlerDecoratorType()
|
||||
{
|
||||
// Arrange
|
||||
Type contract = typeof(IDomainEventHandler<LibrarySavedDomainEvent>);
|
||||
|
||||
// Act
|
||||
Type result = TelemetryDecoratorFactory.GetDecoratorType(contract);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(typeof(TelemetryDomainEventHandlerDecorator<LibrarySavedDomainEvent>), result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDecoratorType_WhenContractIsNotSupported_ShouldThrowArgumentException()
|
||||
{
|
||||
// Arrange
|
||||
Type contract = typeof(IEnumerable<int>);
|
||||
|
||||
// Act & Assert
|
||||
ArgumentException exception = Assert.Throws<ArgumentException>(() => TelemetryDecoratorFactory.GetDecoratorType(contract));
|
||||
Assert.Contains("No telemetry decorator is defined", exception.Message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user