Adds the shared fixtures for the theming feature tests

This commit is contained in:
BinaryAlley committed 2026-08-21 09:42:57 -07:00
1 parent 07bc20a9e6
commit 9c83e5dfa7
34 files changed
+1710

No files matched your search

@@ -0,0 +1,110 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
/// <summary>
/// Fixture class for the <see cref="ThemeEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThemeEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="ThemeEntity"/>.
/// </summary>
/// <param name="id">Optional database Id of the theme.</param>
/// <param name="themeId">Optional manifest id of the theme.</param>
/// <param name="name">Optional display name of the theme.</param>
/// <param name="description">Optional description of the theme.</param>
/// <param name="author">Optional author of the theme.</param>
/// <param name="version">Optional version of the theme.</param>
/// <param name="previewPath">Optional preview image path of the theme, or <see langword="null"/> when the theme has no preview.</param>
/// <param name="includePreviewPath">Whether to set <paramref name="previewPath"/>, or <see langword="null"/> when <see langword="false"/>.</param>
/// <param name="installSource">Optional source the theme was installed from.</param>
/// <param name="isCurrent">Optional value indicating whether the theme is the currently active one.</param>
/// <param name="includeIsCurrent">Whether to set <paramref name="isCurrent"/>, or <see langword="null"/> when <see langword="false"/>.</param>
/// <param name="isDeleted">Optional value indicating whether the theme was soft deleted.</param>
/// <param name="installedAtUtc">Optional UTC timestamp when the theme was installed.</param>
/// <param name="createdOnUtc">Optional UTC timestamp when the entity was created.</param>
/// <param name="createdBy">Optional Id of the user that created the entity.</param>
/// <param name="updatedOnUtc">Optional UTC timestamp when the entity was updated.</param>
/// <param name="includeUpdatedOnUtc">Whether to set <paramref name="updatedOnUtc"/>, or <see langword="null"/> when <see langword="false"/>.</param>
/// <param name="updatedBy">Optional Id of the user that updated the entity.</param>
/// <param name="includeUpdatedBy">Whether to set <paramref name="updatedBy"/>, or <see langword="null"/> when <see langword="false"/>.</param>
/// <returns>A configured <see cref="ThemeEntity"/> instance.</returns>
public ThemeEntity Create(
Guid? id = null,
string? themeId = null,
string? name = null,
string? description = null,
string? author = null,
string? version = null,
string? previewPath = null,
bool includePreviewPath = false,
ThemeInstallSource? installSource = null,
bool? isCurrent = null,
bool includeIsCurrent = false,
bool? isDeleted = null,
DateTime? installedAtUtc = null,
DateTime? createdOnUtc = null,
Guid? createdBy = null,
DateTime? updatedOnUtc = null,
bool includeUpdatedOnUtc = false,
Guid? updatedBy = null,
bool includeUpdatedBy = false)
{
Guid resolvedCreatedBy = createdBy ?? Guid.NewGuid();
return new Faker<ThemeEntity>()
.CustomInstantiator(f => new ThemeEntity
{
Id = default,
ThemeId = default!,
Name = default!,
Description = default!,
Author = default!,
Version = default!,
PreviewPath = default,
InstallSource = default,
IsCurrent = default,
IsDeleted = default,
InstalledAtUtc = default,
CreatedOnUtc = default,
CreatedBy = default,
UpdatedOnUtc = default,
UpdatedBy = default
})
.RuleFor(theme => theme.Id, f => id ?? f.Random.Guid())
.RuleFor(theme => theme.ThemeId, f => themeId ?? f.Lorem.Slug(2))
.RuleFor(theme => theme.Name, f => name ?? f.Commerce.ProductName())
.RuleFor(theme => theme.Description, f => description ?? f.Lorem.Sentence())
.RuleFor(theme => theme.Author, f => author ?? f.Name.FullName())
.RuleFor(theme => theme.Version, f => version ?? f.System.Semver())
.RuleFor(theme => theme.PreviewPath, f => includePreviewPath ? (previewPath ?? f.System.FilePath()) : null)
.RuleFor(theme => theme.InstallSource, f => installSource ?? f.PickRandom<ThemeInstallSource>())
.RuleFor(theme => theme.IsCurrent, f => includeIsCurrent ? (isCurrent ?? (f.Random.Bool() ? true : null)) : null)
.RuleFor(theme => theme.IsDeleted, f => isDeleted ?? f.Random.Bool())
.RuleFor(theme => theme.InstalledAtUtc, f => installedAtUtc ?? f.Date.Recent().ToUniversalTime())
.RuleFor(theme => theme.CreatedOnUtc, f => createdOnUtc ?? f.Date.Past().ToUniversalTime())
.RuleFor(theme => theme.CreatedBy, resolvedCreatedBy)
.RuleFor(theme => theme.UpdatedOnUtc, f => includeUpdatedOnUtc ? (updatedOnUtc ?? f.Date.Recent().ToUniversalTime()) : null)
.RuleFor(theme => theme.UpdatedBy, f => includeUpdatedBy ? (updatedBy ?? f.Random.Guid()) : null)
.Generate();
}
/// <summary>
/// Creates a list of <see cref="ThemeEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ThemeEntity"/> instances.</returns>
public List<ThemeEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,74 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
/// <summary>
/// Fixture class for the <see cref="ThemeManifestDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThemeManifestDtoFixture
{
/// <summary>
/// Creates a random valid <see cref="ThemeManifestDto"/>.
/// </summary>
/// <param name="schemaVersion">Optional schema version of the manifest.</param>
/// <param name="id">Optional unique identifier of the theme.</param>
/// <param name="name">Optional display name of the theme.</param>
/// <param name="description">Optional description of the theme.</param>
/// <param name="author">Optional author of the theme.</param>
/// <param name="version">Optional version of the theme.</param>
/// <param name="preview">Optional preview image path of the theme, or <see langword="null"/> when the theme has no preview.</param>
/// <param name="includePreview">Whether to set <paramref name="preview"/>, or <see langword="null"/> when <see langword="false"/>.</param>
/// <param name="templates">Optional template mappings of the theme.</param>
/// <returns>A configured <see cref="ThemeManifestDto"/> instance.</returns>
public ThemeManifestDto Create(
int? schemaVersion = null,
string? id = null,
string? name = null,
string? description = null,
string? author = null,
string? version = null,
string? preview = null,
bool includePreview = false,
Dictionary<string, string>? templates = null)
{
return new Faker<ThemeManifestDto>()
.CustomInstantiator(f => new ThemeManifestDto
{
SchemaVersion = default,
Id = default!,
Name = default!,
Description = default!,
Author = default!,
Version = default!,
Preview = default,
Templates = default!
})
.RuleFor(manifest => manifest.SchemaVersion, f => schemaVersion ?? f.Random.Int(1, 5))
.RuleFor(manifest => manifest.Id, f => id ?? f.Lorem.Slug(2))
.RuleFor(manifest => manifest.Name, f => name ?? f.Commerce.ProductName())
.RuleFor(manifest => manifest.Description, f => description ?? f.Lorem.Sentence())
.RuleFor(manifest => manifest.Author, f => author ?? f.Name.FullName())
.RuleFor(manifest => manifest.Version, f => version ?? f.System.Semver())
.RuleFor(manifest => manifest.Preview, f => includePreview ? (preview ?? (f.Random.Bool() ? f.System.FilePath() : null)) : null)
.RuleFor(manifest => manifest.Templates, f => templates ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) { ["home"] = "templates/home.html" })
.Generate();
}
/// <summary>
/// Creates a list of <see cref="ThemeManifestDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="ThemeManifestDto"/> instances.</returns>
public List<ThemeManifestDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Commands.DeleteTheme;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Commands.DeleteTheme;
/// <summary>
/// Fixture class for the <see cref="DeleteThemeCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class DeleteThemeCommandFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="DeleteThemeCommand"/>.
/// </summary>
/// <param name="themeId">Optional manifest id of the theme to delete.</param>
/// <returns>The created <see cref="DeleteThemeCommand"/>.</returns>
public DeleteThemeCommand Create(string? themeId = null)
{
return new DeleteThemeCommand(themeId ?? _faker.Lorem.Slug(2));
}
/// <summary>
/// Creates a list of <see cref="DeleteThemeCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<DeleteThemeCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Commands.InstallTheme;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Commands.InstallTheme;
/// <summary>
/// Fixture class for the <see cref="InstallThemeCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class InstallThemeCommandFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="InstallThemeCommand"/>.
/// </summary>
/// <param name="archive">Optional ZIP archive stream of the theme pack.</param>
/// <param name="fileName">Optional file name of the uploaded archive.</param>
/// <returns>The created <see cref="InstallThemeCommand"/>.</returns>
public InstallThemeCommand Create(Stream? archive = null, string? fileName = null)
{
Stream resolvedArchive = archive ?? new MemoryStream(Encoding.UTF8.GetBytes(_faker.Lorem.Paragraph()));
return new InstallThemeCommand(resolvedArchive, fileName ?? $"{_faker.Lorem.Word()}.zip");
}
/// <summary>
/// Creates a list of <see cref="InstallThemeCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<InstallThemeCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Commands.SetCurrentTheme;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Commands.SetCurrentTheme;
/// <summary>
/// Fixture class for the <see cref="SetCurrentThemeCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetCurrentThemeCommandFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="SetCurrentThemeCommand"/>.
/// </summary>
/// <param name="themeId">Optional manifest id of the theme to activate.</param>
/// <returns>The created <see cref="SetCurrentThemeCommand"/>.</returns>
public SetCurrentThemeCommand Create(string? themeId = null)
{
return new SetCurrentThemeCommand(themeId ?? _faker.Lorem.Slug(2));
}
/// <summary>
/// Creates a list of <see cref="SetCurrentThemeCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<SetCurrentThemeCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Themes.Management.Queries.GetCurrentTheme;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetCurrentTheme;
/// <summary>
/// Fixture class for the <see cref="GetCurrentThemeQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetCurrentThemeQueryFixture
{
/// <summary>
/// Creates a <see cref="GetCurrentThemeQuery"/>.
/// </summary>
/// <returns>The created <see cref="GetCurrentThemeQuery"/>.</returns>
public GetCurrentThemeQuery Create()
{
return new GetCurrentThemeQuery();
}
/// <summary>
/// Creates a list of <see cref="GetCurrentThemeQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetCurrentThemeQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Queries.GetThemeArchive;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeArchive;
/// <summary>
/// Fixture class for the <see cref="GetThemeArchiveQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeArchiveQueryFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetThemeArchiveQuery"/>.
/// </summary>
/// <param name="themeId">Optional manifest id of the theme.</param>
/// <returns>The created <see cref="GetThemeArchiveQuery"/>.</returns>
public GetThemeArchiveQuery Create(string? themeId = null)
{
return new GetThemeArchiveQuery(themeId ?? _faker.Lorem.Slug(2));
}
/// <summary>
/// Creates a list of <see cref="GetThemeArchiveQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThemeArchiveQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Queries.GetThemeAsset;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeAsset;
/// <summary>
/// Fixture class for the <see cref="GetThemeAssetQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeAssetQueryFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetThemeAssetQuery"/>.
/// </summary>
/// <param name="themeId">Optional manifest id of the theme.</param>
/// <param name="assetPath">Optional asset path relative to the theme pack root.</param>
/// <returns>The created <see cref="GetThemeAssetQuery"/>.</returns>
public GetThemeAssetQuery Create(string? themeId = null, string? assetPath = null)
{
return new GetThemeAssetQuery(
themeId ?? _faker.Lorem.Slug(2),
assetPath ?? _faker.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="GetThemeAssetQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThemeAssetQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Themes.Management.Queries.GetThemeSettings;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeSettings;
/// <summary>
/// Fixture class for the <see cref="GetThemeSettingsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeSettingsQueryFixture
{
/// <summary>
/// Creates a <see cref="GetThemeSettingsQuery"/>.
/// </summary>
/// <returns>The created <see cref="GetThemeSettingsQuery"/>.</returns>
public GetThemeSettingsQuery Create()
{
return new GetThemeSettingsQuery();
}
/// <summary>
/// Creates a list of <see cref="GetThemeSettingsQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThemeSettingsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Themes.Management.Queries.GetThemeTemplate;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemeTemplate;
/// <summary>
/// Fixture class for the <see cref="GetThemeTemplateQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemeTemplateQueryFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GetThemeTemplateQuery"/>.
/// </summary>
/// <param name="themeId">Optional manifest id of the theme.</param>
/// <param name="pageKey">Optional page key that selects the template.</param>
/// <returns>The created <see cref="GetThemeTemplateQuery"/>.</returns>
public GetThemeTemplateQuery Create(string? themeId = null, string? pageKey = null)
{
return new GetThemeTemplateQuery(
themeId ?? _faker.Lorem.Slug(2),
pageKey ?? _faker.Lorem.Word());
}
/// <summary>
/// Creates a list of <see cref="GetThemeTemplateQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThemeTemplateQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Themes.Management.Queries.GetThemes;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemes;
/// <summary>
/// Fixture class for the <see cref="GetThemesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThemesQueryFixture
{
/// <summary>
/// Creates a <see cref="GetThemesQuery"/>.
/// </summary>
/// <returns>The created <see cref="GetThemesQuery"/>.</returns>
public GetThemesQuery Create()
{
return new GetThemesQuery();
}
/// <summary>
/// Creates a list of <see cref="GetThemesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThemesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}