diff --git a/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/Themes/ThemeEntityFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/Themes/ThemeEntityFixture.cs new file mode 100644 index 00000000..f51fec10 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/DataAccess/Entities/Themes/ThemeEntityFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class ThemeEntityFixture +{ + /// + /// Creates a random valid . + /// + /// Optional database Id of the theme. + /// Optional manifest id of the theme. + /// Optional display name of the theme. + /// Optional description of the theme. + /// Optional author of the theme. + /// Optional version of the theme. + /// Optional preview image path of the theme, or when the theme has no preview. + /// Whether to set , or when . + /// Optional source the theme was installed from. + /// Optional value indicating whether the theme is the currently active one. + /// Whether to set , or when . + /// Optional value indicating whether the theme was soft deleted. + /// Optional UTC timestamp when the theme was installed. + /// Optional UTC timestamp when the entity was created. + /// Optional Id of the user that created the entity. + /// Optional UTC timestamp when the entity was updated. + /// Whether to set , or when . + /// Optional Id of the user that updated the entity. + /// Whether to set , or when . + /// A configured instance. + 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() + .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()) + .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(); + } + + /// + /// Creates a list of instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDtoFixture.cs b/tests/Common/Lumina.Application.Fixtures/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDtoFixture.cs new file mode 100644 index 00000000..de55b6c4 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Common/Infrastructure/Models/DTO/Themes/ThemeManifestDtoFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class ThemeManifestDtoFixture +{ + /// + /// Creates a random valid . + /// + /// Optional schema version of the manifest. + /// Optional unique identifier of the theme. + /// Optional display name of the theme. + /// Optional description of the theme. + /// Optional author of the theme. + /// Optional version of the theme. + /// Optional preview image path of the theme, or when the theme has no preview. + /// Whether to set , or when . + /// Optional template mappings of the theme. + /// A configured instance. + 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? templates = null) + { + return new Faker() + .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(StringComparer.OrdinalIgnoreCase) { ["home"] = "templates/home.html" }) + .Generate(); + } + + /// + /// Creates a list of instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandFixture.cs new file mode 100644 index 00000000..bea20392 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/DeleteTheme/DeleteThemeCommandFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class DeleteThemeCommandFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional manifest id of the theme to delete. + /// The created . + public DeleteThemeCommand Create(string? themeId = null) + { + return new DeleteThemeCommand(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandFixture.cs new file mode 100644 index 00000000..78cb9985 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/InstallTheme/InstallThemeCommandFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class InstallThemeCommandFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional ZIP archive stream of the theme pack. + /// Optional file name of the uploaded archive. + /// The created . + 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"); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandFixture.cs new file mode 100644 index 00000000..a7257669 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Commands/SetCurrentTheme/SetCurrentThemeCommandFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class SetCurrentThemeCommandFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional manifest id of the theme to activate. + /// The created . + public SetCurrentThemeCommand Create(string? themeId = null) + { + return new SetCurrentThemeCommand(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryFixture.cs new file mode 100644 index 00000000..531fd197 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetCurrentTheme/GetCurrentThemeQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetCurrentThemeQueryFixture +{ + /// + /// Creates a . + /// + /// The created . + public GetCurrentThemeQuery Create() + { + return new GetCurrentThemeQuery(); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryFixture.cs new file mode 100644 index 00000000..c17f60a6 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeArchive/GetThemeArchiveQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetThemeArchiveQueryFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional manifest id of the theme. + /// The created . + public GetThemeArchiveQuery Create(string? themeId = null) + { + return new GetThemeArchiveQuery(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryFixture.cs new file mode 100644 index 00000000..4397337e --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeAsset/GetThemeAssetQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetThemeAssetQueryFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional manifest id of the theme. + /// Optional asset path relative to the theme pack root. + /// The created . + public GetThemeAssetQuery Create(string? themeId = null, string? assetPath = null) + { + return new GetThemeAssetQuery( + themeId ?? _faker.Lorem.Slug(2), + assetPath ?? _faker.System.FilePath()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryFixture.cs new file mode 100644 index 00000000..bb1a652f --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeSettings/GetThemeSettingsQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetThemeSettingsQueryFixture +{ + /// + /// Creates a . + /// + /// The created . + public GetThemeSettingsQuery Create() + { + return new GetThemeSettingsQuery(); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryFixture.cs new file mode 100644 index 00000000..84cba75d --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemeTemplate/GetThemeTemplateQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetThemeTemplateQueryFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional manifest id of the theme. + /// Optional page key that selects the template. + /// The created . + public GetThemeTemplateQuery Create(string? themeId = null, string? pageKey = null) + { + return new GetThemeTemplateQuery( + themeId ?? _faker.Lorem.Slug(2), + pageKey ?? _faker.Lorem.Word()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemes/GetThemesQueryFixture.cs b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemes/GetThemesQueryFixture.cs new file mode 100644 index 00000000..8c189e25 --- /dev/null +++ b/tests/Common/Lumina.Application.Fixtures/Core/Themes/Management/Queries/GetThemes/GetThemesQueryFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class GetThemesQueryFixture +{ + /// + /// Creates a . + /// + /// The created . + public GetThemesQuery Create() + { + return new GetThemesQuery(); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/DeleteThemeRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/DeleteThemeRequestFixture.cs new file mode 100644 index 00000000..4034dfff --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/DeleteThemeRequestFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class DeleteThemeRequestFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The manifest id of the theme to delete. + /// The created . + public DeleteThemeRequest Create(string? themeId = null) + { + return new DeleteThemeRequest(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeArchiveRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeArchiveRequestFixture.cs new file mode 100644 index 00000000..a7421ee3 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeArchiveRequestFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class GetThemeArchiveRequestFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The manifest id of the theme. + /// The created . + public GetThemeArchiveRequest Create(string? themeId = null) + { + return new GetThemeArchiveRequest(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeAssetRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeAssetRequestFixture.cs new file mode 100644 index 00000000..b78f5459 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeAssetRequestFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class GetThemeAssetRequestFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The manifest id of the theme. + /// Optional. The asset path relative to the theme pack root. + /// The created . + public GetThemeAssetRequest Create(string? themeId = null, string? assetPath = null) + { + return new GetThemeAssetRequest( + themeId ?? _faker.Lorem.Slug(2), + assetPath ?? _faker.System.FilePath()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeTemplateRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeTemplateRequestFixture.cs new file mode 100644 index 00000000..1b9da5de --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/GetThemeTemplateRequestFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class GetThemeTemplateRequestFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The manifest id of the theme. + /// Optional. The page key that selects the template. + /// The created . + public GetThemeTemplateRequest Create(string? themeId = null, string? pageKey = null) + { + return new GetThemeTemplateRequest( + themeId ?? _faker.Lorem.Slug(2), + pageKey ?? _faker.Lorem.Word()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/SetCurrentThemeRequestFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/SetCurrentThemeRequestFixture.cs new file mode 100644 index 00000000..78d68248 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Requests/Themes/SetCurrentThemeRequestFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class SetCurrentThemeRequestFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The manifest id of the theme to activate. + /// The created . + public SetCurrentThemeRequest Create(string? themeId = null) + { + return new SetCurrentThemeRequest(themeId ?? _faker.Lorem.Slug(2)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeArchiveResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeArchiveResponseFixture.cs new file mode 100644 index 00000000..ea08780b --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeArchiveResponseFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ThemeArchiveResponseFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The bytes of the ZIP archive. + /// Optional. The file name to expose when downloading the archive. + /// Optional. The MIME content type of the archive. + /// The created . + 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()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeAssetResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeAssetResponseFixture.cs new file mode 100644 index 00000000..da27cd1b --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeAssetResponseFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ThemeAssetResponseFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The bytes of the asset file. + /// Optional. The MIME content type of the asset file. + /// The created . + public ThemeAssetResponse Create(byte[]? bytes = null, string? contentType = null) + { + return new ThemeAssetResponse( + bytes ?? Encoding.UTF8.GetBytes(_faker.Lorem.Paragraph()), + contentType ?? _faker.System.MimeType()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeResponseFixture.cs new file mode 100644 index 00000000..c0c03b0d --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeResponseFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ThemeResponseFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The Id of the theme. + /// Optional. The manifest id of the theme. + /// Optional. The display name of the theme. + /// Optional. The description of the theme. + /// Optional. The author of the theme. + /// Optional. The version of the theme. + /// Optional. The preview image path of the theme, or when the theme has no preview. + /// Whether to set , or when . + /// Optional. The source the theme was installed from. + /// Optional. Whether the theme is the currently active one. + /// Whether to set , or when . + /// Optional. The UTC timestamp when the theme was installed. + /// The created . + 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(), + includeIsCurrent ? (isCurrent ?? (_faker.Random.Bool() ? true : null)) : null, + installedAtUtc ?? _faker.Date.Recent().ToUniversalTime()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeSettingsResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeSettingsResponseFixture.cs new file mode 100644 index 00000000..1a807539 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeSettingsResponseFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ThemeSettingsResponseFixture +{ + private readonly Faker _faker = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The maximum allowed size of a theme archive, in bytes. + /// Optional. Whether theme templates may contain script elements. + /// Optional. The identifier of the default theme. + /// The created . + 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)); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeTemplateResponseFixture.cs b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeTemplateResponseFixture.cs new file mode 100644 index 00000000..be29df78 --- /dev/null +++ b/tests/Common/Lumina.Contracts.Fixtures/Core/Responses/Themes/ThemeTemplateResponseFixture.cs @@ -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; + +/// +/// Fixture class for the record. +/// +[ExcludeFromCodeCoverage] +public class ThemeTemplateResponseFixture +{ + private readonly Faker _faker = new(); + private readonly ThemeResponseFixture _themeResponseFixture = new(); + + /// + /// Creates a random valid . + /// + /// Optional. The theme the template belongs to. + /// Optional. The sanitized content of the template. + /// The created . + public ThemeTemplateResponse Create(ThemeResponse? theme = null, string? template = null) + { + return new ThemeTemplateResponse( + theme ?? _themeResponseFixture.Create(), + template ?? _faker.Lorem.Paragraph()); + } + + /// + /// Creates a list of . + /// + /// The number of elements to create. + /// The created list. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Infrastructure.Fixtures/Common/Models/DTO/Configuration/ThemeEngineOptionsDtoFixture.cs b/tests/Common/Lumina.Infrastructure.Fixtures/Common/Models/DTO/Configuration/ThemeEngineOptionsDtoFixture.cs new file mode 100644 index 00000000..b61fbdd5 --- /dev/null +++ b/tests/Common/Lumina.Infrastructure.Fixtures/Common/Models/DTO/Configuration/ThemeEngineOptionsDtoFixture.cs @@ -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; + +/// +/// Fixture class for the class. +/// +[ExcludeFromCodeCoverage] +public class ThemeEngineOptionsDtoFixture +{ + /// + /// Creates a random valid . + /// + /// Optional directory where installed theme packs are stored. + /// Optional directory where the shipped theme pack archives are located. + /// Optional identifier of the default theme. + /// Optional maximum size of an uploaded theme archive, in bytes. + /// Optional maximum total size of an extracted theme pack, in bytes. + /// Optional maximum size of a single file within a theme pack, in bytes. + /// Optional maximum number of entries in a theme pack archive. + /// Optional value indicating whether script elements are allowed. + /// A configured instance. + 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() + }; + } + + /// + /// Creates a list of instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemeArchiveEntry.cs b/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemeArchiveEntry.cs new file mode 100644 index 00000000..f106c330 --- /dev/null +++ b/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemeArchiveEntry.cs @@ -0,0 +1,14 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Infrastructure.Fixtures.Core.Themes; + +/// +/// Describes a single entry of a theme pack ZIP archive built by the . +/// +/// The entry path inside the archive. +/// The text content of the entry. +/// Optional Unix file type for the entry, used to simulate special file types such as symbolic links. +[ExcludeFromCodeCoverage] +public sealed record ThemeArchiveEntry(string Path, string Content, int? UnixFileType = null); diff --git a/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemePackFixture.cs b/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemePackFixture.cs new file mode 100644 index 00000000..f87a516f --- /dev/null +++ b/tests/Common/Lumina.Infrastructure.Fixtures/Core/Themes/ThemePackFixture.cs @@ -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; + +/// +/// Fixture class for generating theme pack ZIP archives used by theme tests. +/// +[ExcludeFromCodeCoverage] +public sealed class ThemePackFixture +{ + /// + /// Creates a valid theme pack ZIP archive containing a manifest, the template files referenced by it and a preview asset. + /// + /// Optional theme id written to the manifest. + /// Optional display name written to the manifest. + /// Optional description written to the manifest. + /// Optional author written to the manifest. + /// Optional version written to the manifest. + /// Optional schema version written to the manifest. + /// Optional template mappings written to the manifest. + /// Optional preview path written to the manifest, or to omit the preview. + /// Optional content for the default template file. + /// Whether to include the preview asset file in the archive. + /// Optional additional files written into the archive. + /// The created theme pack ZIP archive. + public byte[] Create( + string themeId = "test-theme", + string? name = null, + string? description = null, + string? author = null, + string? version = null, + int? schemaVersion = null, + Dictionary? templates = null, + string? preview = "assets/preview.png", + string? defaultTemplateContent = null, + bool includePreviewAsset = true, + IReadOnlyDictionary? additionalFiles = null) + { + Dictionary manifestTemplates = templates ?? new Dictionary(StringComparer.OrdinalIgnoreCase) + { + ["default"] = "templates/default.html" + }; + + string manifestJson = CreateManifestJson( + themeId, + name, + description, + author, + version, + schemaVersion, + manifestTemplates, + preview); + + List entries = [new("theme.json", manifestJson)]; + foreach ((string key, string templatePath) in manifestTemplates) + entries.Add(new(templatePath, defaultTemplateContent ?? $"{key} template")); + + 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]); + } + + /// + /// Creates the JSON content of a theme manifest with test defaults that can be overridden per field. + /// + /// Optional theme id written to the manifest. + /// Optional display name written to the manifest. + /// Optional description written to the manifest. + /// Optional author written to the manifest. + /// Optional version written to the manifest. + /// Optional schema version written to the manifest. + /// Optional template mappings written to the manifest. + /// Optional preview path written to the manifest, or to omit the preview. + /// The created manifest JSON content. + public string CreateManifestJson( + string themeId = "test-theme", + string? name = null, + string? description = null, + string? author = null, + string? version = null, + int? schemaVersion = null, + Dictionary? 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(StringComparer.OrdinalIgnoreCase) + { + ["default"] = "templates/default.html" + } + }; + + return JsonSerializer.Serialize(manifest); + } + + /// + /// Creates a ZIP archive from the provided entries, allowing tests to build arbitrary valid and invalid theme packs. + /// + /// The entries to write into the archive. + /// The created ZIP archive bytes. + 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(); + } + + /// + /// Creates multiple valid theme pack ZIP archives with randomized test data. + /// + /// Number of archives to create. + /// List of configured theme pack ZIP archives. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(index => Create(themeId: $"test-theme-{index}"))]; + } +} diff --git a/tests/Common/Lumina.Presentation.Api.Fixtures/Core/Endpoints/Themes/TestThemeArchiveFixture.cs b/tests/Common/Lumina.Presentation.Api.Fixtures/Core/Endpoints/Themes/TestThemeArchiveFixture.cs new file mode 100644 index 00000000..3fe523ab --- /dev/null +++ b/tests/Common/Lumina.Presentation.Api.Fixtures/Core/Endpoints/Themes/TestThemeArchiveFixture.cs @@ -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; + +/// +/// Fixture class for building theme pack ZIP archives used by the theme integration tests. +/// +[ExcludeFromCodeCoverage] +public class TestThemeArchiveFixture +{ + /// + /// Builds a valid theme pack ZIP archive in memory, containing a theme.json manifest and a default template. + /// + /// Optional manifest id of the theme; a unique id is generated when not supplied. + /// The bytes of the theme pack ZIP archive. + 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("

Default template

"); + } + + return stream.ToArray(); + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeInfoDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeInfoDtoFixture.cs new file mode 100644 index 00000000..a7f32034 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeInfoDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeInfoDtoFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional manifest id of the theme. + /// Optional display name of the theme. + /// Optional description of the theme. + /// Optional author of the theme. + /// Optional semantic version of the theme. + /// Optional URL of the theme preview image. + /// Whether the theme ships with the application. + /// A configured instance. + 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() + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeNavMenuDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeNavMenuDtoFixture.cs new file mode 100644 index 00000000..5016ae36 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeNavMenuDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeNavMenuDtoFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional name of the site displayed by the navigation menu. + /// Optional sections of the mobile navigation menu. + /// Optional sections of the desktop navigation menu bar. + /// A configured instance. + public ThemeNavMenuDto Create( + string? siteName = null, + IReadOnlyList? mobileSections = null, + IReadOnlyList? menubarSections = null) + { + Faker faker = new(); + ThemeNavSectionDto[] generatedSections = [CreateSection()]; + return new ThemeNavMenuDto( + SiteName: siteName ?? faker.Company.CompanyName(), + MobileSections: mobileSections ?? generatedSections, + MenubarSections: menubarSections ?? generatedSections + ); + } + + /// + /// Creates a single instance with randomized test data. + /// + /// Optional label of the section. + /// Optional entries of the section. + /// A configured instance. + public ThemeNavSectionDto CreateSection(string? label = null, IReadOnlyList? items = null) + { + Faker faker = new(); + return new ThemeNavSectionDto( + Label: label ?? faker.Lorem.Word(), + Items: items ?? [CreateEntry()] + ); + } + + /// + /// Creates a single instance with randomized test data. + /// + /// Optional label of the entry. + /// Optional URL of the link, or for a submenu. + /// Whether to set , or when . + /// Optional CSS classes of the link. + /// Whether to set , or when . + /// Optional child links of a submenu. + /// A configured instance. + public ThemeNavEntryDto CreateEntry( + string? label = null, + string? url = null, + bool includeUrl = false, + string? cssClass = null, + bool includeCssClass = false, + IReadOnlyList? 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 ?? [] + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemePageDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemePageDtoFixture.cs new file mode 100644 index 00000000..684f568a --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemePageDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemePageDtoFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional key of the page, used to select the template to render. + /// Optional title of the page. + /// Optional description of the page. + /// Optional resolved values exposed to the theme template. + /// A configured instance. + public ThemePageDto Create( + string? pageKey = null, + string? title = null, + string? description = null, + IReadOnlyDictionary? 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() + }; + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeRenderDocumentDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeRenderDocumentDtoFixture.cs new file mode 100644 index 00000000..45a22191 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeRenderDocumentDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeRenderDocumentDtoFixture +{ + private readonly ThemeInfoDtoFixture _themeInfoDtoFixture = new(); + + /// + /// Creates a new instance with randomized test data. + /// + /// Optional metadata of the resolved theme. + /// Optional raw template source to render. + /// A configured instance. + public ThemeRenderDocumentDto Create(ThemeInfoDto? theme = null, string? template = null) + { + Faker faker = new(); + return new ThemeRenderDocumentDto( + Theme: theme ?? _themeInfoDtoFixture.Create(), + Template: template ?? faker.Lorem.Paragraph() + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeResponseDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeResponseDtoFixture.cs new file mode 100644 index 00000000..9abbbf15 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeResponseDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeResponseDtoFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional database identifier of the theme. + /// Optional manifest id of the theme. + /// Optional display name of the theme. + /// Optional description of the theme. + /// Optional author of the theme. + /// Optional semantic version of the theme. + /// Optional preview image path of the theme, or when the theme has no preview. + /// Whether to set , or when . + /// Optional source the theme was installed from. + /// Optional value indicating whether the theme is the active one. + /// Whether to set , or when . + /// Optional UTC timestamp at which the theme was installed. + /// A configured instance. + 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() + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeSettingsResponseDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeSettingsResponseDtoFixture.cs new file mode 100644 index 00000000..fcb6ece5 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeSettingsResponseDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeSettingsResponseDtoFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional maximum allowed archive size, in bytes. + /// Whether theme templates may load script files. + /// Optional identifier of the fallback theme. + /// A configured instance. + 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() + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeTemplateResponseDtoFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeTemplateResponseDtoFixture.cs new file mode 100644 index 00000000..fe00f0b4 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/DTO/Themes/ThemeTemplateResponseDtoFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class ThemeTemplateResponseDtoFixture +{ + private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new(); + + /// + /// Creates a new instance with randomized test data. + /// + /// Optional theme the template belongs to. + /// Optional sanitized template content. + /// A configured instance. + public ThemeTemplateResponseDto Create( + ThemeResponseDto? theme = null, + string? template = null) + { + Faker faker = new(); + return new ThemeTemplateResponseDto( + Theme: theme ?? _themeResponseDtoFixture.Create(), + Template: template ?? faker.Lorem.Paragraph() + ); + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModel.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModel.cs new file mode 100644 index 00000000..201c8d07 --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModel.cs @@ -0,0 +1,17 @@ +#region ========================================================================= USING ===================================================================================== +using System.Diagnostics.CodeAnalysis; +#endregion + +namespace Lumina.Presentation.Web.Fixtures.Common.Models; + +/// +/// Small model class used to verify section rendering against a plain object scope. +/// +[ExcludeFromCodeCoverage] +public sealed class SectionModel +{ + /// + /// Gets the text rendered by the section. + /// + public string Text { get; init; } = string.Empty; +} diff --git a/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModelFixture.cs b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModelFixture.cs new file mode 100644 index 00000000..e6a005bf --- /dev/null +++ b/tests/Common/Lumina.Presentation.Web.Fixtures/Common/Models/SectionModelFixture.cs @@ -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; + +/// +/// Fixture class for generating test data. +/// +[ExcludeFromCodeCoverage] +public class SectionModelFixture +{ + /// + /// Creates a new instance with randomized test data. + /// + /// Optional text rendered by the section. + /// A configured instance. + public SectionModel Create(string? text = null) + { + Faker faker = new(); + return new SectionModel { Text = text ?? faker.Lorem.Word() }; + } + + /// + /// Creates multiple instances with randomized test data. + /// + /// Number of instances to create. + /// List of configured instances. + public List CreateMany(int count = 3) + { + return [.. Enumerable.Range(0, count).Select(_ => Create())]; + } +}