mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 08:11:10 +00:00
Adds the Cover Art Archive music artwork plugin, its fixtures, and its unit and security test suites
This commit is contained in:
1 parent
c8a8d8750b
commit
fb05561619
36 files changed
+4029
No files matched your search
+43
@@ -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())];
|
||||
}
|
||||
}
|
||||
+67
@@ -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())];
|
||||
}
|
||||
}
|
||||
+51
@@ -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())];
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>disable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>false</IsTestProject>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoFixture" />
|
||||
<PackageReference Include="AutoFixture.AutoNSubstitute" />
|
||||
<PackageReference Include="AutoFixture.Xunit2" />
|
||||
<PackageReference Include="Bogus" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\plugins\Lumina.Plugins.CoverArtArchive\Lumina.Plugins.CoverArtArchive.csproj" />
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Lumina.Plugins.CoverArtArchive.Fixtures")]
|
||||
[assembly: AssemblyProduct("Lumina.Plugins.CoverArtArchive.Fixtures")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("D4E2F7A1-8B3C-4D5E-A6F1-2B3C4D5E6F70")]
|
||||
|
||||
[assembly: InternalsVisibleTo("Lumina.Plugins.CoverArtArchive.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Lumina.Plugins.CoverArtArchive.SecurityTests")]
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
Reference in new issue
Block a user