Adds the should aggregate artwork when missing setting to the user settings, configuration, and validation

This commit is contained in:
BinaryAlley committed 2026-10-10 13:05:00 +03:00
1 parent 6b5e731546
commit e139a7bb00
21 files changed
+97 -43

No files matched your search

@@ -22,17 +22,20 @@ public class MediaSettingsDtoFixture
/// <param name="rootDirectory">Optional. The root directory where media files are stored.</param>
/// <param name="librariesDirectory">Optional. The directory where media library files are stored.</param>
/// <param name="booksDirectory">Optional. The directory where the media item files are stored.</param>
/// <param name="musicDirectory">Optional. The directory where the music library item files are stored.</param>
/// <returns>The created <see cref="MediaSettingsDto"/>.</returns>
public MediaSettingsDto Create(
string? rootDirectory = null,
string? librariesDirectory = null,
string? booksDirectory = null)
string? booksDirectory = null,
string? musicDirectory = null)
{
return new MediaSettingsDto
{
RootDirectory = rootDirectory ?? _faker.System.DirectoryPath(),
LibrariesDirectory = librariesDirectory ?? _faker.System.DirectoryPath(),
BooksDirectory = booksDirectory ?? _faker.System.DirectoryPath()
BooksDirectory = booksDirectory ?? _faker.System.DirectoryPath(),
MusicDirectory = musicDirectory ?? _faker.System.DirectoryPath()
};
}
@@ -22,6 +22,7 @@ public class UpdateUserSettingsCommandFixture
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the "The" prefix is ignored by the alpha picker, or not.</param>
/// <param name="isThemeCachingEnabled">Optional. Whether the theme data served to this user is cached, or not.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Optional. Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing.</param>
/// <param name="shouldAggregateArtworkWhenMissing">Optional. Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
/// <param name="shouldRenderPdfAsImages">Optional. Whether PDF books are rendered as page images for the user.</param>
/// <param name="shouldPreserveBookStyles">Optional. Whether the styles of the book content are preserved when it is rendered for the user.</param>
/// <returns>The created command.</returns>
@@ -31,16 +32,18 @@ public class UpdateUserSettingsCommandFixture
bool? shouldIgnoreThePrefixForAlphaPicker = null,
bool? isThemeCachingEnabled = null,
bool? shouldAggregateMetadataWhenMissing = null,
bool? shouldAggregateArtworkWhenMissing = null,
bool? shouldRenderPdfAsImages = null,
bool? shouldPreserveBookStyles = null)
{
return new Faker<UpdateUserSettingsCommand>()
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default, default, default, default))
.CustomInstantiator(f => new UpdateUserSettingsCommand(default, default, default, default, default, default, default, default))
.RuleFor(x => x.IsPaginationEnabled, f => isPaginationEnabled ?? f.Random.Bool())
.RuleFor(x => x.ItemsPerPage, f => itemsPerPage ?? f.Random.Int(1, 100))
.RuleFor(x => x.ShouldIgnoreThePrefixForAlphaPicker, f => shouldIgnoreThePrefixForAlphaPicker ?? f.Random.Bool())
.RuleFor(x => x.IsThemeCachingEnabled, f => isThemeCachingEnabled ?? f.Random.Bool())
.RuleFor(x => x.ShouldAggregateMetadataWhenMissing, f => shouldAggregateMetadataWhenMissing ?? f.Random.Bool())
.RuleFor(x => x.ShouldAggregateArtworkWhenMissing, f => shouldAggregateArtworkWhenMissing ?? f.Random.Bool())
.RuleFor(x => x.ShouldRenderPdfAsImages, f => shouldRenderPdfAsImages ?? f.Random.Bool())
.RuleFor(x => x.ShouldPreserveBookStyles, f => shouldPreserveBookStyles ?? f.Random.Bool())
.Generate();
@@ -24,6 +24,7 @@ public class UpdateUserSettingsRequestFixture
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix is ignored by the alpha picker.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing.</param>
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user.</param>
/// <returns>The created <see cref="UpdateUserSettingsRequest"/>.</returns>
@@ -33,6 +34,7 @@ public class UpdateUserSettingsRequestFixture
bool? shouldIgnoreThePrefixForAlphaPicker = null,
bool? isThemeCachingEnabled = null,
bool? shouldAggregateMetadataWhenMissing = null,
bool? shouldAggregateArtworkWhenMissing = null,
bool? shouldRenderPdfAsImages = null,
bool? shouldPreserveBookStyles = null)
{
@@ -42,6 +44,7 @@ public class UpdateUserSettingsRequestFixture
shouldIgnoreThePrefixForAlphaPicker ?? _faker.Random.Bool(),
isThemeCachingEnabled ?? _faker.Random.Bool(),
shouldAggregateMetadataWhenMissing ?? _faker.Random.Bool(),
shouldAggregateArtworkWhenMissing ?? _faker.Random.Bool(),
shouldRenderPdfAsImages ?? _faker.Random.Bool(),
shouldPreserveBookStyles ?? _faker.Random.Bool());
}
@@ -26,6 +26,7 @@ public class UserSettingsResponseFixture
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the "The" prefix is ignored by the alpha picker.</param>
/// <param name="isThemeCachingEnabled">Optional. Whether the theme data served to this user is cached.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Optional. Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing.</param>
/// <param name="shouldAggregateArtworkWhenMissing">Optional. Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
/// <param name="shouldRenderPdfAsImages">Optional. Whether PDF books are rendered as page images for the user.</param>
/// <param name="shouldPreserveBookStyles">Optional. Whether the styles of the book content are preserved when it is rendered for the user.</param>
/// <returns>The created <see cref="UserSettingsResponse"/>.</returns>
@@ -36,6 +37,7 @@ public class UserSettingsResponseFixture
bool? shouldIgnoreThePrefixForAlphaPicker = null,
bool? isThemeCachingEnabled = null,
bool? shouldAggregateMetadataWhenMissing = null,
bool? shouldAggregateArtworkWhenMissing = null,
bool? shouldRenderPdfAsImages = null,
bool? shouldPreserveBookStyles = null)
{
@@ -46,6 +48,7 @@ public class UserSettingsResponseFixture
shouldIgnoreThePrefixForAlphaPicker ?? _faker.Random.Bool(),
isThemeCachingEnabled ?? _faker.Random.Bool(),
shouldAggregateMetadataWhenMissing ?? _faker.Random.Bool(),
shouldAggregateArtworkWhenMissing ?? _faker.Random.Bool(),
shouldRenderPdfAsImages ?? _faker.Random.Bool(),
shouldPreserveBookStyles ?? _faker.Random.Bool());
}
@@ -25,6 +25,7 @@ public class UserSettingsFixture
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker.</param>
/// <param name="isThemeCachingEnabled">Whether the theme data served to this user is cached.</param>
/// <param name="shouldAggregateMetadataWhenMissing">Whether the metadata of the media library items is aggregated from multiple providers, when fields are missing.</param>
/// <param name="shouldAggregateArtworkWhenMissing">Whether the artwork of the media library items is aggregated from multiple providers, when it is missing.</param>
/// <param name="shouldRenderPdfAsImages">Whether PDF books are rendered as page images for the user.</param>
/// <param name="shouldPreserveBookStyles">Whether the styles of the book content are preserved when it is rendered for the user.</param>
/// <returns>The created <see cref="UserSettings"/>.</returns>
@@ -35,6 +36,7 @@ public class UserSettingsFixture
bool shouldIgnoreThePrefixForAlphaPicker = false,
bool isThemeCachingEnabled = true,
bool shouldAggregateMetadataWhenMissing = false,
bool shouldAggregateArtworkWhenMissing = false,
bool shouldRenderPdfAsImages = false,
bool shouldPreserveBookStyles = true)
{
@@ -45,6 +47,7 @@ public class UserSettingsFixture
shouldIgnoreThePrefixForAlphaPicker,
isThemeCachingEnabled,
shouldAggregateMetadataWhenMissing,
shouldAggregateArtworkWhenMissing,
shouldRenderPdfAsImages,
shouldPreserveBookStyles);
return settings.Value;
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.UsersManagement.Users;
[ExcludeFromCodeCoverage]
public class UpdateUserSettingsRequestMappingTests
{
private readonly UpdateUserSettingsRequestFixture _requestFixture = new();
private readonly UpdateUserSettingsRequestFixture _updateUserSettingsRequestFixture = new();
[Fact]
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
{
// Arrange
UpdateUserSettingsRequest request = _requestFixture.Create(
UpdateUserSettingsRequest request = _updateUserSettingsRequestFixture.Create(
isPaginationEnabled: true,
itemsPerPage: 48,
shouldIgnoreThePrefixForAlphaPicker: false,
@@ -80,7 +80,7 @@ public class UserSettingsTests
UserId userId = _userIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
// Assert
Assert.False(result.IsFailure);
@@ -117,7 +117,7 @@ public class UserSettingsTests
UserId userId = _userIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
// Assert
Assert.True(result.IsFailure);
@@ -132,7 +132,7 @@ public class UserSettingsTests
UserSettingsId id = _userSettingsIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: true);
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 24, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: true);
// Assert
Assert.False(result.IsFailure);
@@ -149,7 +149,7 @@ public class UserSettingsTests
UserSettingsId id = _userSettingsIdFixture.Create();
// Act
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 0, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
Result<UserSettings> result = UserSettings.Create(id, userId, isPaginationEnabled: true, itemsPerPage: 0, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
// Assert
Assert.True(result.IsFailure);
@@ -163,7 +163,7 @@ public class UserSettingsTests
UserSettings userSettings = _userSettingsFixture.Create();
// Act
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false, shouldAggregateMetadataWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, shouldIgnoreThePrefixForAlphaPicker: true, isThemeCachingEnabled: false, shouldAggregateMetadataWhenMissing: true, shouldAggregateArtworkWhenMissing: true, shouldRenderPdfAsImages: true, shouldPreserveBookStyles: true);
// Assert
Assert.False(result.IsFailure);
@@ -185,7 +185,7 @@ public class UserSettingsTests
UserSettings userSettings = _userSettingsFixture.Create();
// Act
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, shouldIgnoreThePrefixForAlphaPicker: false, isThemeCachingEnabled: true, shouldAggregateMetadataWhenMissing: false, shouldAggregateArtworkWhenMissing: false, shouldRenderPdfAsImages: false, shouldPreserveBookStyles: false);
// Assert
Assert.True(result.IsFailure);
@@ -21,6 +21,7 @@ namespace Lumina.Infrastructure.UnitTests.Common.Validation;
public class ValidationOptionsTests
{
private readonly IFixture _fixture;
private readonly ValidationOptionsFixture _validationOptionsFixture = new();
/// <summary>
/// Initializes a new instance of the <see cref="ValidationOptionsTests"/> class.
@@ -35,7 +36,7 @@ public class ValidationOptionsTests
{
// Arrange
string name = _fixture.Create<string>();
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
@@ -55,7 +56,7 @@ public class ValidationOptionsTests
// Arrange
string name = _fixture.Create<string>();
string differentName = _fixture.Create<string>();
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
ValidationOptions<ValidationOptionsFixture> sut = new(name, validator);
@@ -71,7 +72,7 @@ public class ValidationOptionsTests
public void Validate_WhenNullName_ShouldValidateOptions()
{
// Arrange
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<ValidationOptionsFixture> sut = new(null, validator);
@@ -105,7 +106,7 @@ public class ValidationOptionsTests
{
// Arrange
string name = _fixture.Create<string>();
ValidationOptionsFixture options = _fixture.Create<ValidationOptionsFixture>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
List<Error> validationFailures =
[
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Presentation.Web.Common.Primitives;
using Lumina.Presentation.Web.Common.Validation;
using Lumina.Presentation.Web.Fixtures.Common.Validation;
using Microsoft.Extensions.Options;
using NSubstitute;
using System;
@@ -17,15 +18,17 @@ namespace Lumina.Presentation.Web.UnitTests.Common.Validation;
[ExcludeFromCodeCoverage]
public class ValidationOptionsTests
{
private readonly ValidationOptionsFixture _validationOptionsFixture = new();
[Fact]
public void Validate_WhenMatchingName_ShouldValidateOptions()
{
// Arrange
string optionsName = "OptionsName";
TestOptions options = new();
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<TestOptions> sut = new(optionsName, validator);
ValidationOptions<ValidationOptionsFixture> sut = new(optionsName, validator);
// Act
ValidateOptionsResult result = sut.Validate(optionsName, options);
@@ -42,9 +45,9 @@ public class ValidationOptionsTests
// Arrange
string optionsName = "OptionsName";
string differentOptionsName = "DifferentOptionsName";
TestOptions options = new();
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptions<TestOptions> sut = new(optionsName, validator);
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
ValidationOptions<ValidationOptionsFixture> sut = new(optionsName, validator);
// Act
ValidateOptionsResult result = sut.Validate(differentOptionsName, options);
@@ -58,10 +61,10 @@ public class ValidationOptionsTests
public void Validate_WhenNullName_ShouldValidateOptions()
{
// Arrange
TestOptions options = new();
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
validator.Validate(options).Returns([]);
ValidationOptions<TestOptions> sut = new(null, validator);
ValidationOptions<ValidationOptionsFixture> sut = new(null, validator);
// Act
ValidateOptionsResult result = sut.Validate("AnyOptionsName", options);
@@ -77,15 +80,15 @@ public class ValidationOptionsTests
{
// Arrange
string optionsName = "OptionsName";
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptions<TestOptions> sut = new(optionsName, validator);
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
ValidationOptions<ValidationOptionsFixture> sut = new(optionsName, validator);
// Act
Action act = () => sut.Validate(optionsName, null!);
// Assert
Assert.Throws<ArgumentNullException>(act);
validator.DidNotReceive().Validate(Arg.Any<TestOptions>());
validator.DidNotReceive().Validate(Arg.Any<ValidationOptionsFixture>());
}
[Fact]
@@ -93,14 +96,14 @@ public class ValidationOptionsTests
{
// Arrange
string optionsName = "OptionsName";
TestOptions options = new();
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
List<Error> validationFailures =
[
Error.Validation("PropertyName", "Error Message")
];
validator.Validate(options).Returns(validationFailures);
ValidationOptions<TestOptions> sut = new(optionsName, validator);
ValidationOptions<ValidationOptionsFixture> sut = new(optionsName, validator);
// Act
ValidateOptionsResult result = sut.Validate(optionsName, options);
@@ -117,15 +120,15 @@ public class ValidationOptionsTests
{
// Arrange
string optionsName = "OptionsName";
TestOptions options = new();
IValidator<TestOptions> validator = Substitute.For<IValidator<TestOptions>>();
ValidationOptionsFixture options = _validationOptionsFixture.Create();
IValidator<ValidationOptionsFixture> validator = Substitute.For<IValidator<ValidationOptionsFixture>>();
List<Error> validationFailures =
[
Error.Validation("PropertyOne", "First Error Message"),
Error.Validation("PropertyTwo", "Second Error Message")
];
validator.Validate(options).Returns(validationFailures);
ValidationOptions<TestOptions> sut = new(optionsName, validator);
ValidationOptions<ValidationOptionsFixture> sut = new(optionsName, validator);
// Act
ValidateOptionsResult result = sut.Validate(optionsName, options);
@@ -137,12 +140,4 @@ public class ValidationOptionsTests
Assert.Contains("Options validation failed for 'PropertyOne' with error: 'First Error Message'", result.Failures);
Assert.Contains("Options validation failed for 'PropertyTwo' with error: 'Second Error Message'", result.Failures);
}
/// <summary>
/// Placeholder options type used to exercise the generic <see cref="ValidationOptions{TOptions}"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public sealed class TestOptions
{
}
}