Merge pull request #154 from BinaryAlley/refactor/improve-test-assertion-robustness

Hardens test assertions and adds missing test coverage.
This commit is contained in:
BinaryAlley authored and GitHub committed 2026-08-18 13:03:43 -07:00
commit 215325a027
509 files changed
+40614 -697

No files matched your search

@@ -0,0 +1,8 @@
using System.Runtime.CompilerServices;
// Test-enabling declaration for the Open Library plugin assembly.
// Mirrors the InternalsVisibleTo pattern present in every other testable source project,
// so that the internal Open Library types can be exercised by their unit tests.
[assembly: InternalsVisibleTo("Lumina.Plugins.OpenLibrary.UnitTests")]
[assembly: InternalsVisibleTo("Lumina.Plugins.OpenLibrary.Fixtures")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -55,15 +55,15 @@ public class LibraryScanFailedDomainEventHandler : IDomainEventHandler<LibrarySc
public async ValueTask HandleAsync(LibraryScanFailedDomainEvent domainEvent, CancellationToken cancellationToken)
{
// get the library scan from the repository
Result<LibraryScanEntity?> getLibraryScansResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(
Result<LibraryScanEntity?> getLibraryScanResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(
domainEvent.MediaLibraryScanCompositeId.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScansResult.IsFailure)
throw new EventualConsistencyException(getLibraryScansResult.FirstError, getLibraryScansResult.Errors);
if (getLibraryScansResult.Value is null)
if (getLibraryScanResult.IsFailure)
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
if (getLibraryScanResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository scan to a domain object
Result<LibraryScan> libraryScanDomainResult = getLibraryScansResult.Value.ToDomainEntity();
Result<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
if (libraryScanDomainResult.IsFailure)
throw new EventualConsistencyException(libraryScanDomainResult.FirstError, libraryScanDomainResult.Errors);
@@ -1,17 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DomainEvents;
using Lumina.Application.Common.Infrastructure.Authentication;
using Lumina.Application.Common.Mapping.MediaLibrary.Management;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Events;
using Lumina.Domain.Common.Exceptions;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System.Threading;
using System.Threading.Tasks;
#endregion
@@ -50,8 +48,10 @@ public class LibraryScanQueuedDomainEventHandler : IDomainEventHandler<LibrarySc
{
// get the library scan that was queued, from the repository
Result<LibraryScanEntity?> getLibraryScanResult = await _unitOfWork.LibraryScanRepository.GetByIdAsync(domainEvent.ScanId.Value, cancellationToken).ConfigureAwait(false);
if (getLibraryScanResult.IsFailure || getLibraryScanResult.Value is null)
if (getLibraryScanResult.IsFailure)
throw new EventualConsistencyException(getLibraryScanResult.FirstError, getLibraryScanResult.Errors);
if (getLibraryScanResult.Value is null)
throw new EventualConsistencyException(Errors.LibraryScanning.LibraryScanNotFound);
// convert the repository entity to a domain entity
Result<LibraryScan> libraryScanDomainResult = getLibraryScanResult.Value.ToDomainEntity();
@@ -0,0 +1,19 @@
#region ========================================================================= USING =====================================================================================
using Dapper;
#endregion
namespace Lumina.DataAccess.Common.Dapper;
/// <summary>
/// Registers the Dapper type handlers used by the DataAccess layer.
/// </summary>
internal static class DapperTypeHandlers
{
/// <summary>
/// Registers all Dapper type handlers used by the DataAccess layer, and must run before any Dapper query executes.
/// </summary>
internal static void Register()
{
SqlMapper.AddTypeHandler(new SqliteGuidTypeHandler());
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Dapper;
using System;
using System.Data;
#endregion
namespace Lumina.DataAccess.Common.Dapper;
/// <summary>
/// Maps <see cref="Guid"/> values to and from the TEXT representation used by the SQLite provider.
/// </summary>
/// <remarks>
/// The SQLite provider stores <see cref="Guid"/> columns as TEXT, and Dapper falls back to Convert.ChangeType when materializing such
/// columns into <see cref="Guid"/> properties. <see cref="Guid"/> has no string <see cref="TypeConverter"/>, so that conversion throws
/// an <see cref="InvalidCastException"/>; this handler performs the conversion explicitly instead.
/// </remarks>
internal sealed class SqliteGuidTypeHandler : SqlMapper.TypeHandler<Guid>
{
/// <summary>
/// Sets the parameter value to the TEXT representation of the <see cref="Guid"/> value, keeping writes consistent with reads.
/// </summary>
/// <param name="parameter">The database parameter to set.</param>
/// <param name="value">The <see cref="Guid"/> value to store.</param>
public override void SetValue(IDbDataParameter parameter, Guid value)
{
parameter.Value = value.ToString();
}
/// <summary>
/// Parses the raw TEXT value read from the storage medium into a <see cref="Guid"/>.
/// </summary>
/// <param name="value">The raw value read from the storage medium.</param>
/// <returns>The parsed <see cref="Guid"/>.</returns>
public override Guid Parse(object value)
{
return value is Guid guid ? guid : Guid.Parse((string)value);
}
}
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Seed;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.DataAccess.Common.Dapper;
using Lumina.DataAccess.Common.Interceptors;
using Lumina.DataAccess.Core.Seed;
using Lumina.DataAccess.Core.UoW;
@@ -27,6 +28,9 @@ public static class DataAccessLayerServices
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static void AddDataAccessLayerServices(this IServiceCollection services)
{
// Type handlers are global static state, not DI services, and must be registered before any Dapper query executes;
// the composition root runs at startup, before any query, so this is the correct place for the application.
DapperTypeHandlers.Register();
string? basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if (!Directory.Exists(basePath))
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
+105
View File
@@ -232,6 +232,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Web.Int
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Presentation.Web.SecurityTests", "..\tests\SecurityTests\Lumina.Presentation.Web.SecurityTests\Lumina.Presentation.Web.SecurityTests.csproj", "{3FE25467-CBC6-438F-BB96-6601AF56E937}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Contracts.UnitTests", "..\tests\UnitTests\Lumina.Contracts.UnitTests\Lumina.Contracts.UnitTests.csproj", "{8336763E-26CE-4598-8438-26C7FFD60A2E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Domain.SharedKernel.UnitTests", "..\tests\UnitTests\Lumina.Domain.SharedKernel.UnitTests\Lumina.Domain.SharedKernel.UnitTests.csproj", "{B03AA3FE-4716-482C-8880-7BF3D9682A9F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.Contracts.UnitTests", "..\tests\UnitTests\Lumina.Plugins.Contracts.UnitTests\Lumina.Plugins.Contracts.UnitTests.csproj", "{09F90296-A229-4CA2-8635-15B5893FE2EA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.Contracts.Fixtures", "..\tests\Common\Lumina.Plugins.Contracts.Fixtures\Lumina.Plugins.Contracts.Fixtures.csproj", "{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.OpenLibrary.UnitTests", "..\tests\UnitTests\Lumina.Plugins.OpenLibrary.UnitTests\Lumina.Plugins.OpenLibrary.UnitTests.csproj", "{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.OpenLibrary.Fixtures", "..\tests\Common\Lumina.Plugins.OpenLibrary.Fixtures\Lumina.Plugins.OpenLibrary.Fixtures.csproj", "{16F65859-93AB-499F-A0BE-9EC05E20435F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.TestPlugin", "..\tests\Common\Lumina.TestPlugin\Lumina.TestPlugin.csproj", "{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -574,6 +588,90 @@ Global
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x64.Build.0 = Release|Any CPU
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x86.ActiveCfg = Release|Any CPU
{3FE25467-CBC6-438F-BB96-6601AF56E937}.Release|x86.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x64.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x64.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x86.ActiveCfg = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Debug|x86.Build.0 = Debug|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|Any CPU.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x64.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x64.Build.0 = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x86.ActiveCfg = Release|Any CPU
{8336763E-26CE-4598-8438-26C7FFD60A2E}.Release|x86.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x64.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x64.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x86.ActiveCfg = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Debug|x86.Build.0 = Debug|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|Any CPU.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x64.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x64.Build.0 = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x86.ActiveCfg = Release|Any CPU
{B03AA3FE-4716-482C-8880-7BF3D9682A9F}.Release|x86.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x64.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x64.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x86.ActiveCfg = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Debug|x86.Build.0 = Debug|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|Any CPU.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x64.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x64.Build.0 = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x86.ActiveCfg = Release|Any CPU
{09F90296-A229-4CA2-8635-15B5893FE2EA}.Release|x86.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x64.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x64.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Debug|x86.Build.0 = Debug|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|Any CPU.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x64.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x64.Build.0 = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x86.ActiveCfg = Release|Any CPU
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB}.Release|x86.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x64.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x64.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x86.ActiveCfg = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Debug|x86.Build.0 = Debug|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|Any CPU.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x64.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x64.Build.0 = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x86.ActiveCfg = Release|Any CPU
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A}.Release|x86.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x64.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x64.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x86.ActiveCfg = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Debug|x86.Build.0 = Debug|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|Any CPU.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x64.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x64.Build.0 = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x86.ActiveCfg = Release|Any CPU
{16F65859-93AB-499F-A0BE-9EC05E20435F}.Release|x86.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x64.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x64.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x86.ActiveCfg = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Debug|x86.Build.0 = Debug|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|Any CPU.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x64.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x64.Build.0 = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x86.ActiveCfg = Release|Any CPU
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -631,6 +729,13 @@ Global
{697F6057-DBDC-40B9-A7E5-02F295BC18B3} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{4BE18EDC-02ED-47E2-A23A-3F6650ADAF0A} = {3F057926-562F-4EF4-BFC0-EE62372D4551}
{3FE25467-CBC6-438F-BB96-6601AF56E937} = {8B06B1D2-80B9-490C-9A36-C7748F58B705}
{8336763E-26CE-4598-8438-26C7FFD60A2E} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{B03AA3FE-4716-482C-8880-7BF3D9682A9F} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{09F90296-A229-4CA2-8635-15B5893FE2EA} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{C4C9EA32-AF10-4D03-9907-8EA9EA06EBFB} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{FEC00EBD-6A64-4280-B0F7-1EC5321C294A} = {53B1231B-37F5-44BA-80D5-DBA979775F5C}
{16F65859-93AB-499F-A0BE-9EC05E20435F} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{65AA7896-2DE2-4F07-A1B2-C1E1774521C2} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A55A28E-C657-4A0B-95EA-2931AE66004E}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for generating <see cref="DirectoryScanFingerprintEntity"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class DirectoryScanFingerprintEntityFixture
{
/// <summary>
/// Creates a new <see cref="DirectoryScanFingerprintEntity"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional. The Id of the directory scan fingerprint.</param>
/// <param name="libraryId">Optional. The Id of the media library to which the fingerprint belongs.</param>
/// <param name="path">Optional path of the directory to which the fingerprint belongs.</param>
/// <param name="lastWriteTimeUtc">Optional last write time of the directory, in UTC.</param>
/// <returns>A configured <see cref="DirectoryScanFingerprintEntity"/> instance.</returns>
public DirectoryScanFingerprintEntity Create(
Guid? id = null,
Guid? libraryId = null,
string? path = null,
DateTime? lastWriteTimeUtc = null)
{
return new Faker<DirectoryScanFingerprintEntity>()
.CustomInstantiator(faker => new DirectoryScanFingerprintEntity
{
Id = id ?? Guid.NewGuid(),
LibraryId = libraryId ?? Guid.NewGuid(),
Path = path ?? faker.System.DirectoryPath(),
LastWriteTimeUtc = lastWriteTimeUtc ?? faker.Date.Recent()
})
.Generate();
}
/// <summary>
/// Creates multiple <see cref="DirectoryScanFingerprintEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="DirectoryScanFingerprintEntity"/> instances.</returns>
public List<DirectoryScanFingerprintEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,89 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library.</param>
/// <param name="userId">Optional. The Id of the user that owns the media library.</param>
/// <param name="title">Optional. The title of the media library.</param>
/// <param name="libraryType">Optional. The type of the media library.</param>
/// <param name="contentLocations">Optional. The content locations of the media library.</param>
/// <param name="coverImage">Optional. The cover image path of the media library.</param>
/// <param name="isEnabled">Whether the media library is enabled or not.</param>
/// <param name="isLocked">Whether the media library is locked or not.</param>
/// <param name="downloadMetadataFromWeb">Whether the media library should download metadata from the web or not.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Whether the metadata should be saved in the media directories or not.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during a scan or not.</param>
/// <returns>The created media library entity.</returns>
public LibraryEntity Create(
Guid? id = null,
Guid? userId = null,
string? title = null,
LibraryType? libraryType = null,
IEnumerable<string>? contentLocations = null,
string? coverImage = null,
bool isEnabled = true,
bool isLocked = false,
bool downloadMetadataFromWeb = true,
bool shouldSaveMetadataInMediaDirectories = true,
bool shouldSkipUnchangedDirectoriesDuringScan = false)
{
return new Faker<LibraryEntity>()
.CustomInstantiator(f => new LibraryEntity
{
Id = id ?? Guid.NewGuid(),
UserId = userId ?? Guid.NewGuid(),
Title = default!,
CoverImage = default,
LibraryType = default,
ContentLocations = [],
LibraryScans = [],
IsEnabled = isEnabled,
IsLocked = isLocked,
DownloadMetadataFromWeb = downloadMetadataFromWeb,
ShouldSaveMetadataInMediaDirectories = shouldSaveMetadataInMediaDirectories,
ShouldSkipUnchangedDirectoriesDuringScan = shouldSkipUnchangedDirectoriesDuringScan,
CreatedOnUtc = default,
CreatedBy = default,
UpdatedOnUtc = null,
UpdatedBy = null
})
.RuleFor(library => library.Title, f => title ?? f.Lorem.Word())
.RuleFor(library => library.LibraryType, f => libraryType ?? f.PickRandom<LibraryType>())
.RuleFor(library => library.CoverImage, f => coverImage ?? f.System.FilePath())
.RuleFor(library => library.ContentLocations, f =>
{
IEnumerable<string> paths = contentLocations ?? [f.System.DirectoryPath(), f.System.DirectoryPath()];
return [.. paths.Select(path => new LibraryContentLocationEntity() { Path = path })];
})
.RuleFor(library => library.CreatedOnUtc, f => f.Date.Past())
.RuleFor(library => library.CreatedBy, f => f.Random.Guid())
.Generate();
}
/// <summary>
/// Creates a list of <see cref="LibraryEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryEntity"/> instances.</returns>
public List<LibraryEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,70 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryScanEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryScanEntityFixture
{
private readonly LibraryEntityFixture _libraryEntityFixture = new();
/// <summary>
/// Creates a random valid <see cref="LibraryScanEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library scan.</param>
/// <param name="libraryId">Optional. The Id of the media library that is scanned.</param>
/// <param name="userId">Optional. The Id of the user that initiated the media library scan.</param>
/// <param name="status">The status of the media library scan.</param>
/// <param name="libraryEntity">Optional. The media library that is scanned.</param>
/// <param name="createdOnUtc">Optional. The time and date when the entity was added.</param>
/// <returns>The created media library scan entity.</returns>
public LibraryScanEntity Create(
Guid? id = null,
Guid? libraryId = null,
Guid? userId = null,
LibraryScanJobStatus? status = null,
LibraryEntity? libraryEntity = null,
DateTime? createdOnUtc = null)
{
Guid resolvedLibraryId = libraryId ?? Guid.NewGuid();
Guid resolvedUserId = userId ?? Guid.NewGuid();
LibraryEntity resolvedLibrary = libraryEntity ?? _libraryEntityFixture.Create(id: resolvedLibraryId, userId: resolvedUserId);
return new Faker<LibraryScanEntity>()
.CustomInstantiator(f => new LibraryScanEntity
{
Id = id ?? Guid.NewGuid(),
LibraryId = resolvedLibraryId,
UserId = resolvedUserId,
Status = status ?? LibraryScanJobStatus.Running,
Library = resolvedLibrary,
User = null!,
LibraryScanResults = [],
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
CreatedBy = resolvedUserId,
UpdatedOnUtc = null,
UpdatedBy = null
})
.Generate();
}
/// <summary>
/// Creates a list of <see cref="LibraryScanEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryScanEntity"/> instances.</returns>
public List<LibraryScanEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for generating <see cref="LibraryScanResultEntity"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryScanResultEntityFixture
{
/// <summary>
/// Creates a new <see cref="LibraryScanResultEntity"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional. The Id of the media library scan result.</param>
/// <param name="libraryScanId">Optional. The Id of the media library scan that this result belongs to.</param>
/// <param name="status">Optional status of the media library scan file.</param>
/// <param name="path">Optional path of the media library scan file.</param>
/// <param name="contentHash">Optional hash calculated for the media library scan file.</param>
/// <param name="fileSize">Optional size of the media library scan file.</param>
/// <param name="ticks">Optional last write time of the media library scan file, stored in ticks.</param>
/// <returns>A configured <see cref="LibraryScanResultEntity"/> instance.</returns>
public LibraryScanResultEntity Create(
Guid? id = null,
Guid? libraryScanId = null,
LibraryScanFileStatus? status = null,
string? path = null,
ulong? contentHash = null,
long? fileSize = null,
long? ticks = null)
{
return new Faker<LibraryScanResultEntity>()
.CustomInstantiator(faker => new LibraryScanResultEntity
{
Id = id ?? Guid.NewGuid(),
LibraryScanId = libraryScanId ?? Guid.NewGuid(),
Status = status ?? faker.PickRandom<LibraryScanFileStatus>(),
Path = path ?? faker.System.FilePath(),
ContentHash = contentHash ?? faker.Random.ULong(),
FileSize = fileSize ?? faker.Random.Long(1, long.MaxValue),
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
LibraryScan = null!
})
.Generate();
}
/// <summary>
/// Creates multiple <see cref="LibraryScanResultEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryScanResultEntity"/> instances.</returns>
public List<LibraryScanResultEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for generating <see cref="LibraryScanSnapshotEntity"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryScanSnapshotEntityFixture
{
/// <summary>
/// Creates a new <see cref="LibraryScanSnapshotEntity"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional. The Id of the media library scan snapshot item.</param>
/// <param name="libraryId">Optional. The Id of the media library to which the snapshot item belongs.</param>
/// <param name="path">Optional path of the media library scan snapshot item.</param>
/// <param name="contentHash">Optional hash calculated for the media library scan snapshot item.</param>
/// <param name="fileSize">Optional size of the media library scan snapshot item.</param>
/// <param name="ticks">Optional last write time of the media library scan snapshot item, stored in ticks.</param>
/// <returns>A configured <see cref="LibraryScanSnapshotEntity"/> instance.</returns>
public LibraryScanSnapshotEntity Create(
Guid? id = null,
Guid? libraryId = null,
string? path = null,
ulong? contentHash = null,
long? fileSize = null,
long? ticks = null)
{
return new Faker<LibraryScanSnapshotEntity>()
.CustomInstantiator(faker => new LibraryScanSnapshotEntity
{
Id = id ?? Guid.NewGuid(),
LibraryId = libraryId ?? Guid.NewGuid(),
Path = path ?? faker.System.FilePath(),
ContentHash = contentHash ?? faker.Random.ULong(),
FileSize = fileSize ?? faker.Random.Long(1, long.MaxValue),
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
Library = null!,
CreatedOnUtc = faker.Date.Past(),
CreatedBy = Guid.NewGuid(),
UpdatedOnUtc = faker.Random.Bool() ? faker.Date.Recent() : null,
UpdatedBy = faker.Random.Bool() ? Guid.NewGuid() : null
})
.Generate();
}
/// <summary>
/// Creates multiple <see cref="LibraryScanSnapshotEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryScanSnapshotEntity"/> instances.</returns>
public List<LibraryScanSnapshotEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
/// <summary>
/// Fixture class for generating <see cref="LibraryScanStagingResultsEntity"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryScanStagingResultsEntityFixture
{
/// <summary>
/// Creates a new <see cref="LibraryScanStagingResultsEntity"/> instance with randomized test data.
/// </summary>
/// <param name="id">Optional. The Id of the media library scan staging result.</param>
/// <param name="libraryScanId">Optional. The Id of the media library scan that this staging result belongs to.</param>
/// <param name="path">Optional path of the media library scan staging result.</param>
/// <param name="size">Optional size of the media library scan staging result.</param>
/// <param name="ticks">Optional last write time of the file system item, stored in ticks.</param>
/// <param name="contentHash">Optional hash calculated for the media library scan staging result.</param>
/// <param name="previousContentHash">Optional hash stored in the media library scan snapshot of a previous scan.</param>
/// <param name="needsRehash">Optional value indicating whether the file system item needs its content hashed.</param>
/// <param name="isNew">Optional value indicating whether the file system item is new.</param>
/// <returns>A configured <see cref="LibraryScanStagingResultsEntity"/> instance.</returns>
public LibraryScanStagingResultsEntity Create(
Guid? id = null,
Guid? libraryScanId = null,
string? path = null,
long? size = null,
long? ticks = null,
ulong? contentHash = null,
ulong? previousContentHash = null,
bool? needsRehash = null,
bool? isNew = null)
{
return new Faker<LibraryScanStagingResultsEntity>()
.CustomInstantiator(faker => new LibraryScanStagingResultsEntity
{
Id = id ?? Guid.NewGuid(),
LibraryScanId = libraryScanId ?? Guid.NewGuid(),
Path = path ?? faker.System.FilePath(),
Size = size ?? faker.Random.Long(1, long.MaxValue),
Ticks = ticks ?? faker.Random.Long(0, long.MaxValue),
ContentHash = contentHash ?? faker.Random.ULong(),
PreviousContentHash = previousContentHash ?? faker.Random.ULong(),
NeedsRehash = needsRehash ?? faker.Random.Bool(),
IsNew = isNew ?? faker.Random.Bool()
})
.Generate();
}
/// <summary>
/// Creates multiple <see cref="LibraryScanStagingResultsEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryScanStagingResultsEntity"/> instances.</returns>
public List<LibraryScanStagingResultsEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -23,18 +23,28 @@ public class BookEntityFixture
/// <summary>
/// Creates a random valid <see cref="BookEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the book.</param>
/// <param name="libraryId">Optional. The Id of the media library that owns the book.</param>
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="originalTitle">Optional. The original title of the book.</param>
/// <returns>The created <see cref="BookEntity"/>.</returns>
public BookEntity Create()
public BookEntity Create(
Guid? id = null,
Guid? libraryId = null,
string? path = null,
string? title = null,
string? originalTitle = null)
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
return new Faker<BookEntity>()
.RuleFor(x => x.Id, f => f.Random.Guid())
.RuleFor(x => x.LibraryId, f => f.Random.Guid())
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
.RuleFor(x => x.LibraryId, f => libraryId ?? f.Random.Guid())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.Title, f => title ?? f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.OriginalTitle, f => originalTitle ?? f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
@@ -21,8 +21,10 @@ public class UserEntityFixture
/// Creates a random valid <see cref="UserEntity"/>.
/// </summary>
/// <param name="libraryCount">Number of libraries to generate. Default is 0.</param>
/// <param name="username">Optional username to pin, or <see langword="null"/> to generate a random one.</param>
/// <param name="password">Optional password to pin, or <see langword="null"/> to generate a random one.</param>
/// <returns>The created user entity.</returns>
public UserEntity Create(int libraryCount = 0)
public UserEntity Create(int libraryCount = 0, string? username = null, string? password = null)
{
Guid userId = Guid.NewGuid();
List<LibraryEntity> libraries = libraryCount > 0
@@ -42,8 +44,8 @@ public class UserEntityFixture
UserRole = null,
CreatedBy = userId
})
.RuleFor(x => x.Username, f => f.Internet.UserName())
.RuleFor(x => x.Password, f => Uri.EscapeDataString(f.Internet.Password()))
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
.RuleFor(x => x.Password, f => password ?? Uri.EscapeDataString(f.Internet.Password()))
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
.Generate();
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.MediaLibraryScanJobPayloads;
/// <summary>
/// Fixture class for the <see cref="HashedFileSystemFileDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class HashedFileSystemFileDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="HashedFileSystemFileDto"/>.
/// </summary>
/// <param name="path">Optional. The path of the file system file.</param>
/// <param name="size">Optional. The size of the file system file.</param>
/// <param name="currentHash">Optional. The current hash obtained by sampling the file system file contents.</param>
/// <param name="oldHash">Optional. The old hash of the file system file, stored at the previous scan.</param>
/// <param name="ticks">Optional. The time and date when the file system file was last modified, stored in ticks.</param>
/// <returns>The created <see cref="HashedFileSystemFileDto"/>.</returns>
public HashedFileSystemFileDto Create(
string? path = null,
long? size = null,
ulong? currentHash = null,
ulong? oldHash = null,
long? ticks = null)
{
return new HashedFileSystemFileDto
{
Path = path ?? _faker.System.FilePath(),
Size = size ?? _faker.Random.Long(1, 1_000_000),
CurrentHash = currentHash ?? _faker.Random.ULong(),
OldHash = oldHash ?? _faker.Random.ULong(),
Ticks = ticks ?? _faker.Date.Recent().Ticks
};
}
/// <summary>
/// Creates a list of <see cref="HashedFileSystemFileDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="HashedFileSystemFileDto"/> instances.</returns>
public List<HashedFileSystemFileDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,13 @@
#region ========================================================================= USING =====================================================================================
#endregion
namespace Lumina.Application.Fixtures.Common.Utilities;
/// <summary>
/// Enumeration used to exercise the <see cref="Lumina.Application.Common.Utilities.ValidatorUtilities.IsInEnum{TRequest, TEnum}(FluentValidation.IRuleBuilder{TRequest, TEnum})"/> extension method.
/// </summary>
public enum ValidatorUtilitiesTestEnum
{
First,
Second
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Fixtures.Common.Utilities;
/// <summary>
/// Request used to exercise the <see cref="Lumina.Application.Common.Utilities.ValidatorUtilities"/> extension methods.
/// </summary>
[ExcludeFromCodeCoverage]
public sealed record ValidatorUtilitiesTestRequest(
int IntValue,
int? NullableIntValue,
decimal DecimalValue,
decimal? NullableDecimalValue,
TimeSpan TimeSpanValue,
int IntValue2,
int? NullableIntValue2,
decimal? NullableDecimalValue2,
string? NotNullValue,
string? NotEmptyValue,
Guid NotEmptyGuidValue,
List<string>? NotEmptyCollectionValue,
ValidatorUtilitiesTestEnum EnumValue,
ValidatorUtilitiesTestEnum? NullableEnumValue,
string? MaxLengthValue,
string? MinLengthValue,
string? ExactLengthValue,
string? RangeLengthValue,
string? MatchValue,
string? SelectorMatchValue,
string PatternValue,
int InclusiveIntValue,
int? InclusiveNullableIntValue,
string? EqualValue,
string? EqualComparisonValue);
@@ -0,0 +1,121 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.Utilities;
/// <summary>
/// Fixture class for generating <see cref="ValidatorUtilitiesTestRequest"/> test data.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidatorUtilitiesTestRequestFixture
{
private const string ValidPattern = "^[a-z]{3}-\\d{3}$";
/// <summary>
/// Creates a new <see cref="ValidatorUtilitiesTestRequest"/> instance with randomized test data that satisfies all validation rules.
/// </summary>
/// <param name="intValue">Optional. The integer value that must be greater than 3.</param>
/// <param name="nullableIntValue">Optional. The nullable integer value that must be greater than 3.</param>
/// <param name="decimalValue">Optional. The decimal value that must be greater than 3.</param>
/// <param name="nullableDecimalValue">Optional. The nullable decimal value that must be greater than 3.</param>
/// <param name="timeSpanValue">Optional. The time span value that must be greater than 3 hours.</param>
/// <param name="intValue2">Optional. The integer value that must be greater than or equal to 5.</param>
/// <param name="nullableIntValue2">Optional. The nullable integer value that must be greater than or equal to 5.</param>
/// <param name="nullableDecimalValue2">Optional. The nullable decimal value that must be greater than or equal to 5.</param>
/// <param name="notNullValue">Optional. The value that must not be null.</param>
/// <param name="notEmptyValue">Optional. The value that must not be empty.</param>
/// <param name="notEmptyGuidValue">Optional. The Guid that must not be empty.</param>
/// <param name="notEmptyCollectionValue">Optional. The collection that must not be empty.</param>
/// <param name="enumValue">Optional. The enum value that must be defined.</param>
/// <param name="nullableEnumValue">Optional. The nullable enum value that must be defined.</param>
/// <param name="maxLengthValue">Optional. The value that must not exceed 5 characters.</param>
/// <param name="minLengthValue">Optional. The value that must be at least 3 characters.</param>
/// <param name="exactLengthValue">Optional. The value that must be exactly 3 characters.</param>
/// <param name="rangeLengthValue">Optional. The value that must be between 3 and 5 characters.</param>
/// <param name="matchValue">Optional. The value that must match the valid pattern.</param>
/// <param name="selectorMatchValue">Optional. The value that must match the pattern selected from the request.</param>
/// <param name="patternValue">Optional. The pattern the selector match value must match.</param>
/// <param name="inclusiveIntValue">Optional. The integer value that must be between 1 and 10.</param>
/// <param name="inclusiveNullableIntValue">Optional. The nullable integer value that must be between 1 and 10.</param>
/// <param name="equalValue">Optional. The value that must equal the comparison value.</param>
/// <param name="equalComparisonValue">Optional. The comparison value.</param>
/// <returns>A configured <see cref="ValidatorUtilitiesTestRequest"/> instance.</returns>
public ValidatorUtilitiesTestRequest Create(
int? intValue = null,
int? nullableIntValue = null,
decimal? decimalValue = null,
decimal? nullableDecimalValue = null,
TimeSpan? timeSpanValue = null,
int? intValue2 = null,
int? nullableIntValue2 = null,
decimal? nullableDecimalValue2 = null,
string? notNullValue = null,
string? notEmptyValue = null,
Guid? notEmptyGuidValue = null,
List<string>? notEmptyCollectionValue = null,
ValidatorUtilitiesTestEnum? enumValue = null,
ValidatorUtilitiesTestEnum? nullableEnumValue = null,
string? maxLengthValue = null,
string? minLengthValue = null,
string? exactLengthValue = null,
string? rangeLengthValue = null,
string? matchValue = null,
string? selectorMatchValue = null,
string? patternValue = null,
int? inclusiveIntValue = null,
int? inclusiveNullableIntValue = null,
string? equalValue = null,
string? equalComparisonValue = null)
{
string resolvedPattern = patternValue ?? ValidPattern;
return new Faker<ValidatorUtilitiesTestRequest>()
.CustomInstantiator(f => new ValidatorUtilitiesTestRequest(
IntValue: intValue ?? f.Random.Int(4, 100),
NullableIntValue: nullableIntValue ?? f.Random.Int(4, 100),
DecimalValue: decimalValue ?? f.Random.Decimal(4m, 100m),
NullableDecimalValue: nullableDecimalValue ?? f.Random.Decimal(4m, 100m),
TimeSpanValue: timeSpanValue ?? f.Date.BetweenTimeOnly(new TimeOnly(4, 0), new TimeOnly(23, 0)).ToTimeSpan(),
IntValue2: intValue2 ?? f.Random.Int(5, 100),
NullableIntValue2: nullableIntValue2 ?? f.Random.Int(5, 100),
NullableDecimalValue2: nullableDecimalValue2 ?? f.Random.Decimal(5m, 100m),
NotNullValue: notNullValue ?? f.Lorem.Word(),
NotEmptyValue: notEmptyValue ?? f.Lorem.Word(),
NotEmptyGuidValue: notEmptyGuidValue ?? f.Random.Guid(),
NotEmptyCollectionValue: notEmptyCollectionValue ?? [f.Lorem.Word()],
EnumValue: enumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>(),
NullableEnumValue: nullableEnumValue ?? f.PickRandom<ValidatorUtilitiesTestEnum>(),
MaxLengthValue: maxLengthValue ?? f.Random.String2(1, 5),
MinLengthValue: minLengthValue ?? f.Random.String2(3, 5),
ExactLengthValue: exactLengthValue ?? f.Random.String2(3, 3),
RangeLengthValue: rangeLengthValue ?? f.Random.String2(3, 5),
MatchValue: matchValue ?? GenerateMatchingValue(f),
SelectorMatchValue: selectorMatchValue ?? GenerateMatchingValue(f),
PatternValue: resolvedPattern,
InclusiveIntValue: inclusiveIntValue ?? f.Random.Int(1, 10),
InclusiveNullableIntValue: inclusiveNullableIntValue ?? f.Random.Int(1, 10),
EqualValue: equalValue ?? "same",
EqualComparisonValue: equalComparisonValue ?? "same"))
.Generate();
}
/// <summary>
/// Creates multiple <see cref="ValidatorUtilitiesTestRequest"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ValidatorUtilitiesTestRequest"/> instances.</returns>
public List<ValidatorUtilitiesTestRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
private static string GenerateMatchingValue(Faker f)
{
string letters = new(Enumerable.Range(0, 3).Select(_ => f.Random.Char('a', 'z')).ToArray());
return $"{letters}-{f.Random.Replace("###")}";
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Plugins.Queries.GetLibraryMetadataProviders;
/// <summary>
/// Fixture class for the <see cref="GetLibraryMetadataProvidersQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryMetadataProvidersQueryFixture
{
/// <summary>
/// Creates a random valid query to get the metadata providers of a media library.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose metadata providers are retrieved.</param>
/// <returns>The created query.</returns>
public GetLibraryMetadataProvidersQuery Create(Guid? libraryId = null)
{
return new Faker<GetLibraryMetadataProvidersQuery>()
.CustomInstantiator(f => new GetLibraryMetadataProvidersQuery(
libraryId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetLibraryMetadataProvidersQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryMetadataProvidersQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Plugins.Queries.GetPluginSettings;
/// <summary>
/// Fixture class for the <see cref="GetPluginSettingsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPluginSettingsQueryFixture
{
/// <summary>
/// Creates a random valid query to get the settings of a plugin.
/// </summary>
/// <param name="pluginId">Optional. The unique identifier of the plugin.</param>
/// <returns>The created query.</returns>
public GetPluginSettingsQuery Create(Guid? pluginId = null)
{
return new Faker<GetPluginSettingsQuery>()
.CustomInstantiator(f => new GetPluginSettingsQuery(
pluginId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetPluginSettingsQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPluginSettingsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Authentication;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.Authentication;
/// <summary>
/// Fixture class for the <see cref="PermissionDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PermissionDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PermissionDto"/>.
/// </summary>
/// <param name="id">Optional. The Id of the permission.</param>
/// <param name="permissionName">Optional. The name of the permission.</param>
/// <returns>The created <see cref="PermissionDto"/>.</returns>
public PermissionDto Create(
Guid? id = null,
AuthorizationPermission? permissionName = null)
{
return new PermissionDto(
id ?? Guid.NewGuid(),
permissionName ?? _faker.PickRandom<AuthorizationPermission>()
);
}
/// <summary>
/// Creates a list of <see cref="PermissionDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PermissionDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,44 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Authentication;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.Authentication;
/// <summary>
/// Fixture class for the <see cref="RoleDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RoleDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="RoleDto"/>.
/// </summary>
/// <param name="id">Optional. The unique identifier of the role.</param>
/// <param name="roleName">Optional. The name of the role.</param>
/// <returns>The created <see cref="RoleDto"/>.</returns>
public RoleDto Create(
Guid? id = null,
string? roleName = null)
{
return new RoleDto(
id ?? Guid.NewGuid(),
roleName ?? _faker.Lorem.Word());
}
/// <summary>
/// Creates a list of <see cref="RoleDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<RoleDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,86 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookMetadataDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookMetadataDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookMetadataDto"/>.
/// </summary>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="originalTitle">Optional. The original title of the book.</param>
/// <param name="description">Optional. A brief description or summary of the book.</param>
/// <param name="goodreadsId">Optional. The Goodreads ID of the book.</param>
/// <param name="format">Optional. The format of the book.</param>
/// <param name="publisher">Optional. The name of the publisher of the book.</param>
/// <param name="pageCount">Optional. The number of pages in the book.</param>
/// <param name="includeOptionalProperties">Whether optional properties should be included.</param>
/// <returns>The created <see cref="BookMetadataDto"/>.</returns>
public BookMetadataDto Create(
string? title = null,
string? originalTitle = null,
string? description = null,
string? goodreadsId = null,
BookFormat? format = null,
string? publisher = null,
int? pageCount = null,
bool includeOptionalProperties = true)
{
int releaseYear = _faker.Random.Int(1900, 2024);
return new BookMetadataDto(
title ?? _faker.Lorem.Sentence(3),
originalTitle,
description,
includeOptionalProperties
? new ReleaseInfoDto(new DateOnly(releaseYear, 1, 1), releaseYear, null, null, _faker.Address.CountryCode(), null)
: null,
includeOptionalProperties ? [new GenreDto(_faker.Lorem.Word())] : null,
includeOptionalProperties ? [new TagDto(_faker.Lorem.Word())] : null,
includeOptionalProperties ? new LanguageInfoDto("en", "English", "English") : null,
null,
publisher,
pageCount,
format ?? _faker.PickRandom<BookFormat>(),
null,
includeOptionalProperties ? _faker.Random.Int(1, 10) : null,
null,
null,
goodreadsId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
}
/// <summary>
/// Creates a list of <see cref="BookMetadataDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BookMetadataDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,59 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookMetadataLookupDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookMetadataLookupDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookMetadataLookupDto"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the book belongs to.</param>
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="isbn">Optional. The ISBN of the book.</param>
/// <param name="openLibraryId">Optional. The Open Library ID of the book.</param>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="author">Optional. The author of the book.</param>
/// <param name="languageCode">Optional. The language code of the book.</param>
/// <returns>The created <see cref="BookMetadataLookupDto"/>.</returns>
public BookMetadataLookupDto Create(
Guid? libraryId = null,
string? path = null,
string? isbn = null,
string? openLibraryId = null,
string? title = null,
string? author = null,
string? languageCode = null)
{
return new BookMetadataLookupDto(
libraryId ?? Guid.NewGuid(),
path ?? _faker.System.FilePath(),
isbn,
openLibraryId,
title,
author,
languageCode);
}
/// <summary>
/// Creates a list of <see cref="BookMetadataLookupDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BookMetadataLookupDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Authorization;
/// <summary>
/// Fixture class for the <see cref="UpdateRoleRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateRoleRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UpdateRoleRequest"/>.
/// </summary>
/// <param name="roleId">Optional. The Id of the role to update.</param>
/// <param name="roleName">Optional. The name of the role.</param>
/// <param name="permissions">Optional. The Ids of the permissions of the role.</param>
/// <returns>The created <see cref="UpdateRoleRequest"/>.</returns>
public UpdateRoleRequest Create(
Guid? roleId = null,
string? roleName = null,
List<Guid>? permissions = null)
{
return new UpdateRoleRequest(
roleId ?? Guid.NewGuid(),
roleName ?? _faker.Random.Word(),
permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
);
}
/// <summary>
/// Creates a list of <see cref="UpdateRoleRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdateRoleRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Authorization;
/// <summary>
/// Fixture class for the <see cref="UpdateUserRoleAndPermissionsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateUserRoleAndPermissionsRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UpdateUserRoleAndPermissionsRequest"/>.
/// </summary>
/// <param name="userId">Optional. The Id of the user whose role and permissions are updated.</param>
/// <param name="roleId">Optional. The Id of the role assigned to the user.</param>
/// <param name="permissions">Optional. The Ids of the permissions assigned to the user.</param>
/// <returns>The created <see cref="UpdateUserRoleAndPermissionsRequest"/>.</returns>
public UpdateUserRoleAndPermissionsRequest Create(
Guid? userId = null,
Guid? roleId = null,
List<Guid>? permissions = null)
{
return new UpdateUserRoleAndPermissionsRequest(
userId ?? Guid.NewGuid(),
roleId ?? Guid.NewGuid(),
permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
);
}
/// <summary>
/// Creates a list of <see cref="UpdateUserRoleAndPermissionsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdateUserRoleAndPermissionsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,66 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="AddLibraryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddLibraryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="AddLibraryRequest"/>.
/// </summary>
/// <param name="title">Optional. The title of the media library.</param>
/// <param name="libraryType">Optional. The type of the media library.</param>
/// <param name="contentLocations">Optional. The file system paths of the media library content directories.</param>
/// <param name="coverImage">Optional. The path of the image file used as the cover.</param>
/// <param name="isEnabled">Optional. Whether the media library is enabled.</param>
/// <param name="isLocked">Optional. Whether the media library is locked.</param>
/// <param name="downloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <returns>The created <see cref="AddLibraryRequest"/>.</returns>
public AddLibraryRequest Create(
string? title = null,
string? libraryType = null,
string[]? contentLocations = null,
string? coverImage = null,
bool? isEnabled = null,
bool? isLocked = null,
bool? downloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null)
{
return new AddLibraryRequest(
title ?? _faker.Commerce.Department(),
libraryType ?? "EBook",
contentLocations ?? [_faker.System.DirectoryPath()],
coverImage ?? null,
isEnabled ?? _faker.Random.Bool(),
isLocked ?? _faker.Random.Bool(),
downloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="AddLibraryRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<AddLibraryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="CancelLibraryScanRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class CancelLibraryScanRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="CancelLibraryScanRequest"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose scan is cancelled.</param>
/// <param name="scanId">Optional. The Id of the scan to cancel.</param>
/// <returns>The created <see cref="CancelLibraryScanRequest"/>.</returns>
public CancelLibraryScanRequest Create(
Guid? libraryId = null,
Guid? scanId = null)
{
return new CancelLibraryScanRequest(
libraryId ?? _faker.Random.Guid(),
scanId ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="CancelLibraryScanRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<CancelLibraryScanRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="DeleteLibraryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteLibraryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="DeleteLibraryRequest"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library to delete.</param>
/// <returns>The created <see cref="DeleteLibraryRequest"/>.</returns>
public DeleteLibraryRequest Create(Guid? id = null)
{
return new DeleteLibraryRequest(
id ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="DeleteLibraryRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<DeleteLibraryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="GetLibraryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetLibraryRequest"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library to retrieve.</param>
/// <returns>The created <see cref="GetLibraryRequest"/>.</returns>
public GetLibraryRequest Create(Guid? id = null)
{
return new GetLibraryRequest(
id ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="GetLibraryRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="GetLibraryScanProgressRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryScanProgressRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetLibraryScanProgressRequest"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose scan progress is requested.</param>
/// <param name="scanId">Optional. The Id of the media library scan whose progress is requested.</param>
/// <returns>The created <see cref="GetLibraryScanProgressRequest"/>.</returns>
public GetLibraryScanProgressRequest Create(
Guid? libraryId = null,
Guid? scanId = null)
{
return new GetLibraryScanProgressRequest(
libraryId ?? _faker.Random.Guid(),
scanId ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="GetLibraryScanProgressRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryScanProgressRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="ScanLibraryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ScanLibraryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ScanLibraryRequest"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library to scan.</param>
/// <returns>The created <see cref="ScanLibraryRequest"/>.</returns>
public ScanLibraryRequest Create(Guid? id = null)
{
return new ScanLibraryRequest(
id ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="ScanLibraryRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ScanLibraryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,72 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="UpdateLibraryRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateLibraryRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UpdateLibraryRequest"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library to update.</param>
/// <param name="userId">Optional. The Id of the user owning the media library.</param>
/// <param name="title">Optional. The title of the media library.</param>
/// <param name="libraryType">Optional. The type of the media library.</param>
/// <param name="contentLocations">Optional. The file system paths of the media library content directories.</param>
/// <param name="coverImage">Optional. The path of the image file used as the cover.</param>
/// <param name="isEnabled">Optional. Whether the media library is enabled.</param>
/// <param name="isLocked">Optional. Whether the media library is locked.</param>
/// <param name="downloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <returns>The created <see cref="UpdateLibraryRequest"/>.</returns>
public UpdateLibraryRequest Create(
Guid? id = null,
Guid? userId = null,
string? title = null,
string? libraryType = null,
string[]? contentLocations = null,
string? coverImage = null,
bool? isEnabled = null,
bool? isLocked = null,
bool? downloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null)
{
return new UpdateLibraryRequest(
id ?? _faker.Random.Guid(),
userId ?? _faker.Random.Guid(),
title ?? _faker.Commerce.Department(),
libraryType ?? "EBook",
contentLocations ?? [_faker.System.DirectoryPath()],
coverImage ?? null,
isEnabled ?? _faker.Random.Bool(),
isLocked ?? _faker.Random.Bool(),
downloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="UpdateLibraryRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdateLibraryRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="GetLibraryMetadataProvidersRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetLibraryMetadataProvidersRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetLibraryMetadataProvidersRequest"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose metadata providers are retrieved.</param>
/// <returns>The created <see cref="GetLibraryMetadataProvidersRequest"/>.</returns>
public GetLibraryMetadataProvidersRequest Create(Guid? libraryId = null)
{
return new GetLibraryMetadataProvidersRequest(
libraryId ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="GetLibraryMetadataProvidersRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetLibraryMetadataProvidersRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="GetPluginSettingsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPluginSettingsRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetPluginSettingsRequest"/>.
/// </summary>
/// <param name="pluginId">Optional. The Id of the plugin whose settings are retrieved.</param>
/// <returns>The created <see cref="GetPluginSettingsRequest"/>.</returns>
public GetPluginSettingsRequest Create(Guid? pluginId = null)
{
return new GetPluginSettingsRequest(
pluginId ?? _faker.Random.Guid()
);
}
/// <summary>
/// Creates a list of <see cref="GetPluginSettingsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPluginSettingsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="ReorderLibraryMetadataProvidersRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReorderLibraryMetadataProvidersRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ReorderLibraryMetadataProvidersRequest"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose metadata providers are reordered.</param>
/// <param name="pluginIds">Optional. The plugin Ids in the new order.</param>
/// <returns>The created <see cref="ReorderLibraryMetadataProvidersRequest"/>.</returns>
public ReorderLibraryMetadataProvidersRequest Create(
Guid? libraryId = null,
IReadOnlyList<Guid>? pluginIds = null)
{
return new ReorderLibraryMetadataProvidersRequest(
libraryId ?? _faker.Random.Guid(),
pluginIds ?? [Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()]
);
}
/// <summary>
/// Creates a list of <see cref="ReorderLibraryMetadataProvidersRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ReorderLibraryMetadataProvidersRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="SetLibraryMetadataProviderEnabledRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetLibraryMetadataProviderEnabledRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="SetLibraryMetadataProviderEnabledRequest"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library whose metadata provider is enabled or disabled.</param>
/// <param name="pluginId">Optional. The Id of the plugin providing the metadata.</param>
/// <param name="isEnabled">Optional. Whether the metadata provider should be enabled.</param>
/// <returns>The created <see cref="SetLibraryMetadataProviderEnabledRequest"/>.</returns>
public SetLibraryMetadataProviderEnabledRequest Create(
Guid? libraryId = null,
Guid? pluginId = null,
bool? isEnabled = null)
{
return new SetLibraryMetadataProviderEnabledRequest(
libraryId ?? _faker.Random.Guid(),
pluginId ?? _faker.Random.Guid(),
isEnabled ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="SetLibraryMetadataProviderEnabledRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<SetLibraryMetadataProviderEnabledRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.Plugins;
/// <summary>
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdatePluginSettingsRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UpdatePluginSettingsRequest"/>.
/// </summary>
/// <param name="pluginId">Optional. The Id of the plugin whose settings are updated.</param>
/// <param name="settings">Optional. The settings to apply to the plugin.</param>
/// <returns>The created <see cref="UpdatePluginSettingsRequest"/>.</returns>
public UpdatePluginSettingsRequest Create(
Guid? pluginId = null,
IReadOnlyDictionary<string, string>? settings = null)
{
return new UpdatePluginSettingsRequest(
pluginId ?? _faker.Random.Guid(),
settings ?? new Dictionary<string, string>
{
[_faker.Lorem.Word()] = _faker.Lorem.Word()
}
);
}
/// <summary>
/// Creates a list of <see cref="UpdatePluginSettingsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdatePluginSettingsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.Authentication;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Authentication;
/// <summary>
/// Fixture class for the <see cref="RegistrationResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RegistrationResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="RegistrationResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the registered user.</param>
/// <param name="username">Optional. The username of the registered user.</param>
/// <param name="totpSecret">Optional. The TOTP secret used for two-factor authentication.</param>
/// <returns>The created <see cref="RegistrationResponse"/>.</returns>
public RegistrationResponse Create(
Guid? id = null,
string? username = null,
string? totpSecret = null)
{
return new RegistrationResponse(
id ?? Guid.NewGuid(),
username ?? _faker.Internet.UserName(),
totpSecret ?? _faker.Random.AlphaNumeric(16)
);
}
/// <summary>
/// Creates a list of <see cref="RegistrationResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<RegistrationResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Authorization;
/// <summary>
/// Fixture class for the <see cref="PermissionResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PermissionResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PermissionResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the permission.</param>
/// <param name="permissionName">Optional. The name of the permission.</param>
/// <returns>The created <see cref="PermissionResponse"/>.</returns>
public PermissionResponse Create(
Guid? id = null,
AuthorizationPermission? permissionName = null)
{
return new PermissionResponse(
id ?? Guid.NewGuid(),
permissionName ?? _faker.PickRandom<AuthorizationPermission>()
);
}
/// <summary>
/// Creates a list of <see cref="PermissionResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PermissionResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.DTO.Authentication;
using Lumina.Contracts.Fixtures.Core.DTO.Authentication;
using Lumina.Contracts.Responses.Authorization;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Authorization;
/// <summary>
/// Fixture class for the <see cref="RolePermissionsResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RolePermissionsResponseFixture
{
private readonly RoleDtoFixture _roleDtoFixture = new();
private readonly PermissionDtoFixture _permissionDtoFixture = new();
/// <summary>
/// Creates a random valid <see cref="RolePermissionsResponse"/>.
/// </summary>
/// <param name="role">Optional. The authorization role.</param>
/// <param name="permissions">Optional. The permissions of the authorization role.</param>
/// <returns>The created <see cref="RolePermissionsResponse"/>.</returns>
public RolePermissionsResponse Create(
RoleDto? role = null,
IEnumerable<PermissionDto>? permissions = null)
{
return new RolePermissionsResponse(
role ?? _roleDtoFixture.Create(),
(permissions ?? _permissionDtoFixture.CreateMany()).ToArray());
}
/// <summary>
/// Creates a list of <see cref="RolePermissionsResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<RolePermissionsResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,79 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="LibraryResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LibraryResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the media library.</param>
/// <param name="userId">Optional. The Id of the user owning the media library.</param>
/// <param name="title">Optional. The title of the media library.</param>
/// <param name="libraryType">Optional. The type of the media library.</param>
/// <param name="contentLocations">Optional. The file system paths of the media library content directories.</param>
/// <param name="coverImage">Optional. The path of the image file used as the cover of the library.</param>
/// <param name="isEnabled">Optional. Whether the media library is enabled.</param>
/// <param name="isLocked">Optional. Whether the media library is locked.</param>
/// <param name="downloadMetadataFromWeb">Optional. Whether metadata should be downloaded from the web.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Optional. Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Optional. Whether unchanged directories should be skipped during scan.</param>
/// <param name="createdOnUtc">Optional. The date and time when the library was created.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the library was updated.</param>
/// <returns>The created <see cref="LibraryResponse"/>.</returns>
public LibraryResponse Create(
Guid? id = null,
Guid? userId = null,
string? title = null,
LibraryType? libraryType = null,
List<string>? contentLocations = null,
string? coverImage = null,
bool? isEnabled = null,
bool? isLocked = null,
bool? downloadMetadataFromWeb = null,
bool? shouldSaveMetadataInMediaDirectories = null,
bool? shouldSkipUnchangedDirectoriesDuringScan = null,
DateTime? createdOnUtc = null,
DateTime? updatedOnUtc = null)
{
return new LibraryResponse(
id ?? Guid.NewGuid(),
userId ?? Guid.NewGuid(),
title ?? _faker.Commerce.Department(),
libraryType ?? _faker.PickRandom<LibraryType>(),
contentLocations ?? [_faker.System.DirectoryPath(), _faker.System.DirectoryPath()],
coverImage,
isEnabled ?? _faker.Random.Bool(),
isLocked ?? _faker.Random.Bool(),
downloadMetadataFromWeb ?? _faker.Random.Bool(),
shouldSaveMetadataInMediaDirectories ?? _faker.Random.Bool(),
shouldSkipUnchangedDirectoriesDuringScan ?? _faker.Random.Bool(),
createdOnUtc ?? _faker.Date.Past().ToUniversalTime(),
updatedOnUtc
);
}
/// <summary>
/// Creates a list of <see cref="LibraryResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LibraryResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="MediaLibraryScanJobProgressResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanJobProgressResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaLibraryScanJobProgressResponse"/>.
/// </summary>
/// <param name="completedItems">Optional. The number of processed scan job items.</param>
/// <param name="totalItems">Optional. The total number of scan job items.</param>
/// <param name="currentOperation">Optional. The current processing operation in the scan job.</param>
/// <param name="progressPercentage">Optional. The progress percentage of the scan job.</param>
/// <returns>The created <see cref="MediaLibraryScanJobProgressResponse"/>.</returns>
public MediaLibraryScanJobProgressResponse Create(
int? completedItems = null,
int? totalItems = null,
string? currentOperation = null,
decimal? progressPercentage = null)
{
return new MediaLibraryScanJobProgressResponse(
completedItems ?? _faker.Random.Int(0, 100),
totalItems ?? _faker.Random.Int(100, 1000),
currentOperation ?? _faker.Lorem.Word(),
progressPercentage ?? _faker.Random.Decimal(0m, 100m)
);
}
/// <summary>
/// Creates a list of <see cref="MediaLibraryScanJobProgressResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MediaLibraryScanJobProgressResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,64 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.MediaLibrary.Management;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
/// <summary>
/// Fixture class for the <see cref="MediaLibraryScanProgressResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanProgressResponseFixture
{
private readonly Faker _faker = new();
private readonly MediaLibraryScanJobProgressResponseFixture _mediaLibraryScanJobProgressResponseFixture = new();
/// <summary>
/// Creates a random valid <see cref="MediaLibraryScanProgressResponse"/>.
/// </summary>
/// <param name="scanId">Optional. The Id of the media library scan.</param>
/// <param name="userId">Optional. The Id of the user initiating the media library scan.</param>
/// <param name="libraryId">Optional. The Id of the media library that is scanned.</param>
/// <param name="totalJobs">Optional. The total number of jobs to be processed by the scan.</param>
/// <param name="completedJobs">Optional. The number of jobs that have been processed.</param>
/// <param name="currentJobProgress">Optional. The progress of the currently processing job.</param>
/// <param name="status">Optional. The status of the scan.</param>
/// <param name="overallProgressPercentage">Optional. The overall progress percentage of the scan.</param>
/// <returns>The created <see cref="MediaLibraryScanProgressResponse"/>.</returns>
public MediaLibraryScanProgressResponse Create(
Guid? scanId = null,
Guid? userId = null,
Guid? libraryId = null,
int? totalJobs = null,
int? completedJobs = null,
MediaLibraryScanJobProgressResponse? currentJobProgress = null,
string? status = null,
decimal? overallProgressPercentage = null)
{
return new MediaLibraryScanProgressResponse(
scanId ?? Guid.NewGuid(),
userId ?? Guid.NewGuid(),
libraryId ?? Guid.NewGuid(),
totalJobs ?? _faker.Random.Int(1, 10),
completedJobs ?? _faker.Random.Int(0, 10),
currentJobProgress ?? _mediaLibraryScanJobProgressResponseFixture.Create(),
status ?? _faker.Lorem.Word(),
overallProgressPercentage ?? _faker.Random.Decimal(0m, 100m)
);
}
/// <summary>
/// Creates a list of <see cref="MediaLibraryScanProgressResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<MediaLibraryScanProgressResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Fixture class for the <see cref="BookLiteResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookLiteResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookLiteResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the book.</param>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="releaseYear">Optional. The release year of the book.</param>
/// <param name="coverPath">Optional. The path of the image representing the cover of the book.</param>
/// <returns>The created <see cref="BookLiteResponse"/>.</returns>
public BookLiteResponse Create(
Guid? id = null,
string? title = null,
int? releaseYear = null,
string? coverPath = null)
{
return new BookLiteResponse(
id ?? Guid.NewGuid(),
title ?? _faker.Commerce.ProductName(),
releaseYear ?? _faker.Random.Int(1900, 2024),
coverPath ?? _faker.System.FilePath()
);
}
/// <summary>
/// Creates a list of <see cref="BookLiteResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BookLiteResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,102 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Fixture class for the <see cref="BookResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the book.</param>
/// <param name="libraryId">Optional. The Id of the media library the book belongs to.</param>
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="metadata">Optional. The written content metadata of the book.</param>
/// <param name="format">Optional. The format of the book.</param>
/// <param name="metadataStatus">Optional. The metadata enrichment status of the book.</param>
/// <param name="createdOnUtc">Optional. The date and time when the book was created.</param>
/// <returns>The created <see cref="BookResponse"/>.</returns>
public BookResponse Create(
Guid? id = null,
Guid? libraryId = null,
string? path = null,
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
MetadataStatus? metadataStatus = null,
DateTime? createdOnUtc = null)
{
DateTime resolvedCreatedOnUtc = createdOnUtc ?? _faker.Date.Past().ToUniversalTime();
return new BookResponse(
id ?? Guid.NewGuid(),
libraryId ?? Guid.NewGuid(),
path ?? _faker.System.FilePath(),
metadata ?? CreateMetadata(),
format ?? _faker.PickRandom<BookFormat>(),
_faker.Lorem.Word(),
_faker.Random.Int(1, 10),
new BookSeriesDto(_faker.Lorem.Word()),
_faker.Random.AlphaNumeric(10),
_faker.Random.AlphaNumeric(5),
_faker.Random.AlphaNumeric(8),
_faker.Random.AlphaNumeric(10),
_faker.Random.AlphaNumeric(7),
_faker.Random.AlphaNumeric(7),
_faker.Random.AlphaNumeric(6),
_faker.Random.AlphaNumeric(10),
_faker.Random.AlphaNumeric(8),
[new IsbnDto(_faker.Random.Replace("###-#-##-#####-#"), IsbnFormat.Isbn13)],
[new MediaContributorDto(
new MediaContributorNameDto(_faker.Name.FullName(), _faker.Name.FullName()),
new MediaContributorRoleDto(_faker.Commerce.ProductAdjective(), _faker.Commerce.Department()))],
[new BookRatingDto(_faker.Random.Decimal(1m, 5m), 5m, BookRatingSource.Goodreads, _faker.Random.Int(1, 1000))],
metadataStatus ?? _faker.PickRandom<MetadataStatus>(),
_faker.Date.Recent().ToUniversalTime(),
_faker.Company.CompanyName(),
resolvedCreatedOnUtc,
_faker.Random.Bool() ? _faker.Date.Recent().ToUniversalTime() : null
);
}
/// <summary>
/// Creates a list of <see cref="BookResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BookResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
private WrittenContentMetadataDto CreateMetadata()
{
return new WrittenContentMetadataDto(
_faker.Lorem.Sentence(3),
_faker.Lorem.Sentence(3),
_faker.Lorem.Paragraph(),
new ReleaseInfoDto(_faker.Date.PastDateOnly(), _faker.Random.Int(1900, 2024), null, null, _faker.Address.CountryCode(), null),
[new GenreDto(_faker.Lorem.Word())],
[new TagDto(_faker.Lorem.Word())],
new LanguageInfoDto("en", "English", "English"),
null,
_faker.Company.CompanyName(),
_faker.Random.Int(100, 1000)
);
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.Plugins;
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Plugins;
/// <summary>
/// Fixture class for the <see cref="PluginResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PluginResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the plugin.</param>
/// <param name="name">Optional. The display name of the plugin.</param>
/// <param name="author">Optional. The author of the plugin.</param>
/// <param name="version">Optional. The version of the plugin.</param>
/// <param name="description">Optional. The description of the plugin.</param>
/// <param name="loadStatus">Optional. The load status of the plugin.</param>
/// <param name="loadError">Optional. The error message when the plugin failed to load.</param>
/// <param name="settings">Optional. The settings of the plugin.</param>
/// <returns>The created <see cref="PluginResponse"/>.</returns>
public PluginResponse Create(
Guid? id = null,
string? name = null,
string? author = null,
string? version = null,
string? description = null,
PluginLoadStatus? loadStatus = null,
string? loadError = null,
IReadOnlyDictionary<string, string>? settings = null)
{
return new PluginResponse(
id ?? Guid.NewGuid(),
name ?? _faker.Commerce.ProductName(),
author ?? _faker.Company.CompanyName(),
version ?? _faker.System.Semver(),
description ?? _faker.Lorem.Sentence(),
loadStatus ?? _faker.PickRandom<PluginLoadStatus>(),
loadError,
settings ?? new Dictionary<string, string>
{
[_faker.Lorem.Word()] = _faker.Lorem.Word()
}
);
}
/// <summary>
/// Creates a list of <see cref="PluginResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PluginResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.Plugins;
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Plugins;
/// <summary>
/// Fixture class for the <see cref="PluginSettingDescriptorResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginSettingDescriptorResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PluginSettingDescriptorResponse"/>.
/// </summary>
/// <param name="key">Optional. The unique key of the setting.</param>
/// <param name="label">Optional. The display label of the setting.</param>
/// <param name="type">Optional. The type of the setting.</param>
/// <param name="defaultValue">Optional. The default value of the setting.</param>
/// <param name="allowedValues">Optional. The list of allowed values, when the setting is a selection.</param>
/// <returns>The created <see cref="PluginSettingDescriptorResponse"/>.</returns>
public PluginSettingDescriptorResponse Create(
string? key = null,
string? label = null,
PluginSettingType? type = null,
string? defaultValue = null,
IReadOnlyList<string>? allowedValues = null)
{
return new PluginSettingDescriptorResponse(
key ?? _faker.Lorem.Word(),
label ?? _faker.Lorem.Word(),
type ?? _faker.PickRandom<PluginSettingType>(),
defaultValue,
allowedValues ?? [_faker.Lorem.Word(), _faker.Lorem.Word()]
);
}
/// <summary>
/// Creates a list of <see cref="PluginSettingDescriptorResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PluginSettingDescriptorResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.Plugins;
/// <summary>
/// Fixture class for the <see cref="PluginSettingsResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginSettingsResponseFixture
{
private readonly Faker _faker = new();
private readonly PluginSettingDescriptorResponseFixture _pluginSettingDescriptorResponseFixture = new();
/// <summary>
/// Creates a random valid <see cref="PluginSettingsResponse"/>.
/// </summary>
/// <param name="pluginId">Optional. The Id of the plugin.</param>
/// <param name="schema">Optional. The schema of the plugin settings.</param>
/// <param name="settings">Optional. The current values of the plugin settings.</param>
/// <returns>The created <see cref="PluginSettingsResponse"/>.</returns>
public PluginSettingsResponse Create(
Guid? pluginId = null,
IReadOnlyList<PluginSettingDescriptorResponse>? schema = null,
IReadOnlyDictionary<string, string>? settings = null)
{
return new PluginSettingsResponse(
pluginId ?? Guid.NewGuid(),
schema ?? _pluginSettingDescriptorResponseFixture.CreateMany(3),
settings ?? new Dictionary<string, string>
{
[_faker.Lorem.Word()] = _faker.Lorem.Word()
}
);
}
/// <summary>
/// Creates a list of <see cref="PluginSettingsResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PluginSettingsResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.UsersManagement.Users;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.UsersManagement.Users;
/// <summary>
/// Fixture class for the <see cref="UserResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UserResponse"/>.
/// </summary>
/// <param name="id">Optional. The Id of the user.</param>
/// <param name="username">Optional. The username of the user.</param>
/// <param name="createdOnUtc">Optional. The date and time when the user was created.</param>
/// <param name="updatedOnUtc">Optional. The date and time when the user was updated.</param>
/// <returns>The created <see cref="UserResponse"/>.</returns>
public UserResponse Create(
Guid? id = null,
string? username = null,
DateTime? createdOnUtc = null,
DateTime? updatedOnUtc = null)
{
return new UserResponse(
id ?? Guid.NewGuid(),
username ?? _faker.Internet.UserName(),
createdOnUtc ?? _faker.Date.Past().ToUniversalTime(),
updatedOnUtc
);
}
/// <summary>
/// Creates a list of <see cref="UserResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UserResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,44 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
/// <summary>
/// Fixture class for the <see cref="Genre"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="Genre"/>.
/// </summary>
/// <param name="name">Optional. The name of the genre. If not provided, a random name is generated.</param>
/// <returns>The created <see cref="Genre"/>.</returns>
public Genre Create(string? name = null)
{
Result<Genre> genreResult = Genre.Create(name ?? _faker.Lorem.Word());
if (genreResult.IsFailure)
throw new InvalidOperationException("Failed to create Genre: " + string.Join(", ", genreResult.Errors));
return genreResult.Value;
}
/// <summary>
/// Creates multiple <see cref="Genre"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Genre"/> instances.</returns>
public List<Genre> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
/// <summary>
/// Fixture class for the <see cref="LanguageInfo"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class LanguageInfoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LanguageInfo"/>.
/// </summary>
/// <param name="languageCode">Optional. The ISO 639-1 two-letter language code. If not provided, a random code is generated.</param>
/// <param name="languageName">Optional. The full name of the language in English. If not provided, a random name is generated.</param>
/// <param name="nativeName">Optional. The native name of the language. If not provided, a random native name is generated.</param>
/// <returns>The created <see cref="LanguageInfo"/>.</returns>
public LanguageInfo Create(
string? languageCode = null,
string? languageName = null,
Optional<string>? nativeName = null)
{
string[] languages = ["en", "es", "fr", "de", "it", "ja", "ko", "zh", "pt", "ru"];
Result<LanguageInfo> languageInfoResult = LanguageInfo.Create(
languageCode ?? _faker.PickRandom(languages),
languageName ?? _faker.Lorem.Word(),
nativeName ?? Optional<string>.Some(_faker.Lorem.Word()));
if (languageInfoResult.IsFailure)
throw new InvalidOperationException("Failed to create LanguageInfo: " + string.Join(", ", languageInfoResult.Errors));
return languageInfoResult.Value;
}
/// <summary>
/// Creates multiple <see cref="LanguageInfo"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LanguageInfo"/> instances.</returns>
public List<LanguageInfo> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,91 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
/// <summary>
/// Fixture class for the <see cref="ReleaseInfo"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class ReleaseInfoFixture
{
private readonly Faker _faker = new();
private readonly Random _random = new();
/// <summary>
/// Creates a random valid <see cref="ReleaseInfo"/>.
/// </summary>
/// <param name="originalReleaseDate">Optional. The original release date of the media item.</param>
/// <param name="originalReleaseYear">Optional. The original release year of the media item.</param>
/// <param name="reReleaseDate">Optional. The re-release date of the media item.</param>
/// <param name="reReleaseYear">Optional. The re-release year of the media item.</param>
/// <param name="releaseCountry">Optional. The country or region of release.</param>
/// <param name="releaseVersion">Optional. The release version or edition.</param>
/// <returns>The created <see cref="ReleaseInfo"/>.</returns>
public ReleaseInfo Create(
Optional<DateOnly>? originalReleaseDate = null,
Optional<int>? originalReleaseYear = null,
Optional<DateOnly>? reReleaseDate = null,
Optional<int>? reReleaseYear = null,
Optional<string>? releaseCountry = null,
Optional<string>? releaseVersion = null)
{
int generatedYear = _random.Next(1900, 2000);
Optional<DateOnly> resolvedOriginalDate = originalReleaseDate ?? Optional<DateOnly>.None();
Optional<int> resolvedOriginalYear = originalReleaseYear ?? Optional<int>.None();
if (!resolvedOriginalDate.HasValue && !resolvedOriginalYear.HasValue)
{
resolvedOriginalDate = Optional<DateOnly>.Some(new DateOnly(generatedYear, 1, 1));
resolvedOriginalYear = Optional<int>.Some(generatedYear);
}
else if (!resolvedOriginalDate.HasValue)
{
resolvedOriginalDate = Optional<DateOnly>.Some(new DateOnly(resolvedOriginalYear.Value, 1, 1));
}
else if (!resolvedOriginalYear.HasValue)
{
resolvedOriginalYear = Optional<int>.Some(resolvedOriginalDate.Value.Year);
}
Optional<DateOnly> resolvedReReleaseDate = reReleaseDate ?? Optional<DateOnly>.None();
Optional<int> resolvedReReleaseYear = reReleaseYear ?? Optional<int>.None();
if (resolvedReReleaseDate.HasValue && !resolvedReReleaseYear.HasValue)
{
resolvedReReleaseYear = Optional<int>.Some(resolvedReReleaseDate.Value.Year);
}
else if (!resolvedReReleaseDate.HasValue && resolvedReReleaseYear.HasValue)
{
resolvedReReleaseDate = Optional<DateOnly>.Some(new DateOnly(resolvedReReleaseYear.Value, 1, 1));
}
Result<ReleaseInfo> releaseInfoResult = ReleaseInfo.Create(
resolvedOriginalDate,
resolvedOriginalYear,
resolvedReReleaseDate,
resolvedReReleaseYear,
releaseCountry ?? Optional<string>.Some(_faker.Address.Country()),
releaseVersion ?? Optional<string>.Some(_faker.Lorem.Word()));
if (releaseInfoResult.IsFailure)
throw new InvalidOperationException("Failed to create ReleaseInfo: " + string.Join(", ", releaseInfoResult.Errors));
return releaseInfoResult.Value;
}
/// <summary>
/// Creates multiple <see cref="ReleaseInfo"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ReleaseInfo"/> instances.</returns>
public List<ReleaseInfo> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,44 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
/// <summary>
/// Fixture class for the <see cref="Tag"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="Tag"/>.
/// </summary>
/// <param name="name">Optional. The name of the tag. If not provided, a random name is generated.</param>
/// <returns>The created <see cref="Tag"/>.</returns>
public Tag Create(string? name = null)
{
Result<Tag> tagResult = Tag.Create(name ?? _faker.Lorem.Word());
if (tagResult.IsFailure)
throw new InvalidOperationException("Failed to create Tag: " + string.Join(", ", tagResult.Errors));
return tagResult.Value;
}
/// <summary>
/// Creates multiple <see cref="Tag"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Tag"/> instances.</returns>
public List<Tag> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,86 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="AudioMetadata"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class AudioMetadataFixture
{
private readonly Faker _faker = new();
private readonly GenreFixture _genreFixture = new();
private readonly TagFixture _tagFixture = new();
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
private readonly LanguageInfoFixture _languageInfoFixture = new();
/// <summary>
/// Creates a random valid <see cref="AudioMetadata"/>.
/// </summary>
/// <param name="title">Optional. The title of the audio.</param>
/// <param name="originalTitle">Optional. The original title of the audio.</param>
/// <param name="durationInSeconds">Optional. The duration of the audio, in seconds.</param>
/// <param name="sampleRate">Optional. The sample rate of the audio, in Hz.</param>
/// <param name="channels">Optional. The number of audio channels.</param>
/// <param name="releaseInfo">Optional. The release information of the audio.</param>
/// <param name="description">Optional. The description of the audio.</param>
/// <param name="genres">Optional. The genres of the audio.</param>
/// <param name="tags">Optional. The tags associated with the audio.</param>
/// <param name="language">Optional. The language of the audio.</param>
/// <param name="originalLanguage">Optional. The original language of the audio.</param>
/// <param name="bitDepth">Optional. The bit depth of the audio.</param>
/// <param name="audioCodec">Optional. The audio codec used.</param>
/// <param name="bitrate">Optional. The bitrate of the audio, in kbps.</param>
/// <returns>The created <see cref="AudioMetadata"/>.</returns>
public AudioMetadata Create(
string? title = null,
Optional<string>? originalTitle = null,
int? durationInSeconds = null,
int? sampleRate = null,
int? channels = null,
ReleaseInfo? releaseInfo = null,
Optional<string>? description = null,
List<Genre>? genres = null,
List<Tag>? tags = null,
Optional<LanguageInfo>? language = null,
Optional<LanguageInfo>? originalLanguage = null,
Optional<int>? bitDepth = null,
Optional<string>? audioCodec = null,
Optional<int>? bitrate = null)
{
return AudioMetadata.Create(
title ?? _faker.Music.Genre(),
originalTitle ?? Optional<string>.None(),
durationInSeconds ?? _faker.Random.Int(60, 7200),
sampleRate ?? _faker.Random.Int(44100, 192000),
channels ?? _faker.Random.Int(1, 8),
releaseInfo ?? _releaseInfoFixture.Create(),
description ?? Optional<string>.Some(_faker.Lorem.Sentence()),
genres ?? [_genreFixture.Create(), _genreFixture.Create()],
tags ?? [_tagFixture.Create(), _tagFixture.Create()],
language ?? Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
originalLanguage ?? Optional<LanguageInfo>.None(),
bitDepth ?? Optional<int>.Some(_faker.Random.Int(8, 32)),
audioCodec ?? Optional<string>.Some("PCM"),
bitrate ?? Optional<int>.Some(_faker.Random.Int(128, 320))).Value;
}
/// <summary>
/// Creates multiple <see cref="AudioMetadata"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="AudioMetadata"/> instances.</returns>
public List<AudioMetadata> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -32,6 +32,7 @@ public class LibraryFixture
/// <param name="libraryType">Optional. The library type.</param>
/// <param name="contentLocations">Optional. The content locations of the library.</param>
/// <param name="coverImage">Optional. The cover image of the library.</param>
/// <param name="includeCoverImage">Whether to include a cover image or not.</param>
/// <param name="isEnabled">Whether the library is enabled.</param>
/// <param name="isLocked">Whether the library is locked.</param>
/// <param name="downloadMetadataFromWeb">Whether metadata download from the web is enabled.</param>
@@ -46,6 +47,7 @@ public class LibraryFixture
LibraryType? libraryType = null,
IEnumerable<string>? contentLocations = null,
string? coverImage = null,
bool includeCoverImage = true,
bool isEnabled = true,
bool isLocked = false,
bool downloadMetadataFromWeb = true,
@@ -62,6 +64,7 @@ public class LibraryFixture
];
List<ScanId> resolvedScanIds = scanIds is null ? [ScanId.CreateUnique(), ScanId.CreateUnique()] : [.. scanIds.Select(scanId => ScanId.Create(scanId))];
string? resolvedCoverImage = includeCoverImage ? (coverImage ?? _faker.System.FilePath()) : null;
Result<Library> library = id is null ?
Library.Create(
@@ -69,7 +72,7 @@ public class LibraryFixture
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
libraryType ?? _faker.PickRandom<LibraryType>(),
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
coverImage ?? _faker.System.FilePath(),
resolvedCoverImage,
isEnabled,
isLocked,
downloadMetadataFromWeb,
@@ -83,7 +86,7 @@ public class LibraryFixture
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
libraryType ?? _faker.PickRandom<LibraryType>(),
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
coverImage ?? _faker.System.FilePath(),
resolvedCoverImage,
isEnabled,
isLocked,
downloadMetadataFromWeb,
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="LibraryId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryIdFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the library Id.</param>
/// <returns>The created <see cref="LibraryId"/>.</returns>
public LibraryId Create(Guid? value = null)
{
return LibraryId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="LibraryId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryId"/> instances.</returns>
public List<LibraryId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
/// <summary>
/// Fixture class for the <see cref="LibraryScan"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryScanFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryScan"/> domain aggregate.
/// </summary>
/// <param name="id">Optional. The scan Id.</param>
/// <param name="libraryId">Optional. The Id of the media library that is scanned.</param>
/// <param name="userId">Optional. The Id of the user that initiated the scan.</param>
/// <param name="status">Optional. The status of the media library scan.</param>
/// <param name="pastScans">Optional. The list of past scans of the scanned media library.</param>
/// <returns>The created <see cref="LibraryScan"/>.</returns>
public LibraryScan Create(
Guid? id = null,
Guid? libraryId = null,
Guid? userId = null,
LibraryScanJobStatus? status = null,
List<LibraryScan>? pastScans = null)
{
Result<LibraryScan> scan = LibraryScan.Create(
ScanId.Create(id ?? Guid.NewGuid()),
LibraryId.Create(libraryId ?? Guid.NewGuid()),
UserId.Create(userId ?? Guid.NewGuid()),
status ?? LibraryScanJobStatus.Pending,
pastScans ?? []);
return scan.Value;
}
/// <summary>
/// Creates multiple <see cref="LibraryScan"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryScan"/> instances.</returns>
public List<LibraryScan> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaLibraryScanCompositeId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanCompositeIdFixture
{
private readonly ScanIdFixture _scanIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="MediaLibraryScanCompositeId"/>.
/// </summary>
/// <param name="scanId">Optional. The scan Id of the composite scan identifier.</param>
/// <param name="userId">Optional. The user Id of the composite scan identifier.</param>
/// <returns>The created <see cref="MediaLibraryScanCompositeId"/>.</returns>
public MediaLibraryScanCompositeId Create(ScanId? scanId = null, UserId? userId = null)
{
return MediaLibraryScanCompositeId.Create(
scanId ?? _scanIdFixture.Create(),
userId ?? _userIdFixture.Create());
}
/// <summary>
/// Creates a list of <see cref="MediaLibraryScanCompositeId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaLibraryScanCompositeId"/> instances.</returns>
public List<MediaLibraryScanCompositeId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,49 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaLibraryScanJobProgress"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanJobProgressFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaLibraryScanJobProgress"/>.
/// </summary>
/// <param name="completedItems">Optional. The number of completed items of the scan job.</param>
/// <param name="totalItems">Optional. The total number of items of the scan job.</param>
/// <param name="currentOperation">Optional. The current operation being performed by the scan job.</param>
/// <returns>The created <see cref="MediaLibraryScanJobProgress"/>.</returns>
public MediaLibraryScanJobProgress Create(
int? completedItems = null,
int? totalItems = null,
string? currentOperation = null)
{
Result<MediaLibraryScanJobProgress> progress = MediaLibraryScanJobProgress.Create(
completedItems ?? _faker.Random.Number(0, 100),
totalItems ?? _faker.Random.Number(100, 200),
currentOperation ?? _faker.Random.Words());
return progress.Value;
}
/// <summary>
/// Creates a list of <see cref="MediaLibraryScanJobProgress"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaLibraryScanJobProgress"/> instances.</returns>
public List<MediaLibraryScanJobProgress> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaLibraryScanProgress"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaLibraryScanProgressFixture
{
private readonly ScanIdFixture _scanIdFixture = new();
private readonly UserIdFixture _userIdFixture = new();
private readonly LibraryIdFixture _libraryIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="MediaLibraryScanProgress"/>.
/// </summary>
/// <param name="scanId">Optional. The scan Id of the media library scan.</param>
/// <param name="userId">Optional. The user Id of the user initiating the media library scan.</param>
/// <param name="libraryId">Optional. The library Id of the scanned media library.</param>
/// <param name="completedJobs">Optional. The number of completed jobs of the media library scan.</param>
/// <param name="totalJobs">Optional. The total number of jobs of the media library scan.</param>
/// <param name="status">Optional. The status of the media library scan.</param>
/// <param name="currentJobProgress">Optional. The current job progress of the media library scan. When <see langword="null"/>, no current job progress is set.</param>
/// <returns>The created <see cref="MediaLibraryScanProgress"/>.</returns>
public MediaLibraryScanProgress Create(
ScanId? scanId = null,
UserId? userId = null,
LibraryId? libraryId = null,
int? completedJobs = null,
int? totalJobs = null,
LibraryScanJobStatus? status = null,
Optional<MediaLibraryScanJobProgress>? currentJobProgress = null)
{
Result<MediaLibraryScanProgress> progress = MediaLibraryScanProgress.Create(
scanId ?? _scanIdFixture.Create(),
userId ?? _userIdFixture.Create(),
libraryId ?? _libraryIdFixture.Create(),
completedJobs ?? 1,
totalJobs ?? 2,
status ?? LibraryScanJobStatus.Pending,
currentJobProgress ?? Optional<MediaLibraryScanJobProgress>.None());
return progress.Value;
}
/// <summary>
/// Creates a list of <see cref="MediaLibraryScanProgress"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaLibraryScanProgress"/> instances.</returns>
public List<MediaLibraryScanProgress> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="ScanId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class ScanIdFixture
{
/// <summary>
/// Creates a random valid <see cref="ScanId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the scan Id.</param>
/// <returns>The created <see cref="ScanId"/>.</returns>
public ScanId Create(Guid? value = null)
{
return ScanId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="ScanId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ScanId"/> instances.</returns>
public List<ScanId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaContributorId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorIdFixture
{
/// <summary>
/// Creates a random valid <see cref="MediaContributorId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="MediaContributorId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="MediaContributorId"/>.</returns>
public MediaContributorId Create(Guid? value = null)
{
return value is null ? MediaContributorId.CreateUnique() : MediaContributorId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="MediaContributorId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaContributorId"/> instances.</returns>
public List<MediaContributorId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,47 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaContributorName"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorNameFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorName"/>.
/// </summary>
/// <param name="displayName">Optional. The name by which the contributor is popularly known. If not provided, a random name is generated.</param>
/// <param name="legalName">Optional. The legal name of the contributor. If not provided, a random legal name is generated.</param>
/// <returns>The created <see cref="MediaContributorName"/>.</returns>
public MediaContributorName Create(string? displayName = null, Optional<string>? legalName = null)
{
Result<MediaContributorName> nameResult = MediaContributorName.Create(
displayName ?? _faker.Person.FullName,
legalName ?? Optional<string>.Some(_faker.Person.FullName));
if (nameResult.IsFailure)
throw new InvalidOperationException("Failed to create MediaContributorName: " + string.Join(", ", nameResult.Errors));
return nameResult.Value;
}
/// <summary>
/// Creates multiple <see cref="MediaContributorName"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaContributorName"/> instances.</returns>
public List<MediaContributorName> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MediaContributorRole"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MediaContributorRoleFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="MediaContributorRole"/>.
/// </summary>
/// <param name="name">Optional. The name of the role. If not provided, a random name is generated.</param>
/// <param name="category">Optional. The category of the role. If not provided, a random category is generated.</param>
/// <returns>The created <see cref="MediaContributorRole"/>.</returns>
public MediaContributorRole Create(string? name = null, string? category = null)
{
return MediaContributorRole.Create(
name ?? _faker.Lorem.Word(),
category ?? _faker.Commerce.Department());
}
/// <summary>
/// Creates multiple <see cref="MediaContributorRole"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MediaContributorRole"/> instances.</returns>
public List<MediaContributorRole> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,44 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
/// <summary>
/// Fixture class for the <see cref="User"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="User"/> domain aggregate.
/// </summary>
/// <param name="id">Optional. The user Id.</param>
/// <param name="username">Optional. The username of the user.</param>
/// <returns>The created <see cref="User"/>.</returns>
public User Create(Guid? id = null, string? username = null)
{
UserId userId = id is null ? UserId.CreateUnique() : UserId.Create(id.Value);
Result<User> user = User.Create(userId, username ?? _faker.Internet.UserName());
return user.Value;
}
/// <summary>
/// Creates multiple <see cref="User"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="User"/> instances.</returns>
public List<User> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="UserId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserIdFixture
{
/// <summary>
/// Creates a random valid <see cref="UserId"/>.
/// </summary>
/// <param name="value">Optional. The raw value of the user Id.</param>
/// <returns>The created <see cref="UserId"/>.</returns>
public UserId Create(Guid? value = null)
{
return UserId.Create(value ?? Guid.NewGuid());
}
/// <summary>
/// Creates a list of <see cref="UserId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UserId"/> instances.</returns>
public List<UserId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
/// <summary>
/// Fixture class for the <see cref="UserSettings"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserSettingsFixture
{
/// <summary>
/// Creates a random valid <see cref="UserSettings"/> domain aggregate.
/// </summary>
/// <param name="userId">Optional. The Id of the user that owns the settings.</param>
/// <param name="isPaginationEnabled">Whether pagination is enabled for the user.</param>
/// <param name="itemsPerPage">The number of library items displayed per page when pagination is enabled.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Whether the "The" prefix of library item titles is ignored by the alpha picker.</param>
/// <returns>The created <see cref="UserSettings"/>.</returns>
public UserSettings Create(
Guid? userId = null,
bool isPaginationEnabled = true,
int itemsPerPage = 48,
bool ignoreThePrefixForAlphaPicker = false)
{
Result<UserSettings> settings = UserSettings.Create(
userId is null ? UserId.CreateUnique() : UserId.Create(userId.Value),
isPaginationEnabled,
itemsPerPage,
ignoreThePrefixForAlphaPicker);
return settings.Value;
}
/// <summary>
/// Creates multiple <see cref="UserSettings"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UserSettings"/> instances.</returns>
public List<UserSettings> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,57 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate;
/// <summary>
/// Fixture class for the <see cref="Movie"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class MovieFixture
{
private readonly VideoMetadataFixture _videoMetadataFixture = new();
private readonly MovieIdFixture _movieIdFixture = new();
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
/// <summary>
/// Creates a random valid <see cref="Movie"/>.
/// </summary>
/// <param name="id">Optional. The unique identifier of the movie.</param>
/// <param name="metadata">Optional. The metadata of the movie.</param>
/// <param name="contributors">Optional. The list of media contributors of the movie.</param>
/// <param name="ratings">Optional. The list of ratings for the movie.</param>
/// <returns>The created <see cref="Movie"/>.</returns>
public Movie Create(
MovieId? id = null,
VideoMetadata? metadata = null,
List<MediaContributorId>? contributors = null,
List<Rating>? ratings = null)
{
return Movie.Create(
id ?? _movieIdFixture.Create(),
metadata ?? _videoMetadataFixture.Create(),
contributors ?? [_mediaContributorIdFixture.Create()],
ratings ?? []).Value;
}
/// <summary>
/// Creates multiple <see cref="Movie"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Movie"/> instances.</returns>
public List<Movie> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="MovieId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class MovieIdFixture
{
/// <summary>
/// Creates a random valid <see cref="MovieId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="MovieId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="MovieId"/>.</returns>
public MovieId Create(Guid? value = null)
{
return value is null ? MovieId.CreateUnique() : MovieId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="MovieId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="MovieId"/> instances.</returns>
public List<MovieId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,84 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="VideoMetadata"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class VideoMetadataFixture
{
private readonly Faker _faker = new();
private readonly GenreFixture _genreFixture = new();
private readonly TagFixture _tagFixture = new();
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
private readonly LanguageInfoFixture _languageInfoFixture = new();
/// <summary>
/// Creates a random valid <see cref="VideoMetadata"/>.
/// </summary>
/// <param name="title">Optional. The title of the video.</param>
/// <param name="originalTitle">Optional. The original title of the video.</param>
/// <param name="durationInSeconds">Optional. The duration of the video in seconds.</param>
/// <param name="resolution">Optional. The resolution of the video.</param>
/// <param name="description">Optional. The description of the video.</param>
/// <param name="releaseInfo">Optional. The release information of the video.</param>
/// <param name="language">Optional. The language of the video.</param>
/// <param name="originalLanguage">Optional. The original language of the video.</param>
/// <param name="frameRate">Optional. The frame rate of the video.</param>
/// <param name="videoCodec">Optional. The video codec used.</param>
/// <param name="audioCodec">Optional. The audio codec used.</param>
/// <param name="genres">Optional. The genres of the video.</param>
/// <param name="tags">Optional. The tags associated with the video.</param>
/// <returns>The created <see cref="VideoMetadata"/>.</returns>
public VideoMetadata Create(
string? title = null,
Optional<string>? originalTitle = null,
int? durationInSeconds = null,
string? resolution = null,
Optional<string>? description = null,
ReleaseInfo? releaseInfo = null,
Optional<LanguageInfo>? language = null,
Optional<LanguageInfo>? originalLanguage = null,
Optional<float>? frameRate = null,
Optional<string>? videoCodec = null,
Optional<string>? audioCodec = null,
List<Genre>? genres = null,
List<Tag>? tags = null)
{
return VideoMetadata.Create(
title ?? _faker.Commerce.ProductName(),
originalTitle ?? Optional<string>.None(),
durationInSeconds ?? _faker.Random.Int(60, 18000),
resolution ?? "1920x1080",
description ?? Optional<string>.Some(_faker.Lorem.Sentence()),
releaseInfo ?? _releaseInfoFixture.Create(),
language ?? Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
originalLanguage ?? Optional<LanguageInfo>.None(),
frameRate ?? Optional<float>.Some(24),
videoCodec ?? Optional<string>.Some("H.264"),
audioCodec ?? Optional<string>.Some("AAC"),
genres ?? [_genreFixture.Create(), _genreFixture.Create()],
tags ?? [_tagFixture.Create(), _tagFixture.Create()]).Value;
}
/// <summary>
/// Creates multiple <see cref="VideoMetadata"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="VideoMetadata"/> instances.</returns>
public List<VideoMetadata> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="EpisodeId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class EpisodeIdFixture
{
/// <summary>
/// Creates a random valid <see cref="EpisodeId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="EpisodeId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="EpisodeId"/>.</returns>
public EpisodeId Create(Guid? value = null)
{
return value is null ? EpisodeId.CreateUnique() : EpisodeId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="EpisodeId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="EpisodeId"/> instances.</returns>
public List<EpisodeId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="SeasonId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class SeasonIdFixture
{
/// <summary>
/// Creates a random valid <see cref="SeasonId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="SeasonId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="SeasonId"/>.</returns>
public SeasonId Create(Guid? value = null)
{
return value is null ? SeasonId.CreateUnique() : SeasonId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="SeasonId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="SeasonId"/> instances.</returns>
public List<SeasonId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="TvShowId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class TvShowIdFixture
{
/// <summary>
/// Creates a random valid <see cref="TvShowId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="TvShowId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="TvShowId"/>.</returns>
public TvShowId Create(Guid? value = null)
{
return value is null ? TvShowId.CreateUnique() : TvShowId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="TvShowId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="TvShowId"/> instances.</returns>
public List<TvShowId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
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.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
/// <summary>
/// Fixture class for the <see cref="BookSeries"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookSeriesFixture
{
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
/// <summary>
/// Creates a random valid <see cref="BookSeries"/>.
/// </summary>
/// <param name="id">Optional. The unique identifier of the book series.</param>
/// <param name="isComplete">Whether the book series is complete.</param>
/// <returns>The created <see cref="BookSeries"/>.</returns>
public BookSeries Create(
Guid? id = null,
bool isComplete = false)
{
return BookSeries.Create(
id is null ? BookSeriesId.CreateUnique() : _bookSeriesIdFixture.Create(id.Value),
_writtenContentMetadataFixture.Create(),
isComplete,
[]).Value;
}
/// <summary>
/// Creates multiple <see cref="BookSeries"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookSeries"/> instances.</returns>
public List<BookSeries> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookId"/>.</returns>
public BookId Create(Guid? value = null)
{
return value is null ? BookId.CreateUnique() : BookId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="BookId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookId"/> instances.</returns>
public List<BookId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,37 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookLibraryId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookLibraryIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookLibraryId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookLibraryId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookLibraryId"/>.</returns>
public BookLibraryId Create(Guid? value = null)
{
return value is null ? BookLibraryId.CreateUnique().Value : BookLibraryId.Create(value.Value).Value;
}
/// <summary>
/// Creates multiple <see cref="BookLibraryId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookLibraryId"/> instances.</returns>
public List<BookLibraryId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookSeriesId"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookSeriesIdFixture
{
/// <summary>
/// Creates a random valid <see cref="BookSeriesId"/>.
/// </summary>
/// <param name="value">Optional. The value used to create the <see cref="BookSeriesId"/>. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="BookSeriesId"/>.</returns>
public BookSeriesId Create(Guid? value = null)
{
return value is null ? BookSeriesId.CreateUnique() : BookSeriesId.Create(value.Value);
}
/// <summary>
/// Creates multiple <see cref="BookSeriesId"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookSeriesId"/> instances.</returns>
public List<BookSeriesId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,4 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
@@ -19,13 +20,23 @@ public class IsbnFixture
/// <summary>
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
/// </summary>
/// <param name="value">Optional. The ISBN value to use. If not provided, a random valid value is generated for the requested format.</param>
/// <param name="format">Optional. The requested <see cref="IsbnFormat"/>. If not provided, a random format is selected.</param>
/// <returns>The created <see cref="Isbn"/>.</returns>
public Isbn Create(IsbnFormat? format = null)
public Isbn Create(string? value = null, IsbnFormat? format = null)
{
IsbnFormat targetFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
string isbn = targetFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
return Isbn.Create(isbn, targetFormat).Value;
if (value is not null)
{
IsbnFormat targetFormat = format ?? IsbnFormat.Isbn10;
Result<Isbn> result = Isbn.Create(value, targetFormat);
if (result.IsFailure)
throw new InvalidOperationException("Failed to create Isbn: " + string.Join(", ", result.Errors));
return result.Value;
}
IsbnFormat requestedFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
string isbn = requestedFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
return Isbn.Create(isbn, requestedFormat).Value;
}
/// <summary>
@@ -0,0 +1,75 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
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 System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="WrittenContentMetadata"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class WrittenContentMetadataFixture
{
private readonly Faker _faker = new();
private readonly GenreFixture _genreFixture = new();
private readonly TagFixture _tagFixture = new();
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
private readonly LanguageInfoFixture _languageInfoFixture = new();
/// <summary>
/// Creates a random valid <see cref="WrittenContentMetadata"/>.
/// </summary>
/// <param name="title">Optional. The title of the written content.</param>
/// <param name="originalTitle">Optional. The original title of the written content.</param>
/// <param name="description">Optional. The description of the written content.</param>
/// <param name="releaseInfo">Optional. The release information of the written content.</param>
/// <param name="genres">Optional. The genres of the written content.</param>
/// <param name="tags">Optional. The tags associated with the written content.</param>
/// <param name="language">Optional. The language of the written content.</param>
/// <param name="originalLanguage">Optional. The original language of the written content.</param>
/// <param name="publisher">Optional. The publisher of the written content.</param>
/// <param name="pageCount">Optional. The number of pages in the written content.</param>
/// <returns>The created <see cref="WrittenContentMetadata"/>.</returns>
public WrittenContentMetadata Create(
string? title = null,
Optional<string>? originalTitle = null,
Optional<string>? description = null,
ReleaseInfo? releaseInfo = null,
List<Genre>? genres = null,
List<Tag>? tags = null,
Optional<LanguageInfo>? language = null,
Optional<LanguageInfo>? originalLanguage = null,
Optional<string>? publisher = null,
Optional<int>? pageCount = null)
{
return WrittenContentMetadata.Create(
title ?? _faker.Commerce.ProductName(),
originalTitle ?? Optional<string>.None(),
description ?? Optional<string>.Some(_faker.Lorem.Sentence()),
releaseInfo ?? _releaseInfoFixture.Create(),
genres ?? [_genreFixture.Create(), _genreFixture.Create()],
tags ?? [_tagFixture.Create(), _tagFixture.Create()],
language ?? Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
originalLanguage ?? Optional<LanguageInfo>.None(),
publisher ?? Optional<string>.Some(_faker.Company.CompanyName()),
pageCount ?? Optional<int>.Some(_faker.Random.Int(1, 1000))).Value;
}
/// <summary>
/// Creates multiple <see cref="WrittenContentMetadata"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="WrittenContentMetadata"/> instances.</returns>
public List<WrittenContentMetadata> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
/// <summary>
/// Fixture class for the <see cref="CorsSettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CorsSettingsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a valid <see cref="CorsSettingsDto"/>.
/// </summary>
/// <param name="allowedOrigins">Optional. The allowed origins, or <see langword="null"/> to generate valid origins.</param>
/// <returns>The created <see cref="CorsSettingsDto"/>.</returns>
public CorsSettingsDto Create(string[]? allowedOrigins = null)
{
return new CorsSettingsDto
{
AllowedOrigins = allowedOrigins ?? [$"https://{_faker.Internet.DomainName()}", $"http://{_faker.Internet.DomainName()}"]
};
}
/// <summary>
/// Creates a list of <see cref="CorsSettingsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="CorsSettingsDto"/> instances.</returns>
public List<CorsSettingsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.Infrastructure.Models.DTO.Configuration;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
/// <summary>
/// Fixture class for the <see cref="PluginsSettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginsSettingsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a valid <see cref="PluginsSettingsDto"/>.
/// </summary>
/// <param name="directory">Optional. The directory where the plugin assemblies are located.</param>
/// <returns>The created <see cref="PluginsSettingsDto"/>.</returns>
public PluginsSettingsDto Create(string? directory = null)
{
return new PluginsSettingsDto
{
Directory = directory ?? _faker.System.DirectoryPath()
};
}
/// <summary>
/// Creates a list of <see cref="PluginsSettingsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PluginsSettingsDto"/> instances.</returns>
public List<PluginsSettingsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -22,7 +22,7 @@ public class AuthorizationServiceFixture
/// <param name="directPermissions">Direct permissions to assign to the user.</param>
/// <param name="rolePermissions">Permissions to assign through roles.</param>
/// <returns>The created user entity.</returns>
public static UserEntity CreateUserWithPermissions(
public UserEntity CreateUserWithPermissions(
IEnumerable<AuthorizationPermission>? directPermissions = null,
Dictionary<string, IEnumerable<AuthorizationPermission>>? rolePermissions = null)
{
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Plugins.Contracts.Fixtures.Common.Models.DTO.Settings;
/// <summary>
/// Fixture class for the <see cref="PluginSettingDescriptorDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginSettingDescriptorDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PluginSettingDescriptorDto"/>.
/// </summary>
/// <param name="key">Optional. The key of the setting.</param>
/// <param name="label">Optional. The display label of the setting.</param>
/// <param name="type">Optional. The type of the setting.</param>
/// <param name="defaultValue">Optional. The default value of the setting.</param>
/// <param name="allowedValues">Optional. The list of allowed values of the setting.</param>
/// <returns>The created <see cref="PluginSettingDescriptorDto"/>.</returns>
public PluginSettingDescriptorDto Create(
string? key = null,
string? label = null,
PluginSettingType? type = null,
string? defaultValue = null,
IReadOnlyList<string>? allowedValues = null)
{
return new PluginSettingDescriptorDto(
key ?? _faker.Random.String2(4, 32),
label ?? _faker.Commerce.ProductName(),
type ?? _faker.Random.Enum<PluginSettingType>(),
defaultValue,
allowedValues);
}
/// <summary>
/// Creates a list of <see cref="PluginSettingDescriptorDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<PluginSettingDescriptorDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,24 @@
<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" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Bogus" Version="35.6.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,20 @@
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.Contracts.Fixtures")]
[assembly: AssemblyProduct("Lumina.Plugins.Contracts.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("A1B2C3D4-0001-4A5B-9C0D-111111111111")]
[assembly: InternalsVisibleTo("Lumina.Plugins.Contracts.UnitTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -0,0 +1,36 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryAuthorResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryAuthorResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryAuthorResponse"/>.
/// </summary>
/// <param name="key">Optional. The key of the author.</param>
/// <param name="name">Optional. The name of the author.</param>
/// <param name="personalName">Optional. The personal name of the author.</param>
/// <returns>The created author response.</returns>
public OpenLibraryAuthorResponse Create(
string? key = null,
string? name = null,
string? personalName = null)
{
return new OpenLibraryAuthorResponse
{
Key = key ?? $"/authors/OL{_faker.Random.Number(1000, 9999)}A",
Name = name ?? _faker.Name.FullName(),
PersonalName = personalName
};
}
}
@@ -0,0 +1,95 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryEditionResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryEditionResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryEditionResponse"/>.
/// </summary>
/// <param name="key">Optional. The key of the edition.</param>
/// <param name="title">Optional. The title of the edition.</param>
/// <param name="subtitle">Optional. The subtitle of the edition.</param>
/// <param name="notes">Optional. The notes of the edition.</param>
/// <param name="publishDate">Optional. The publication date of the edition.</param>
/// <param name="publishers">Optional. The publishers of the edition.</param>
/// <param name="publishPlaces">Optional. The publication places of the edition.</param>
/// <param name="numberOfPages">Optional. The number of pages of the edition.</param>
/// <param name="physicalFormat">Optional. The physical format of the edition.</param>
/// <param name="editionName">Optional. The name of the edition.</param>
/// <param name="series">Optional. The series of the edition.</param>
/// <param name="volume">Optional. The volume of the edition within its series.</param>
/// <param name="isbn10">Optional. The ISBN-10 identifiers of the edition.</param>
/// <param name="isbn13">Optional. The ISBN-13 identifiers of the edition.</param>
/// <param name="lccn">Optional. The LCCN identifiers of the edition.</param>
/// <param name="oclcNumbers">Optional. The OCLC numbers of the edition.</param>
/// <param name="identifiers">Optional. The external identifiers of the edition.</param>
/// <param name="sourceRecords">Optional. The source records of the edition.</param>
/// <param name="languages">Optional. The languages of the edition.</param>
/// <param name="authors">Optional. The authors of the edition.</param>
/// <param name="works">Optional. The works the edition belongs to.</param>
/// <param name="contributions">Optional. The contributions of the edition.</param>
/// <returns>The created edition response.</returns>
public OpenLibraryEditionResponse Create(
string? key = null,
string? title = null,
string? subtitle = null,
JsonElement? notes = null,
string? publishDate = null,
List<string>? publishers = null,
List<string>? publishPlaces = null,
int? numberOfPages = null,
string? physicalFormat = null,
string? editionName = null,
List<string>? series = null,
string? volume = null,
List<string>? isbn10 = null,
List<string>? isbn13 = null,
List<string>? lccn = null,
List<string>? oclcNumbers = null,
JsonElement? identifiers = null,
List<string>? sourceRecords = null,
List<OpenLibraryKeyReferenceResponse>? languages = null,
List<OpenLibraryKeyReferenceResponse>? authors = null,
List<OpenLibraryKeyReferenceResponse>? works = null,
List<string>? contributions = null)
{
return new OpenLibraryEditionResponse
{
Key = key ?? $"/books/OL{_faker.Random.Number(1000, 9999)}M",
Title = title ?? _faker.Commerce.ProductName(),
Subtitle = subtitle,
Notes = notes ?? default,
PublishDate = publishDate,
Publishers = publishers ?? [],
PublishPlaces = publishPlaces ?? [],
NumberOfPages = numberOfPages,
PhysicalFormat = physicalFormat,
EditionName = editionName,
Series = series ?? [],
Volume = volume,
Isbn10 = isbn10 ?? [],
Isbn13 = isbn13 ?? [],
Lccn = lccn ?? [],
OclcNumbers = oclcNumbers ?? [],
Identifiers = identifiers ?? default,
SourceRecords = sourceRecords ?? [],
Languages = languages ?? [],
Authors = authors ?? [],
Works = works ?? [],
Contributions = contributions ?? []
};
}
}
@@ -0,0 +1,29 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryKeyReferenceResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryKeyReferenceResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryKeyReferenceResponse"/>.
/// </summary>
/// <param name="key">Optional. The key of the referenced resource.</param>
/// <returns>The created reference response.</returns>
public OpenLibraryKeyReferenceResponse Create(string? key = null)
{
return new OpenLibraryKeyReferenceResponse
{
Key = key ?? $"/works/OL{_faker.Random.Number(1000, 9999)}W"
};
}
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryRatingSummaryResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryRatingSummaryResponseFixture
{
/// <summary>
/// Creates a random valid <see cref="OpenLibraryRatingSummaryResponse"/>.
/// </summary>
/// <param name="average">Optional. The average rating of the work.</param>
/// <param name="count">Optional. The number of ratings of the work.</param>
/// <returns>The created rating summary response.</returns>
public OpenLibraryRatingSummaryResponse Create(decimal? average = null, int? count = null)
{
return new OpenLibraryRatingSummaryResponse
{
Average = average ?? 4.5m,
Count = count ?? 100
};
}
}
@@ -0,0 +1,28 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryRatingsResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryRatingsResponseFixture
{
private readonly OpenLibraryRatingSummaryResponseFixture _ratingSummaryResponseFixture = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryRatingsResponse"/>.
/// </summary>
/// <param name="summary">Optional. The summary of the ratings of the work.</param>
/// <returns>The created ratings response.</returns>
public OpenLibraryRatingsResponse Create(OpenLibraryRatingSummaryResponse? summary = null)
{
return new OpenLibraryRatingsResponse
{
Summary = summary ?? _ratingSummaryResponseFixture.Create()
};
}
}
@@ -0,0 +1,88 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibrarySearchDocumentResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibrarySearchDocumentResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibrarySearchDocumentResponse"/>.
/// </summary>
/// <param name="key">Optional. The key of the search document.</param>
/// <param name="title">Optional. The title of the search document.</param>
/// <param name="authorNames">Optional. The author names of the search document.</param>
/// <param name="authorKeys">Optional. The author keys of the search document.</param>
/// <param name="firstPublishYear">Optional. The first publication year of the search document.</param>
/// <param name="editionKeys">Optional. The edition keys of the search document.</param>
/// <param name="isbns">Optional. The ISBNs of the search document.</param>
/// <param name="languages">Optional. The languages of the search document.</param>
/// <param name="publishers">Optional. The publishers of the search document.</param>
/// <param name="subjects">Optional. The subjects of the search document.</param>
/// <param name="publishPlaces">Optional. The publication places of the search document.</param>
/// <param name="numberOfPagesMedian">Optional. The median number of pages of the search document.</param>
/// <param name="ratingsAverage">Optional. The average rating of the search document.</param>
/// <param name="ratingsCount">Optional. The number of ratings of the search document.</param>
/// <param name="amazonIds">Optional. The Amazon identifiers of the search document.</param>
/// <param name="goodreadsIds">Optional. The Goodreads identifiers of the search document.</param>
/// <param name="googleIds">Optional. The Google identifiers of the search document.</param>
/// <param name="libraryThingIds">Optional. The LibraryThing identifiers of the search document.</param>
/// <param name="lccn">Optional. The LCCN identifiers of the search document.</param>
/// <param name="oclc">Optional. The OCLC identifiers of the search document.</param>
/// <returns>The created search document response.</returns>
public OpenLibrarySearchDocumentResponse Create(
string? key = null,
string? title = null,
List<string>? authorNames = null,
List<string>? authorKeys = null,
int? firstPublishYear = null,
List<string>? editionKeys = null,
List<string>? isbns = null,
List<string>? languages = null,
List<string>? publishers = null,
List<string>? subjects = null,
List<string>? publishPlaces = null,
int? numberOfPagesMedian = null,
decimal? ratingsAverage = null,
int? ratingsCount = null,
List<string>? amazonIds = null,
List<string>? goodreadsIds = null,
List<string>? googleIds = null,
List<string>? libraryThingIds = null,
List<string>? lccn = null,
List<string>? oclc = null)
{
return new OpenLibrarySearchDocumentResponse
{
Key = key ?? $"/works/OL{_faker.Random.Number(1000, 9999)}W",
Title = title ?? _faker.Commerce.ProductName(),
AuthorNames = authorNames ?? [],
AuthorKeys = authorKeys ?? [],
FirstPublishYear = firstPublishYear,
EditionKeys = editionKeys ?? [],
Isbns = isbns ?? [],
Languages = languages ?? [],
Publishers = publishers ?? [],
Subjects = subjects ?? [],
PublishPlaces = publishPlaces ?? [],
NumberOfPagesMedian = numberOfPagesMedian,
RatingsAverage = ratingsAverage,
RatingsCount = ratingsCount,
AmazonIds = amazonIds ?? [],
GoodreadsIds = goodreadsIds ?? [],
GoogleIds = googleIds ?? [],
LibraryThingIds = libraryThingIds ?? [],
Lccn = lccn ?? [],
Oclc = oclc ?? []
};
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryWorkAuthorResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryWorkAuthorResponseFixture
{
private readonly Faker _faker = new();
private readonly OpenLibraryKeyReferenceResponseFixture _keyReferenceResponseFixture = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryWorkAuthorResponse"/>.
/// </summary>
/// <param name="author">Optional. The author reference of the work.</param>
/// <param name="key">Optional. The direct key of the author reference.</param>
/// <returns>The created work author response.</returns>
public OpenLibraryWorkAuthorResponse Create(
OpenLibraryKeyReferenceResponse? author = null,
string? key = null)
{
return new OpenLibraryWorkAuthorResponse
{
Author = author ?? _keyReferenceResponseFixture.Create(key: $"/authors/OL{_faker.Random.Number(1000, 9999)}A"),
Key = key
};
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.Contracts.Responses;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.Contracts.Responses;
/// <summary>
/// Fixture class for the <see cref="OpenLibraryWorkResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibraryWorkResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibraryWorkResponse"/>.
/// </summary>
/// <param name="key">Optional. The key of the work.</param>
/// <param name="title">Optional. The title of the work.</param>
/// <param name="originalTitle">Optional. The original title of the work.</param>
/// <param name="description">Optional. The description of the work.</param>
/// <param name="firstPublishDate">Optional. The first publication date of the work.</param>
/// <param name="subjects">Optional. The subjects of the work.</param>
/// <param name="genres">Optional. The genres of the work.</param>
/// <param name="authors">Optional. The authors of the work.</param>
/// <param name="originalLanguages">Optional. The original languages of the work.</param>
/// <returns>The created work response.</returns>
public OpenLibraryWorkResponse Create(
string? key = null,
string? title = null,
string? originalTitle = null,
JsonElement? description = null,
string? firstPublishDate = null,
List<string>? subjects = null,
List<string>? genres = null,
List<OpenLibraryWorkAuthorResponse>? authors = null,
List<OpenLibraryKeyReferenceResponse>? originalLanguages = null)
{
return new OpenLibraryWorkResponse
{
Key = key ?? $"/works/OL{_faker.Random.Number(1000, 9999)}W",
Title = title ?? _faker.Commerce.ProductName(),
OriginalTitle = originalTitle,
Description = description ?? default,
FirstPublishDate = firstPublishDate,
Subjects = subjects ?? [],
Genres = genres ?? [],
Authors = authors ?? [],
OriginalLanguages = originalLanguages ?? []
};
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Plugins.OpenLibrary.Common.Models.DTO.Settings;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Models.DTO.Settings;
/// <summary>
/// Fixture class for the <see cref="OpenLibrarySettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
internal class OpenLibrarySettingsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="OpenLibrarySettingsDto"/>.
/// </summary>
/// <param name="userAgent">Optional. The user agent sent with every request.</param>
/// <param name="contactEmail">Optional. The contact email sent with every request.</param>
/// <param name="searchResultLimit">Optional. The maximum number of search results.</param>
/// <param name="workEditionLimit">Optional. The maximum number of editions fetched per work.</param>
/// <param name="minimumRequestInterval">Optional. The minimum interval between consecutive requests.</param>
/// <returns>The created <see cref="OpenLibrarySettingsDto"/>.</returns>
public OpenLibrarySettingsDto Create(
string? userAgent = null,
string? contactEmail = null,
int? searchResultLimit = null,
int? workEditionLimit = null,
TimeSpan? minimumRequestInterval = null)
{
return new OpenLibrarySettingsDto
{
UserAgent = userAgent ?? _faker.Internet.UserAgent(),
ContactEmail = contactEmail,
SearchResultLimit = searchResultLimit ?? _faker.Random.Number(1, 50),
WorkEditionLimit = workEditionLimit ?? _faker.Random.Number(1, 200),
MinimumRequestInterval = minimumRequestInterval ?? TimeSpan.FromMilliseconds(_faker.Random.Number(100, 2000))
};
}
}
@@ -0,0 +1,81 @@
#region ========================================================================= USING =====================================================================================
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
#endregion
namespace Lumina.Plugins.OpenLibrary.Fixtures.Common.Setup;
/// <summary>
/// <see cref="HttpMessageHandler"/> test double that routes requests to the configured responses based on their absolute path.
/// </summary>
[ExcludeFromCodeCoverage]
internal class StubOpenLibraryHttpMessageHandler : HttpMessageHandler
{
private readonly List<(Func<HttpRequestMessage, bool> Matches, Func<HttpRequestMessage, HttpResponseMessage> ResponseFactory)> _routes = [];
/// <summary>
/// Gets the list of requests that were sent through this handler.
/// </summary>
public List<HttpRequestMessage> Requests { get; } = [];
/// <summary>
/// Routes requests with the given absolute path to the provided JSON response.
/// </summary>
/// <param name="absolutePath">The absolute path of the request URL to match.</param>
/// <param name="json">The JSON payload of the response.</param>
/// <returns>This handler, for chaining.</returns>
public StubOpenLibraryHttpMessageHandler MapPath(string absolutePath, string json)
{
return AddRoute(
request => string.Equals(request.RequestUri?.AbsolutePath, absolutePath, StringComparison.Ordinal),
_ => CreateJsonResponse(HttpStatusCode.OK, json));
}
/// <summary>
/// Routes requests matching the given predicate to the response produced by the provided factory.
/// </summary>
/// <param name="matches">The predicate that determines whether the request matches the route.</param>
/// <param name="responseFactory">The factory that produces the response for a matching request.</param>
/// <returns>This handler, for chaining.</returns>
public StubOpenLibraryHttpMessageHandler AddRoute(Func<HttpRequestMessage, bool> matches, Func<HttpRequestMessage, HttpResponseMessage> responseFactory)
{
_routes.Add((matches, responseFactory));
return this;
}
/// <summary>
/// Creates a JSON response with the given status code and payload.
/// </summary>
/// <param name="statusCode">The status code of the response.</param>
/// <param name="json">The JSON payload of the response.</param>
/// <returns>The created JSON response.</returns>
public static HttpResponseMessage CreateJsonResponse(HttpStatusCode statusCode, string json)
{
return new HttpResponseMessage(statusCode)
{
Content = new StringContent(json, Encoding.UTF8, "application/json")
};
}
/// <summary>
/// Sends the request to the first matching route, or returns a not found response.
/// </summary>
/// <param name="request">The HTTP request message to send.</param>
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
/// <returns>The HTTP response message for the request.</returns>
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
Requests.Add(request);
foreach ((Func<HttpRequestMessage, bool> matches, Func<HttpRequestMessage, HttpResponseMessage> responseFactory) in _routes)
if (matches(request))
return Task.FromResult(responseFactory(request));
return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound));
}
}
@@ -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" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Bogus" Version="35.6.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\plugins\Lumina.Plugins.OpenLibrary\Lumina.Plugins.OpenLibrary.csproj" />
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,20 @@
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.OpenLibrary.Fixtures")]
[assembly: AssemblyProduct("Lumina.Plugins.OpenLibrary.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("A1B2C3D4-0002-4A5B-9C0D-222222222222")]
[assembly: InternalsVisibleTo("Lumina.Plugins.OpenLibrary.UnitTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -0,0 +1,21 @@
<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="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Plugins.Contracts\Lumina.Plugins.Contracts.csproj" />
</ItemGroup>
</Project>
Loaded 100 of 509 files, more files were not shown because too many files have changed in this diff. Show more