Adds the Cover Art Archive music artwork plugin, its fixtures, and its unit and security test suites

This commit is contained in:
BinaryAlley committed 2026-10-03 11:47:00 +03:00
1 parent c8a8d8750b
commit fb05561619
36 files changed
+4029

No files matched your search

@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Plugins.CoverArtArchive.Common.Models.Contracts.Responses;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Plugins.CoverArtArchive.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="CoverArtArchiveArtworkResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
internal sealed class CoverArtArchiveArtworkResponseFixture
{
private readonly CoverArtArchiveImageResponseFixture _coverArtArchiveImageResponseFixture = new();
/// <summary>
/// Creates a new <see cref="CoverArtArchiveArtworkResponse"/> instance with randomized test data.
/// </summary>
/// <param name="images">Optional. The images of the artwork.</param>
/// <param name="includeImages">Whether the images should be included, or forced to <see langword="null"/>.</param>
/// <returns>A configured <see cref="CoverArtArchiveArtworkResponse"/> instance.</returns>
public CoverArtArchiveArtworkResponse Create(
List<CoverArtArchiveImageResponse?>? images = null,
bool includeImages = true)
{
return new CoverArtArchiveArtworkResponse
{
Images = includeImages ? images ?? [.. _coverArtArchiveImageResponseFixture.CreateMany()] : null
};
}
/// <summary>
/// Creates multiple <see cref="CoverArtArchiveArtworkResponse"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CoverArtArchiveArtworkResponse"/> instances.</returns>
public List<CoverArtArchiveArtworkResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.CoverArtArchive.Common.Models.Contracts.Responses;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Plugins.CoverArtArchive.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="CoverArtArchiveImageResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
internal sealed class CoverArtArchiveImageResponseFixture
{
private static readonly string[] s_knownTypes =
[
"Front", "Back", "Booklet", "Medium", "Tray", "Spine", "Obi", "Sticker", "Poster", "Liner", "Watermark", "Other"
];
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="CoverArtArchiveImageResponse"/> instance with randomized test data.
/// </summary>
/// <param name="image">Optional. The URL of the full size image.</param>
/// <param name="includeImage">Whether the image URL should be included, or forced to <see langword="null"/>.</param>
/// <param name="thumbnail">Optional. The URL of the thumbnail of the image.</param>
/// <param name="types">Optional. The types of the image.</param>
/// <param name="includeTypes">Whether the types should be included, or forced to <see langword="null"/>.</param>
/// <param name="isFront">Optional. Whether the image is the front cover.</param>
/// <param name="isBack">Optional. Whether the image is the back cover.</param>
/// <param name="comment">Optional. The comment describing the image.</param>
/// <returns>A configured <see cref="CoverArtArchiveImageResponse"/> instance.</returns>
public CoverArtArchiveImageResponse Create(
string? image = null,
bool includeImage = true,
string? thumbnail = null,
List<string?>? types = null,
bool includeTypes = true,
bool? isFront = null,
bool? isBack = null,
string? comment = null)
{
return new CoverArtArchiveImageResponse
{
Image = includeImage ? image ?? $"https://coverartarchive.org/release/{Guid.NewGuid():D}/{_faker.Random.Long(1, 999_999_999)}.jpg" : null,
Thumbnail = thumbnail ?? $"https://coverartarchive.org/release/{Guid.NewGuid():D}/thumb.jpg",
Types = includeTypes ? types ?? [_faker.PickRandom(s_knownTypes)] : null,
IsFront = isFront ?? _faker.Random.Bool(),
IsBack = isBack ?? _faker.Random.Bool(),
Comment = comment ?? _faker.Lorem.Sentence()
};
}
/// <summary>
/// Creates multiple <see cref="CoverArtArchiveImageResponse"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CoverArtArchiveImageResponse"/> instances.</returns>
public List<CoverArtArchiveImageResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.CoverArtArchive.Common.Models.DTO.Settings;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Plugins.CoverArtArchive.Fixtures.Common.Models.DTO.Settings;
/// <summary>
/// Fixture class for the <see cref="CoverArtArchiveSettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
internal sealed class CoverArtArchiveSettingsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="CoverArtArchiveSettingsDto"/> instance with randomized test data.
/// </summary>
/// <param name="userAgent">Optional. The user agent sent with every request.</param>
/// <param name="contactEmail">Optional. The contact email sent to the Cover Art Archive API.</param>
/// <param name="includeContactEmail">Whether the contact email should be included, or forced to <see langword="null"/>.</param>
/// <param name="minimumRequestInterval">Optional. The minimum interval between consecutive requests.</param>
/// <returns>A configured <see cref="CoverArtArchiveSettingsDto"/> instance.</returns>
public CoverArtArchiveSettingsDto Create(
string? userAgent = null,
string? contactEmail = null,
bool includeContactEmail = true,
TimeSpan? minimumRequestInterval = null)
{
return new CoverArtArchiveSettingsDto
{
UserAgent = userAgent ?? $"Lumina-CoverArtArchive/{_faker.Random.Int(1, 9)}.{_faker.Random.Int(0, 9)}",
ContactEmail = includeContactEmail ? contactEmail ?? _faker.Internet.Email() : null,
MinimumRequestInterval = minimumRequestInterval ?? TimeSpan.FromSeconds(_faker.Random.Double(0, 5))
};
}
/// <summary>
/// Creates multiple <see cref="CoverArtArchiveSettingsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CoverArtArchiveSettingsDto"/> instances.</returns>
public List<CoverArtArchiveSettingsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}