mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 20:01:10 +00:00
Adds the shared fixtures for the theming feature tests
This commit is contained in:
1 parent
07bc20a9e6
commit
9c83e5dfa7
34 files changed
+1710
No files matched your search
+110
@@ -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())];
|
||||
}
|
||||
}
|
||||
+74
@@ -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())];
|
||||
}
|
||||
}
|
||||
+38
@@ -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())];
|
||||
}
|
||||
}
|
||||
+42
@@ -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())];
|
||||
}
|
||||
}
|
||||
+38
@@ -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())];
|
||||
}
|
||||
}
|
||||
+34
@@ -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())];
|
||||
}
|
||||
}
|
||||
+38
@@ -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())];
|
||||
}
|
||||
}
|
||||
+41
@@ -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())];
|
||||
}
|
||||
}
|
||||
+34
@@ -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())];
|
||||
}
|
||||
}
|
||||
+41
@@ -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())];
|
||||
}
|
||||
}
|
||||
+34
@@ -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())];
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="DeleteThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteThemeRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="DeleteThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme to delete.</param>
|
||||
/// <returns>The created <see cref="DeleteThemeRequest"/>.</returns>
|
||||
public DeleteThemeRequest Create(string? themeId = null)
|
||||
{
|
||||
return new DeleteThemeRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="DeleteThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<DeleteThemeRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetThemeArchiveRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeArchiveRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetThemeArchiveRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <returns>The created <see cref="GetThemeArchiveRequest"/>.</returns>
|
||||
public GetThemeArchiveRequest Create(string? themeId = null)
|
||||
{
|
||||
return new GetThemeArchiveRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetThemeArchiveRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetThemeArchiveRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetThemeAssetRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeAssetRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetThemeAssetRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="assetPath">Optional. The asset path relative to the theme pack root.</param>
|
||||
/// <returns>The created <see cref="GetThemeAssetRequest"/>.</returns>
|
||||
public GetThemeAssetRequest Create(string? themeId = null, string? assetPath = null)
|
||||
{
|
||||
return new GetThemeAssetRequest(
|
||||
themeId ?? _faker.Lorem.Slug(2),
|
||||
assetPath ?? _faker.System.FilePath());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetThemeAssetRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetThemeAssetRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="GetThemeTemplateRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeTemplateRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="GetThemeTemplateRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="pageKey">Optional. The page key that selects the template.</param>
|
||||
/// <returns>The created <see cref="GetThemeTemplateRequest"/>.</returns>
|
||||
public GetThemeTemplateRequest Create(string? themeId = null, string? pageKey = null)
|
||||
{
|
||||
return new GetThemeTemplateRequest(
|
||||
themeId ?? _faker.Lorem.Slug(2),
|
||||
pageKey ?? _faker.Lorem.Word());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="GetThemeTemplateRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<GetThemeTemplateRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="SetCurrentThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetCurrentThemeRequestFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="SetCurrentThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme to activate.</param>
|
||||
/// <returns>The created <see cref="SetCurrentThemeRequest"/>.</returns>
|
||||
public SetCurrentThemeRequest Create(string? themeId = null)
|
||||
{
|
||||
return new SetCurrentThemeRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="SetCurrentThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<SetCurrentThemeRequest> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeArchiveResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeArchiveResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeArchiveResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="bytes">Optional. The bytes of the ZIP archive.</param>
|
||||
/// <param name="fileName">Optional. The file name to expose when downloading the archive.</param>
|
||||
/// <param name="contentType">Optional. The MIME content type of the archive.</param>
|
||||
/// <returns>The created <see cref="ThemeArchiveResponse"/>.</returns>
|
||||
public ThemeArchiveResponse Create(byte[]? bytes = null, string? fileName = null, string? contentType = null)
|
||||
{
|
||||
return new ThemeArchiveResponse(
|
||||
bytes ?? Encoding.UTF8.GetBytes(_faker.Lorem.Paragraph()),
|
||||
fileName ?? $"{_faker.Lorem.Word()}.zip",
|
||||
contentType ?? _faker.System.MimeType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeArchiveResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeArchiveResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeAssetResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeAssetResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeAssetResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="bytes">Optional. The bytes of the asset file.</param>
|
||||
/// <param name="contentType">Optional. The MIME content type of the asset file.</param>
|
||||
/// <returns>The created <see cref="ThemeAssetResponse"/>.</returns>
|
||||
public ThemeAssetResponse Create(byte[]? bytes = null, string? contentType = null)
|
||||
{
|
||||
return new ThemeAssetResponse(
|
||||
bytes ?? Encoding.UTF8.GetBytes(_faker.Lorem.Paragraph()),
|
||||
contentType ?? _faker.System.MimeType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeAssetResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeAssetResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The Id of the theme.</param>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="name">Optional. The display name of the theme.</param>
|
||||
/// <param name="description">Optional. The description of the theme.</param>
|
||||
/// <param name="author">Optional. The author of the theme.</param>
|
||||
/// <param name="version">Optional. The version of the theme.</param>
|
||||
/// <param name="previewPath">Optional. The 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. The source the theme was installed from.</param>
|
||||
/// <param name="isCurrent">Optional. 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="installedAtUtc">Optional. The UTC timestamp when the theme was installed.</param>
|
||||
/// <returns>The created <see cref="ThemeResponse"/>.</returns>
|
||||
public ThemeResponse 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,
|
||||
DateTime? installedAtUtc = null)
|
||||
{
|
||||
return new ThemeResponse(
|
||||
id ?? Guid.NewGuid(),
|
||||
themeId ?? _faker.Lorem.Slug(2),
|
||||
name ?? _faker.Commerce.ProductName(),
|
||||
description ?? _faker.Lorem.Sentence(),
|
||||
author ?? _faker.Name.FullName(),
|
||||
version ?? _faker.System.Semver(),
|
||||
includePreviewPath ? (previewPath ?? (_faker.Random.Bool() ? _faker.System.FilePath() : null)) : null,
|
||||
installSource ?? _faker.PickRandom<ThemeInstallSource>(),
|
||||
includeIsCurrent ? (isCurrent ?? (_faker.Random.Bool() ? true : null)) : null,
|
||||
installedAtUtc ?? _faker.Date.Recent().ToUniversalTime());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeSettingsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeSettingsResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeSettingsResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="maxArchiveBytes">Optional. The maximum allowed size of a theme archive, in bytes.</param>
|
||||
/// <param name="allowThemeScripts">Optional. Whether theme templates may contain script elements.</param>
|
||||
/// <param name="defaultThemeId">Optional. The identifier of the default theme.</param>
|
||||
/// <returns>The created <see cref="ThemeSettingsResponse"/>.</returns>
|
||||
public ThemeSettingsResponse Create(
|
||||
long? maxArchiveBytes = null,
|
||||
bool? allowThemeScripts = null,
|
||||
string? defaultThemeId = null)
|
||||
{
|
||||
return new ThemeSettingsResponse(
|
||||
maxArchiveBytes ?? _faker.Random.Long(1_000_000, 100_000_000),
|
||||
allowThemeScripts ?? _faker.Random.Bool(),
|
||||
defaultThemeId ?? _faker.Lorem.Slug(2));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeSettingsResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeSettingsResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.Responses.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="ThemeTemplateResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeTemplateResponseFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly ThemeResponseFixture _themeResponseFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeTemplateResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="theme">Optional. The theme the template belongs to.</param>
|
||||
/// <param name="template">Optional. The sanitized content of the template.</param>
|
||||
/// <returns>The created <see cref="ThemeTemplateResponse"/>.</returns>
|
||||
public ThemeTemplateResponse Create(ThemeResponse? theme = null, string? template = null)
|
||||
{
|
||||
return new ThemeTemplateResponse(
|
||||
theme ?? _themeResponseFixture.Create(),
|
||||
template ?? _faker.Lorem.Paragraph());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeTemplateResponse"/>.
|
||||
/// </summary>
|
||||
/// <param name="count">The number of elements to create.</param>
|
||||
/// <returns>The created list.</returns>
|
||||
public List<ThemeTemplateResponse> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#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="ThemeEngineOptionsDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeEngineOptionsDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="ThemeEngineOptionsDto"/>.
|
||||
/// </summary>
|
||||
/// <param name="storagePath">Optional directory where installed theme packs are stored.</param>
|
||||
/// <param name="bundledThemesPath">Optional directory where the shipped theme pack archives are located.</param>
|
||||
/// <param name="defaultThemeId">Optional identifier of the default theme.</param>
|
||||
/// <param name="maxArchiveBytes">Optional maximum size of an uploaded theme archive, in bytes.</param>
|
||||
/// <param name="maxExpandedBytes">Optional maximum total size of an extracted theme pack, in bytes.</param>
|
||||
/// <param name="maxSingleFileBytes">Optional maximum size of a single file within a theme pack, in bytes.</param>
|
||||
/// <param name="maxEntries">Optional maximum number of entries in a theme pack archive.</param>
|
||||
/// <param name="allowThemeScripts">Optional value indicating whether script elements are allowed.</param>
|
||||
/// <returns>A configured <see cref="ThemeEngineOptionsDto"/> instance.</returns>
|
||||
public ThemeEngineOptionsDto Create(
|
||||
string? storagePath = null,
|
||||
string? bundledThemesPath = null,
|
||||
string? defaultThemeId = null,
|
||||
long? maxArchiveBytes = null,
|
||||
long? maxExpandedBytes = null,
|
||||
long? maxSingleFileBytes = null,
|
||||
int? maxEntries = null,
|
||||
bool? allowThemeScripts = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeEngineOptionsDto
|
||||
{
|
||||
StoragePath = storagePath ?? faker.System.DirectoryPath(),
|
||||
BundledThemesPath = bundledThemesPath ?? faker.System.DirectoryPath(),
|
||||
DefaultThemeId = defaultThemeId ?? faker.Lorem.Word(),
|
||||
MaxArchiveBytes = maxArchiveBytes ?? faker.Random.Long(1_000_000, 100_000_000),
|
||||
MaxExpandedBytes = maxExpandedBytes ?? faker.Random.Long(10_000_000, 500_000_000),
|
||||
MaxSingleFileBytes = maxSingleFileBytes ?? faker.Random.Long(1_000_000, 50_000_000),
|
||||
MaxEntries = maxEntries ?? faker.Random.Int(1, 1000),
|
||||
AllowThemeScripts = allowThemeScripts ?? faker.Random.Bool()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a list of <see cref="ThemeEngineOptionsDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeEngineOptionsDto"/> instances.</returns>
|
||||
public List<ThemeEngineOptionsDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Describes a single entry of a theme pack ZIP archive built by the <see cref="ThemePackFixture"/>.
|
||||
/// </summary>
|
||||
/// <param name="Path">The entry path inside the archive.</param>
|
||||
/// <param name="Content">The text content of the entry.</param>
|
||||
/// <param name="UnixFileType">Optional Unix file type for the entry, used to simulate special file types such as symbolic links.</param>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed record ThemeArchiveEntry(string Path, string Content, int? UnixFileType = null);
|
||||
@@ -0,0 +1,148 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Infrastructure.Fixtures.Core.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating theme pack ZIP archives used by theme tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class ThemePackFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a valid theme pack ZIP archive containing a manifest, the template files referenced by it and a preview asset.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional theme id written to the manifest.</param>
|
||||
/// <param name="name">Optional display name written to the manifest.</param>
|
||||
/// <param name="description">Optional description written to the manifest.</param>
|
||||
/// <param name="author">Optional author written to the manifest.</param>
|
||||
/// <param name="version">Optional version written to the manifest.</param>
|
||||
/// <param name="schemaVersion">Optional schema version written to the manifest.</param>
|
||||
/// <param name="templates">Optional template mappings written to the manifest.</param>
|
||||
/// <param name="preview">Optional preview path written to the manifest, or <see langword="null"/> to omit the preview.</param>
|
||||
/// <param name="defaultTemplateContent">Optional content for the default template file.</param>
|
||||
/// <param name="includePreviewAsset">Whether to include the preview asset file in the archive.</param>
|
||||
/// <param name="additionalFiles">Optional additional files written into the archive.</param>
|
||||
/// <returns>The created theme pack ZIP archive.</returns>
|
||||
public byte[] Create(
|
||||
string themeId = "test-theme",
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string? author = null,
|
||||
string? version = null,
|
||||
int? schemaVersion = null,
|
||||
Dictionary<string, string>? templates = null,
|
||||
string? preview = "assets/preview.png",
|
||||
string? defaultTemplateContent = null,
|
||||
bool includePreviewAsset = true,
|
||||
IReadOnlyDictionary<string, string>? additionalFiles = null)
|
||||
{
|
||||
Dictionary<string, string> manifestTemplates = templates ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["default"] = "templates/default.html"
|
||||
};
|
||||
|
||||
string manifestJson = CreateManifestJson(
|
||||
themeId,
|
||||
name,
|
||||
description,
|
||||
author,
|
||||
version,
|
||||
schemaVersion,
|
||||
manifestTemplates,
|
||||
preview);
|
||||
|
||||
List<ThemeArchiveEntry> entries = [new("theme.json", manifestJson)];
|
||||
foreach ((string key, string templatePath) in manifestTemplates)
|
||||
entries.Add(new(templatePath, defaultTemplateContent ?? $"<html><body>{key} template</body></html>"));
|
||||
|
||||
if (preview is not null && includePreviewAsset)
|
||||
entries.Add(new("assets/preview.png", "preview-image-bytes"));
|
||||
|
||||
if (additionalFiles is not null)
|
||||
entries.AddRange(additionalFiles.Select(file => new ThemeArchiveEntry(file.Key, file.Value)));
|
||||
|
||||
return CreateArchive([.. entries]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the JSON content of a theme manifest with test defaults that can be overridden per field.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional theme id written to the manifest.</param>
|
||||
/// <param name="name">Optional display name written to the manifest.</param>
|
||||
/// <param name="description">Optional description written to the manifest.</param>
|
||||
/// <param name="author">Optional author written to the manifest.</param>
|
||||
/// <param name="version">Optional version written to the manifest.</param>
|
||||
/// <param name="schemaVersion">Optional schema version written to the manifest.</param>
|
||||
/// <param name="templates">Optional template mappings written to the manifest.</param>
|
||||
/// <param name="preview">Optional preview path written to the manifest, or <see langword="null"/> to omit the preview.</param>
|
||||
/// <returns>The created manifest JSON content.</returns>
|
||||
public string CreateManifestJson(
|
||||
string themeId = "test-theme",
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string? author = null,
|
||||
string? version = null,
|
||||
int? schemaVersion = null,
|
||||
Dictionary<string, string>? templates = null,
|
||||
string? preview = "assets/preview.png")
|
||||
{
|
||||
object manifest = new
|
||||
{
|
||||
schemaVersion = schemaVersion ?? 1,
|
||||
id = themeId,
|
||||
name = name ?? "Test Theme",
|
||||
description = description ?? "A theme used for testing.",
|
||||
author = author ?? "Lumina Tests",
|
||||
version = version ?? "1.0.0",
|
||||
preview,
|
||||
templates = templates ?? new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["default"] = "templates/default.html"
|
||||
}
|
||||
};
|
||||
|
||||
return JsonSerializer.Serialize(manifest);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a ZIP archive from the provided entries, allowing tests to build arbitrary valid and invalid theme packs.
|
||||
/// </summary>
|
||||
/// <param name="entries">The entries to write into the archive.</param>
|
||||
/// <returns>The created ZIP archive bytes.</returns>
|
||||
public byte[] CreateArchive(params ThemeArchiveEntry[] entries)
|
||||
{
|
||||
using MemoryStream output = new();
|
||||
using (ZipArchive archive = new(output, ZipArchiveMode.Create, leaveOpen: true))
|
||||
{
|
||||
foreach (ThemeArchiveEntry entry in entries)
|
||||
{
|
||||
ZipArchiveEntry zipEntry = archive.CreateEntry(entry.Path);
|
||||
if (entry.UnixFileType is not null)
|
||||
zipEntry.ExternalAttributes = (entry.UnixFileType.Value << 16) | 0x81A4;
|
||||
|
||||
using StreamWriter writer = new(zipEntry.Open());
|
||||
writer.Write(entry.Content);
|
||||
}
|
||||
}
|
||||
|
||||
return output.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple valid theme pack ZIP archives with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of archives to create.</param>
|
||||
/// <returns>List of configured theme pack ZIP archives.</returns>
|
||||
public List<byte[]> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(index => Create(themeId: $"test-theme-{index}"))];
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Api.Fixtures.Core.Endpoints.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for building theme pack ZIP archives used by the theme integration tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TestThemeArchiveFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds a valid theme pack ZIP archive in memory, containing a <c>theme.json</c> manifest and a default template.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional manifest id of the theme; a unique id is generated when not supplied.</param>
|
||||
/// <returns>The bytes of the theme pack ZIP archive.</returns>
|
||||
public byte[] Create(string? themeId = null)
|
||||
{
|
||||
string resolvedThemeId = themeId ?? $"test-theme-{Guid.NewGuid():N}";
|
||||
|
||||
using MemoryStream stream = new();
|
||||
using (ZipArchive archive = new(stream, ZipArchiveMode.Create, leaveOpen: true))
|
||||
{
|
||||
ZipArchiveEntry manifestEntry = archive.CreateEntry("theme.json");
|
||||
using (StreamWriter writer = new(manifestEntry.Open(), Encoding.UTF8))
|
||||
{
|
||||
writer.Write($$"""
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "{{resolvedThemeId}}",
|
||||
"name": "Test Theme",
|
||||
"description": "A test theme used by the integration tests.",
|
||||
"author": "Test Author",
|
||||
"version": "1.0.0",
|
||||
"templates": {
|
||||
"default": "templates/default.html"
|
||||
}
|
||||
}
|
||||
""");
|
||||
}
|
||||
|
||||
ZipArchiveEntry templateEntry = archive.CreateEntry("templates/default.html");
|
||||
using (StreamWriter writer = new(templateEntry.Open(), Encoding.UTF8))
|
||||
writer.Write("<html><body><h1>Default template</h1></body></html>");
|
||||
}
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeInfoDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeInfoDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeInfoDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">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 semantic version of the theme.</param>
|
||||
/// <param name="previewUrl">Optional URL of the theme preview image.</param>
|
||||
/// <param name="isBundled">Whether the theme ships with the application.</param>
|
||||
/// <returns>A configured <see cref="ThemeInfoDto"/> instance.</returns>
|
||||
public ThemeInfoDto Create(
|
||||
string? id = null,
|
||||
string? name = null,
|
||||
string? description = null,
|
||||
string? author = null,
|
||||
string? version = null,
|
||||
string? previewUrl = null,
|
||||
bool? isBundled = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeInfoDto(
|
||||
Id: id ?? faker.Lorem.Word(),
|
||||
Name: name ?? faker.Commerce.ProductName(),
|
||||
Description: description ?? faker.Lorem.Sentence(),
|
||||
Author: author ?? faker.Name.FullName(),
|
||||
Version: version ?? faker.System.Semver(),
|
||||
PreviewUrl: previewUrl ?? $"/theme-assets/{faker.Lorem.Word()}/preview.png",
|
||||
IsBundled: isBundled ?? faker.Random.Bool()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeInfoDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeInfoDto"/> instances.</returns>
|
||||
public List<ThemeInfoDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeNavMenuDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeNavMenuDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeNavMenuDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="siteName">Optional name of the site displayed by the navigation menu.</param>
|
||||
/// <param name="mobileSections">Optional sections of the mobile navigation menu.</param>
|
||||
/// <param name="menubarSections">Optional sections of the desktop navigation menu bar.</param>
|
||||
/// <returns>A configured <see cref="ThemeNavMenuDto"/> instance.</returns>
|
||||
public ThemeNavMenuDto Create(
|
||||
string? siteName = null,
|
||||
IReadOnlyList<ThemeNavSectionDto>? mobileSections = null,
|
||||
IReadOnlyList<ThemeNavSectionDto>? menubarSections = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
ThemeNavSectionDto[] generatedSections = [CreateSection()];
|
||||
return new ThemeNavMenuDto(
|
||||
SiteName: siteName ?? faker.Company.CompanyName(),
|
||||
MobileSections: mobileSections ?? generatedSections,
|
||||
MenubarSections: menubarSections ?? generatedSections
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single <see cref="ThemeNavSectionDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="label">Optional label of the section.</param>
|
||||
/// <param name="items">Optional entries of the section.</param>
|
||||
/// <returns>A configured <see cref="ThemeNavSectionDto"/> instance.</returns>
|
||||
public ThemeNavSectionDto CreateSection(string? label = null, IReadOnlyList<ThemeNavEntryDto>? items = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeNavSectionDto(
|
||||
Label: label ?? faker.Lorem.Word(),
|
||||
Items: items ?? [CreateEntry()]
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a single <see cref="ThemeNavEntryDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="label">Optional label of the entry.</param>
|
||||
/// <param name="url">Optional URL of the link, or <see langword="null"/> for a submenu.</param>
|
||||
/// <param name="includeUrl">Whether to set <paramref name="url"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="cssClass">Optional CSS classes of the link.</param>
|
||||
/// <param name="includeCssClass">Whether to set <paramref name="cssClass"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="children">Optional child links of a submenu.</param>
|
||||
/// <returns>A configured <see cref="ThemeNavEntryDto"/> instance.</returns>
|
||||
public ThemeNavEntryDto CreateEntry(
|
||||
string? label = null,
|
||||
string? url = null,
|
||||
bool includeUrl = false,
|
||||
string? cssClass = null,
|
||||
bool includeCssClass = false,
|
||||
IReadOnlyList<ThemeNavEntryDto>? children = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeNavEntryDto(
|
||||
Label: label ?? faker.Lorem.Word(),
|
||||
Url: includeUrl ? (url ?? faker.Internet.Url()) : null,
|
||||
CssClass: includeCssClass ? (cssClass ?? faker.Lorem.Word()) : null,
|
||||
Children: children ?? []
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeNavMenuDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeNavMenuDto"/> instances.</returns>
|
||||
public List<ThemeNavMenuDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemePageDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemePageDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemePageDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="pageKey">Optional key of the page, used to select the template to render.</param>
|
||||
/// <param name="title">Optional title of the page.</param>
|
||||
/// <param name="description">Optional description of the page.</param>
|
||||
/// <param name="pageData">Optional resolved values exposed to the theme template.</param>
|
||||
/// <returns>A configured <see cref="ThemePageDto"/> instance.</returns>
|
||||
public ThemePageDto Create(
|
||||
string? pageKey = null,
|
||||
string? title = null,
|
||||
string? description = null,
|
||||
IReadOnlyDictionary<string, object?>? pageData = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemePageDto
|
||||
{
|
||||
PageKey = pageKey ?? faker.Lorem.Word(),
|
||||
Title = title ?? faker.Lorem.Sentence(),
|
||||
Description = description ?? faker.Lorem.Sentence(),
|
||||
PageData = pageData ?? new Dictionary<string, object?>()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemePageDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemePageDto"/> instances.</returns>
|
||||
public List<ThemePageDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeRenderDocumentDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeRenderDocumentDtoFixture
|
||||
{
|
||||
private readonly ThemeInfoDtoFixture _themeInfoDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeRenderDocumentDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="theme">Optional metadata of the resolved theme.</param>
|
||||
/// <param name="template">Optional raw template source to render.</param>
|
||||
/// <returns>A configured <see cref="ThemeRenderDocumentDto"/> instance.</returns>
|
||||
public ThemeRenderDocumentDto Create(ThemeInfoDto? theme = null, string? template = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeRenderDocumentDto(
|
||||
Theme: theme ?? _themeInfoDtoFixture.Create(),
|
||||
Template: template ?? faker.Lorem.Paragraph()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeRenderDocumentDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeRenderDocumentDto"/> instances.</returns>
|
||||
public List<ThemeRenderDocumentDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Enums.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeResponseDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeResponseDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeResponseDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="id">Optional database identifier 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 semantic 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 active one.</param>
|
||||
/// <param name="includeIsCurrent">Whether to set <paramref name="isCurrent"/>, or <see langword="null"/> when <see langword="false"/>.</param>
|
||||
/// <param name="installedAtUtc">Optional UTC timestamp at which the theme was installed.</param>
|
||||
/// <returns>A configured <see cref="ThemeResponseDto"/> instance.</returns>
|
||||
public ThemeResponseDto 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,
|
||||
DateTime? installedAtUtc = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeResponseDto(
|
||||
Id: id ?? Guid.NewGuid(),
|
||||
ThemeId: themeId ?? faker.Lorem.Word(),
|
||||
Name: name ?? faker.Commerce.ProductName(),
|
||||
Description: description ?? faker.Lorem.Sentence(),
|
||||
Author: author ?? faker.Name.FullName(),
|
||||
Version: version ?? faker.System.Semver(),
|
||||
PreviewPath: includePreviewPath ? (previewPath ?? (faker.Random.Bool() ? faker.System.FilePath() : null)) : null,
|
||||
InstallSource: installSource ?? ThemeInstallSource.Uploaded,
|
||||
IsCurrent: includeIsCurrent ? (isCurrent ?? (faker.Random.Bool() ? true : null)) : null,
|
||||
InstalledAtUtc: installedAtUtc ?? faker.Date.Recent()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeResponseDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeResponseDto"/> instances.</returns>
|
||||
public List<ThemeResponseDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeSettingsResponseDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeSettingsResponseDtoFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeSettingsResponseDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="maxArchiveBytes">Optional maximum allowed archive size, in bytes.</param>
|
||||
/// <param name="allowThemeScripts">Whether theme templates may load script files.</param>
|
||||
/// <param name="defaultThemeId">Optional identifier of the fallback theme.</param>
|
||||
/// <returns>A configured <see cref="ThemeSettingsResponseDto"/> instance.</returns>
|
||||
public ThemeSettingsResponseDto Create(
|
||||
long? maxArchiveBytes = null,
|
||||
bool? allowThemeScripts = null,
|
||||
string? defaultThemeId = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeSettingsResponseDto(
|
||||
MaxArchiveBytes: maxArchiveBytes ?? faker.Random.Long(1024 * 1024, 256 * 1024 * 1024),
|
||||
AllowThemeScripts: allowThemeScripts ?? faker.Random.Bool(),
|
||||
DefaultThemeId: defaultThemeId ?? faker.Lorem.Word()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeSettingsResponseDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeSettingsResponseDto"/> instances.</returns>
|
||||
public List<ThemeSettingsResponseDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ThemeTemplateResponseDto"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThemeTemplateResponseDtoFixture
|
||||
{
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ThemeTemplateResponseDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="theme">Optional theme the template belongs to.</param>
|
||||
/// <param name="template">Optional sanitized template content.</param>
|
||||
/// <returns>A configured <see cref="ThemeTemplateResponseDto"/> instance.</returns>
|
||||
public ThemeTemplateResponseDto Create(
|
||||
ThemeResponseDto? theme = null,
|
||||
string? template = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new ThemeTemplateResponseDto(
|
||||
Theme: theme ?? _themeResponseDtoFixture.Create(),
|
||||
Template: template ?? faker.Lorem.Paragraph()
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="ThemeTemplateResponseDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="ThemeTemplateResponseDto"/> instances.</returns>
|
||||
public List<ThemeTemplateResponseDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Small model class used to verify section rendering against a plain object scope.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class SectionModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the text rendered by the section.
|
||||
/// </summary>
|
||||
public string Text { get; init; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="SectionModel"/> test data.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SectionModelFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SectionModel"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="text">Optional text rendered by the section.</param>
|
||||
/// <returns>A configured <see cref="SectionModel"/> instance.</returns>
|
||||
public SectionModel Create(string? text = null)
|
||||
{
|
||||
Faker faker = new();
|
||||
return new SectionModel { Text = text ?? faker.Lorem.Word() };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="SectionModel"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="SectionModel"/> instances.</returns>
|
||||
public List<SectionModel> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user