mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 16:11: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
+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