Standardizes test conventions and documentation

This commit is contained in:
BinaryAlley committed 2026-08-24 14:20:08 -07:00
1 parent 7aeed04255
commit f42dc709de
190 files changed
+2180 -2814

No files matched your search

@@ -2,6 +2,7 @@
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -20,23 +21,33 @@ public class RolePermissionEntityFixture
/// <summary>
/// Creates a random valid <see cref="RolePermissionEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the role permission association.</param>
/// <param name="roleId">Optional. The Id of the role the permission is granted to.</param>
/// <param name="role">Optional. The role the permission is granted to.</param>
/// <param name="permissionId">Optional. The Id of the permission granted to the role.</param>
/// <param name="permission">Optional. The permission granted to the role.</param>
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
public RolePermissionEntity Create()
public RolePermissionEntity Create(
Guid? id = null,
Guid? roleId = null,
RoleEntity? role = null,
Guid? permissionId = null,
PermissionEntity? permission = null)
{
PermissionEntity permission = new()
RoleEntity resolvedRole = role ?? new RoleEntity
{
Id = _faker.Random.Guid(),
PermissionName = _faker.PickRandom<AuthorizationPermission>(),
Id = roleId ?? _faker.Random.Guid(),
RoleName = _faker.Random.String2(10),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid(),
UpdatedOnUtc = _faker.Date.Recent(),
UpdatedBy = _faker.Random.Guid()
};
RoleEntity role = new()
PermissionEntity resolvedPermission = permission ?? new PermissionEntity
{
Id = _faker.Random.Guid(),
RoleName = _faker.Random.String2(10),
Id = permissionId ?? _faker.Random.Guid(),
PermissionName = _faker.PickRandom<AuthorizationPermission>(),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid(),
UpdatedOnUtc = _faker.Date.Recent(),
@@ -46,11 +57,11 @@ public class RolePermissionEntityFixture
return new Faker<RolePermissionEntity>()
.CustomInstantiator(f => new RolePermissionEntity
{
Id = f.Random.Guid(),
RoleId = role.Id,
Role = role,
PermissionId = permission.Id,
Permission = permission,
Id = id ?? f.Random.Guid(),
RoleId = resolvedRole.Id,
Role = role ?? resolvedRole,
PermissionId = resolvedPermission.Id,
Permission = permission ?? resolvedPermission,
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid(),
UpdatedOnUtc = f.Date.Recent(),
@@ -20,16 +20,22 @@ public class UserAuthorizationEntityFixture
/// </summary>
/// <param name="userId">Optional. The user Id to use. If null, a random GUID will be generated.</param>
/// <param name="isAdmin">Whether the user should have admin role.</param>
/// <param name="role">Optional. The role associated to the user. If null, it is derived from the <paramref name="isAdmin"/> flag.</param>
/// <param name="permissions">Optional. The permissions associated to the user. If null, a default set is generated.</param>
/// <returns>The created entity.</returns>
public UserAuthorizationEntity Create(Guid? userId = null, bool isAdmin = false)
public UserAuthorizationEntity Create(
Guid? userId = null,
bool isAdmin = false,
string? role = null,
IReadOnlySet<AuthorizationPermission>? permissions = null)
{
string role = isAdmin ? "Admin" : string.Empty;
string resolvedRole = role ?? (isAdmin ? "Admin" : string.Empty);
return new UserAuthorizationEntity
{
UserId = userId ?? Guid.NewGuid(),
Role = role,
Permissions = new HashSet<AuthorizationPermission>
Role = resolvedRole,
Permissions = permissions ?? new HashSet<AuthorizationPermission>
{
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanRegisterUsers
@@ -1,6 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -14,36 +16,52 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
[ExcludeFromCodeCoverage]
public class UserRoleEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="UserRoleEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the user role association.</param>
/// <param name="userId">Optional. The Id of the user the role is granted to.</param>
/// <param name="user">Optional. The user the role is granted to.</param>
/// <param name="roleId">Optional. The Id of the role granted to the user.</param>
/// <param name="role">Optional. The role granted to the user.</param>
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
public UserRoleEntity Create()
public UserRoleEntity Create(
Guid? id = null,
Guid? userId = null,
UserEntity? user = null,
Guid? roleId = null,
RoleEntity? role = null)
{
UserEntity resolvedUser = user ?? new UserEntity
{
Id = userId ?? _faker.Random.Guid(),
Username = _faker.Internet.UserName(),
Password = _faker.Internet.Password(),
Libraries = [],
UserRole = null,
UserPermissions = [],
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid()
};
RoleEntity resolvedRole = role ?? new RoleEntity
{
Id = roleId ?? _faker.Random.Guid(),
RoleName = _faker.Random.String2(_faker.Random.Number(1, 50)),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid()
};
return new Faker<UserRoleEntity>()
.CustomInstantiator(f => new UserRoleEntity
{
Id = f.Random.Guid(),
UserId = f.Random.Guid(),
User = new()
{
Id = f.Random.Guid(),
Username = f.Internet.UserName(),
Password = f.Internet.Password(),
Libraries = [],
UserRole = null,
UserPermissions = [],
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
},
RoleId = f.Random.Guid(),
Role = new()
{
Id = f.Random.Guid(),
RoleName = f.Random.String2(f.Random.Number(1, 50)),
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
},
Id = id ?? f.Random.Guid(),
UserId = resolvedUser.Id,
User = user ?? resolvedUser,
RoleId = resolvedRole.Id,
Role = role ?? resolvedRole,
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
})
@@ -28,13 +28,15 @@ public class BookEntityFixture
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="title">Optional. The title of the book.</param>
/// <param name="originalTitle">Optional. The original title of the book.</param>
/// <param name="includeMetadata">Whether the book should include its owned metadata collections (Tags, Genres, ISBNs, Ratings) or not.</param>
/// <returns>The created <see cref="BookEntity"/>.</returns>
public BookEntity Create(
Guid? id = null,
Guid? libraryId = null,
string? path = null,
string? title = null,
string? originalTitle = null)
string? originalTitle = null,
bool includeMetadata = true)
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -58,8 +60,8 @@ public class BookEntityFixture
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.Tags, f => [.. CreateTags(f.Random.Number(1, 5))])
.RuleFor(x => x.Genres, f => [.. CreateGenres(f.Random.Number(1, 5))])
.RuleFor(x => x.Tags, f => includeMetadata ? [.. CreateTags(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Genres, f => includeMetadata ? [.. CreateGenres(f.Random.Number(1, 5))] : [])
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
.RuleFor(x => x.PageCount, _random.Next(100, 300))
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
@@ -74,8 +76,8 @@ public class BookEntityFixture
.RuleFor(x => x.GoogleBooksId, CreateGoogleBooksId)
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(x => x.ISBNs, f => CreateIsbns(f.Random.Number(1, 5)))
.RuleFor(x => x.Ratings, f => CreateBookRatings(f.Random.Number(1, 5)))
.RuleFor(x => x.ISBNs, f => includeMetadata ? CreateIsbns(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.Ratings, f => includeMetadata ? CreateBookRatings(f.Random.Number(1, 5)) : [])
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
.Generate();
@@ -1,5 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
@@ -23,13 +24,28 @@ public class UserEntityFixture
/// <param name="libraryCount">Number of libraries to generate. Default is 0.</param>
/// <param name="username">Optional username to pin, or <see langword="null"/> to generate a random one.</param>
/// <param name="password">Optional password to pin, or <see langword="null"/> to generate a random one.</param>
/// <param name="id">Optional Id to pin, or <see langword="null"/> to generate a random one.</param>
/// <param name="userRole">Optional user role association to pin when including it.</param>
/// <param name="userPermissions">Optional user permission associations to pin when including them.</param>
/// <param name="includeUserRole">Whether the user should include a user role association or not.</param>
/// <param name="includeUserPermissions">Whether the user should include user permission associations or not.</param>
/// <param name="libraries">Optional collection of libraries to pin for the user, or <see langword="null"/> to generate them based on <paramref name="libraryCount"/>.</param>
/// <returns>The created user entity.</returns>
public UserEntity Create(int libraryCount = 0, string? username = null, string? password = null)
public UserEntity Create(
int libraryCount = 0,
string? username = null,
string? password = null,
Guid? id = null,
UserRoleEntity? userRole = null,
IEnumerable<UserPermissionEntity>? userPermissions = null,
bool includeUserRole = false,
bool includeUserPermissions = false,
ICollection<LibraryEntity>? libraries = null)
{
Guid userId = Guid.NewGuid();
List<LibraryEntity> libraries = libraryCount > 0
Guid userId = id ?? Guid.NewGuid();
ICollection<LibraryEntity> resolvedLibraries = libraries ?? (libraryCount > 0
? CreateLibraries(libraryCount, userId)
: [];
: []);
return new Faker<UserEntity>()
.CustomInstantiator(f => new UserEntity
@@ -39,9 +55,9 @@ public class UserEntityFixture
Password = default!,
CreatedOnUtc = default,
TotpSecret = default,
Libraries = libraries,
UserPermissions = [],
UserRole = null,
Libraries = resolvedLibraries,
UserPermissions = includeUserPermissions ? (userPermissions ?? []).ToList() : [],
UserRole = includeUserRole ? userRole : null,
CreatedBy = userId
})
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
@@ -28,20 +28,22 @@ public class GetBooksQueryFixture
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <param name="includePaginationData">Whether the query should include pagination data or not.</param>
/// <returns>The created query to get books.</returns>
public GetBooksQuery Create(
Guid? libraryId = null,
PaginationDataDto? paginationData = null,
string? searchTerm = null,
string? sortBy = null,
SortOrder? sortOrder = null)
SortOrder? sortOrder = null,
bool includePaginationData = true)
{
return new GetBooksQuery(
paginationData ?? new PaginationDataDto
includePaginationData ? paginationData ?? new PaginationDataDto
{
CurrentPage = _faker.Random.Number(1, 100),
PerPage = _faker.Random.Number(1, 200)
},
} : null,
new LibraryFilterDto
{
LibraryId = libraryId ?? _faker.Random.Guid(),
@@ -27,31 +27,33 @@ public class GetBooksLiteQueryFixture
/// <param name="paginationData">Optional. The pagination data of the query.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <param name="includePaginationData">Whether the query should include pagination data or not.</param>
/// <returns>The created query to get the lightweight details of books.</returns>
public GetBooksLiteQuery Create(
Guid? libraryId = null,
PaginationDataDto? paginationData = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool ignoreThePrefixForAlphaPicker = false,
bool shouldIgnoreThePrefixForAlphaPicker = false,
string? sortBy = null,
SortOrder? sortOrder = null)
SortOrder? sortOrder = null,
bool includePaginationData = true)
{
return new GetBooksLiteQuery(
paginationData ?? new PaginationDataDto
includePaginationData ? paginationData ?? new PaginationDataDto
{
CurrentPage = _faker.Random.Number(1, 100),
PerPage = _faker.Random.Number(1, 200)
},
} : null,
new LibraryFilterDto
{
LibraryId = libraryId ?? _faker.Random.Guid(),
SearchTerm = searchTerm,
FilterAlphaKey = filterAlphaKey,
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker
},
sortBy,
sortOrder ?? _faker.PickRandom<SortOrder>()
@@ -1,6 +1,7 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
@@ -25,53 +26,93 @@ public class BookMetadataDtoFixture
/// <param name="title">Optional. The title of the book.</param>
/// <param name="originalTitle">Optional. The original title of the book.</param>
/// <param name="description">Optional. A brief description or summary of the book.</param>
/// <param name="goodreadsId">Optional. The Goodreads ID of the book.</param>
/// <param name="format">Optional. The format of the book.</param>
/// <param name="releaseInfo">Optional. The release information of the book.</param>
/// <param name="genres">Optional. The genres of the book.</param>
/// <param name="tags">Optional. The tags of the book.</param>
/// <param name="language">Optional. The language of the book.</param>
/// <param name="originalLanguage">Optional. The original language of the book.</param>
/// <param name="publisher">Optional. The name of the publisher of the book.</param>
/// <param name="pageCount">Optional. The number of pages in the book.</param>
/// <param name="includeOptionalProperties">Whether optional properties should be included.</param>
/// <param name="format">Optional. The format of the book.</param>
/// <param name="edition">Optional. The edition of the book.</param>
/// <param name="volumeNumber">Optional. The volume or book number in the series.</param>
/// <param name="series">Optional. The series the book is part of.</param>
/// <param name="asin">Optional. The ASIN of the book.</param>
/// <param name="goodreadsId">Optional. The Goodreads ID of the book.</param>
/// <param name="lccn">Optional. The LCCN of the book.</param>
/// <param name="oclcNumber">Optional. The OCLC number of the book.</param>
/// <param name="openLibraryId">Optional. The Open Library ID of the book.</param>
/// <param name="libraryThingId">Optional. The LibraryThing ID of the book.</param>
/// <param name="googleBooksId">Optional. The Google Books ID of the book.</param>
/// <param name="barnesAndNobleId">Optional. The Barnes and Noble ID of the book.</param>
/// <param name="appleBooksId">Optional. The Apple Books ID of the book.</param>
/// <param name="isbns">Optional. The ISBNs of the book.</param>
/// <param name="contributors">Optional. The contributors of the book.</param>
/// <param name="ratings">Optional. The ratings of the book.</param>
/// <param name="coverImagePath">Optional. The path of the cover image of the book.</param>
/// <param name="includeTitle">Whether the title should be included, or forced to <see langword="null"/>.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or left <see langword="null"/>.</param>
/// <returns>The created <see cref="BookMetadataDto"/>.</returns>
public BookMetadataDto Create(
string? title = null,
string? originalTitle = null,
string? description = null,
string? goodreadsId = null,
BookFormat? format = null,
ReleaseInfoDto? releaseInfo = null,
List<GenreDto>? genres = null,
List<TagDto>? tags = null,
LanguageInfoDto? language = null,
LanguageInfoDto? originalLanguage = null,
string? publisher = null,
int? pageCount = null,
BookFormat? format = null,
string? edition = null,
float? volumeNumber = null,
BookSeriesDto? series = null,
string? asin = null,
string? goodreadsId = null,
string? lccn = null,
string? oclcNumber = null,
string? openLibraryId = null,
string? libraryThingId = null,
string? googleBooksId = null,
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<IsbnDto>? isbns = null,
List<MediaContributorDto>? contributors = null,
List<BookRatingDto>? ratings = null,
string? coverImagePath = null,
bool includeTitle = true,
bool includeOptionalProperties = true)
{
int releaseYear = _faker.Random.Int(1900, 2024);
return new BookMetadataDto(
title ?? _faker.Lorem.Sentence(3),
includeTitle ? title ?? (includeOptionalProperties ? _faker.Lorem.Sentence(3) : null) : null,
originalTitle,
description,
includeOptionalProperties
? new ReleaseInfoDto(new DateOnly(releaseYear, 1, 1), releaseYear, null, null, _faker.Address.CountryCode(), null)
: null,
includeOptionalProperties ? [new GenreDto(_faker.Lorem.Word())] : null,
includeOptionalProperties ? [new TagDto(_faker.Lorem.Word())] : null,
includeOptionalProperties ? new LanguageInfoDto("en", "English", "English") : null,
null,
releaseInfo ?? (includeOptionalProperties ? new ReleaseInfoDto(new DateOnly(releaseYear, 1, 1), releaseYear, null, null, _faker.Address.CountryCode(), null) : null),
genres ?? (includeOptionalProperties ? [new GenreDto(_faker.Lorem.Word())] : null),
tags ?? (includeOptionalProperties ? [new TagDto(_faker.Lorem.Word())] : null),
language ?? (includeOptionalProperties ? new LanguageInfoDto("en", "English", "English") : null),
originalLanguage,
publisher,
pageCount,
format ?? _faker.PickRandom<BookFormat>(),
null,
includeOptionalProperties ? _faker.Random.Int(1, 10) : null,
null,
null,
format ?? (includeOptionalProperties ? _faker.PickRandom<BookFormat>() : null),
edition,
volumeNumber ?? (includeOptionalProperties ? _faker.Random.Int(1, 10) : null),
series,
asin,
goodreadsId,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null);
lccn,
oclcNumber,
openLibraryId,
libraryThingId,
googleBooksId,
barnesAndNobleId,
appleBooksId,
isbns,
contributors,
ratings,
coverImagePath);
}
/// <summary>
@@ -9,6 +9,7 @@ using Lumina.Contracts.Fixtures.Common.Setup;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
@@ -37,8 +38,48 @@ public class AddBookRequestFixture
/// <summary>
/// Creates a random valid request to add a book.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library the book belongs to.</param>
/// <param name="path">Optional. The file system path of the book.</param>
/// <param name="metadata">Optional. The written content metadata of the book.</param>
/// <param name="format">Optional. The format of the book.</param>
/// <param name="edition">Optional. The edition of the book.</param>
/// <param name="volumeNumber">Optional. The volume or book number in the series.</param>
/// <param name="series">Optional. The series the book is part of.</param>
/// <param name="asin">Optional. The ASIN of the book.</param>
/// <param name="goodreadsId">Optional. The Goodreads Id of the book.</param>
/// <param name="lccn">Optional. The LCCN of the book.</param>
/// <param name="oclcNumber">Optional. The OCLC number of the book.</param>
/// <param name="openLibraryId">Optional. The Open Library Id of the book.</param>
/// <param name="libraryThingId">Optional. The LibraryThing Id of the book.</param>
/// <param name="googleBooksId">Optional. The Google Books Id of the book.</param>
/// <param name="barnesAndNobleId">Optional. The Barnes and Noble Id of the book.</param>
/// <param name="appleBooksId">Optional. The Apple Books Id of the book.</param>
/// <param name="isbns">Optional. The ISBNs of the book.</param>
/// <param name="contributors">Optional. The contributors of the book.</param>
/// <param name="ratings">Optional. The ratings of the book.</param>
/// <param name="includeOptionalProperties">Whether the properties that are not explicitly provided should be randomized, or left <see langword="null"/>.</param>
/// <returns>The created request to add a book.</returns>
public AddBookRequest Create()
public AddBookRequest Create(
Guid? libraryId = null,
string? path = null,
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
string? edition = null,
float? volumeNumber = null,
BookSeriesDto? series = null,
string? asin = null,
string? goodreadsId = null,
string? lccn = null,
string? oclcNumber = null,
string? openLibraryId = null,
string? libraryThingId = null,
string? googleBooksId = null,
string? barnesAndNobleId = null,
string? appleBooksId = null,
List<IsbnDto>? isbns = null,
List<MediaContributorDto>? contributors = null,
List<BookRatingDto>? ratings = null,
bool includeOptionalProperties = true)
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -128,7 +169,7 @@ public class AddBookRequestFixture
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
Faker<WrittenContentMetadataDto> metadataFaker = new Faker<WrittenContentMetadataDto>()
.CustomInstantiator(f => new WrittenContentMetadataDto(
default!,
default,
@@ -210,62 +251,91 @@ public class AddBookRequestFixture
default!,
default!
))
.RuleFor(x => x.LibraryId, _fixture.Create<Guid>())
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Metadata, metadata)
.RuleFor(x => x.Format, _fixture.Create<BookFormat>())
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
.RuleFor(x => x.LCCN, f =>
{
string letters = new([.. Enumerable.Range(0, f.Random.Number(0, 3)).Select(_ => f.Random.Char('a', 'z'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
})
.RuleFor(x => x.OCLCNumber, f =>
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = f.Random.ArrayElement(prefixes);
string number;
switch (prefix)
{
case "ocm":
number = f.Random.String2(8, "0123456789");
break;
case "ocn":
number = f.Random.String2(f.Random.Number(9, 11), "0123456789");
break;
case "on":
number = f.Random.String2(10, "0123456789");
break;
case "(OCoLC)":
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
break;
default:
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return number;
}
return prefix + number;
})
.RuleFor(x => x.OpenLibraryId, f =>
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
})
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.GoogleBooksId, f =>
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
})
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
.RuleFor(x => x.LibraryId, libraryId ?? _fixture.Create<Guid>())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.Metadata, metadata ?? metadataFaker)
.RuleFor(x => x.Format, format ?? (includeOptionalProperties ? _fixture.Create<BookFormat>() : null))
.RuleFor(x => x.Edition, f => edition ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
.RuleFor(x => x.VolumeNumber, volumeNumber ?? (includeOptionalProperties ? (float?)_random.Next(1, 3) : null))
.RuleFor(x => x.Series, series)
.RuleFor(x => x.ASIN, f => asin ?? (includeOptionalProperties ? f.Random.String2(10) : null))
.RuleFor(x => x.GoodreadsId, goodreadsId ?? (includeOptionalProperties ? _random.Next(100000, 500000).ToString() : null))
.RuleFor(x => x.LCCN, f => lccn ?? (includeOptionalProperties ? CreateLccn(f) : null))
.RuleFor(x => x.OCLCNumber, f => oclcNumber ?? (includeOptionalProperties ? CreateOclcNumber(f) : null))
.RuleFor(x => x.OpenLibraryId, f => openLibraryId ?? (includeOptionalProperties ? CreateOpenLibraryId(f) : null))
.RuleFor(x => x.LibraryThingId, f => libraryThingId ?? (includeOptionalProperties ? f.Random.String2(f.Random.Number(1, 50)) : null))
.RuleFor(x => x.GoogleBooksId, f => googleBooksId ?? (includeOptionalProperties ? CreateGoogleBooksId(f) : null))
.RuleFor(x => x.BarnesAndNobleId, f => barnesAndNobleId ?? (includeOptionalProperties ? f.Random.String2(10, "0123456789") : null))
.RuleFor(x => x.AppleBooksId, f => appleBooksId ?? (includeOptionalProperties ? $"id{f.Random.Number(1, 999999)}" : null))
.RuleFor(p => p.ISBNs, f => isbns ?? (includeOptionalProperties ? isbn.Generate(f.Random.Number(1, 5)) : null))
.RuleFor(p => p.Ratings, f => ratings ?? (includeOptionalProperties ? rating.Generate(f.Random.Number(1, 5)) : null))
.RuleFor(x => x.Contributors, f => contributors ?? (includeOptionalProperties ? mediaContributor.Generate(f.Random.Number(1, 5)) : null));
}
/// <summary>
/// Generates a random LCCN (Library of Congress Control Number).
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated LCCN.</returns>
private static string CreateLccn(Faker faker)
{
string letters = new([.. Enumerable.Range(0, faker.Random.Number(0, 3)).Select(_ => faker.Random.Char('a', 'z'))]);
string digits = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
return letters + digits;
}
/// <summary>
/// Generates a random OCLC number (WorldCat identifier).
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated OCLC number.</returns>
private static string CreateOclcNumber(Faker faker)
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = faker.Random.ArrayElement(prefixes);
string number;
switch (prefix)
{
case "ocm":
number = faker.Random.String2(8, "0123456789");
break;
case "ocn":
number = faker.Random.String2(faker.Random.Number(9, 11), "0123456789");
break;
case "on":
number = faker.Random.String2(10, "0123456789");
break;
case "(OCoLC)":
number = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
break;
default:
number = faker.Random.String2(faker.Random.Number(8, 10), "0123456789");
return number;
}
return prefix + number;
}
/// <summary>
/// Generates a random Open Library Id.
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated Open Library Id.</returns>
private static string CreateOpenLibraryId(Faker faker)
{
int firstDigit = faker.Random.Number(1, 9);
string remainingDigits = faker.Random.String2(faker.Random.Number(0, 6), "0123456789");
char suffix = faker.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
}
/// <summary>
/// Generates a random Google Books Id.
/// </summary>
/// <param name="faker">The faker used to generate the value.</param>
/// <returns>The generated Google Books Id.</returns>
private static string CreateGoogleBooksId(Faker faker)
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[faker.Random.Number(VALID_CHARS.Length - 1)])]);
}
}
@@ -26,7 +26,7 @@ public class GetBooksLiteRequestFixture
/// <param name="perPage">Optional. The maximum number of books to retrieve per page.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional. The alpha key used to filter the results by the first character of their title, for the alpha picker.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Optional. Whether the leading "The " prefix of a title should be ignored when computing the alpha key, or not.</param>
/// <param name="sortBy">Optional. The name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional. The direction in which to sort the results.</param>
/// <returns>The created <see cref="GetBooksLiteRequest"/>.</returns>
@@ -36,7 +36,7 @@ public class GetBooksLiteRequestFixture
int? perPage = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool ignoreThePrefixForAlphaPicker = false,
bool shouldIgnoreThePrefixForAlphaPicker = false,
string? sortBy = null,
SortOrder? sortOrder = null)
{
@@ -46,7 +46,7 @@ public class GetBooksLiteRequestFixture
PerPage: perPage ?? _faker.Random.Number(1, 200),
SearchTerm: searchTerm ?? _faker.Lorem.Word(),
FilterAlphaKey: filterAlphaKey,
IgnoreThePrefixForAlphaPicker: ignoreThePrefixForAlphaPicker,
ShouldIgnoreThePrefixForAlphaPicker: shouldIgnoreThePrefixForAlphaPicker,
SortBy: sortBy ?? _faker.Lorem.Word(),
SortOrder: sortOrder ?? _faker.PickRandom<SortOrder>()
);
@@ -15,6 +15,8 @@ namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Thumbnai
[ExcludeFromCodeCoverage]
public class ThumbnailResponseFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ThumbnailResponse"/>.
/// </summary>
@@ -23,10 +25,9 @@ public class ThumbnailResponseFixture
/// <returns>The created <see cref="ThumbnailResponse"/>.</returns>
public ThumbnailResponse Create(ImageType? type = null, byte[]? bytes = null)
{
Faker faker = new();
return new ThumbnailResponse(
type ?? faker.PickRandom<ImageType>(),
bytes ?? faker.Random.Bytes(20)
type ?? _faker.PickRandom<ImageType>(),
bytes ?? _faker.Random.Bytes(20)
);
}
@@ -40,7 +40,8 @@ public class BookResponseFixture
WrittenContentMetadataDto? metadata = null,
BookFormat? format = null,
MetadataStatus? metadataStatus = null,
DateTime? createdOnUtc = null)
DateTime? createdOnUtc = null,
string? coverPath = null)
{
DateTime resolvedCreatedOnUtc = createdOnUtc ?? _faker.Date.Past().ToUniversalTime();
return new BookResponse(
@@ -70,7 +71,8 @@ public class BookResponseFixture
_faker.Date.Recent().ToUniversalTime(),
_faker.Company.CompanyName(),
resolvedCreatedOnUtc,
_faker.Random.Bool() ? _faker.Date.Recent().ToUniversalTime() : null
_faker.Random.Bool() ? _faker.Date.Recent().ToUniversalTime() : null,
coverPath ?? (_faker.Random.Bool() ? _faker.System.FilePath() : null)
);
}
@@ -50,7 +50,7 @@ public class BookFixture
_fixture.Create<WrittenContentMetadata>(),
_fixture.Create<BookFormat>(),
_fixture.Create<Optional<string>>(),
_fixture.Create<Optional<int>>(),
_fixture.Create<Optional<float>>(),
_fixture.Create<Optional<BookSeries>>(),
_fixture.Create<Optional<string>>(),
_fixture.Create<Optional<string>>(),
@@ -15,6 +15,8 @@ namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
[ExcludeFromCodeCoverage]
public class ThemeEngineOptionsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ThemeEngineOptionsDto"/>.
/// </summary>
@@ -35,16 +37,15 @@ public class ThemeEngineOptionsDtoFixture
long? maxSingleFileBytes = null,
int? maxEntries = 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)
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)
};
}
@@ -10,7 +10,6 @@ using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
@@ -29,6 +28,7 @@ public class StubApiHttpClient : IApiHttpClient
private readonly Dictionary<string, Func<object, object>> _postResponseFactories = [];
private readonly Dictionary<string, Func<object, object>> _putResponseFactories = [];
private readonly HashSet<string> _deleteSuccessEndpoints = [];
private BlobDataDto? _blobResponse;
/// <summary>
/// Gets the authorization response returned for the <c>auth/get-authorization</c> endpoint.
@@ -167,6 +167,15 @@ public class StubApiHttpClient : IApiHttpClient
_deleteSuccessEndpoints.Add(endpoint);
}
/// <summary>
/// Registers the blob response returned when a blob endpoint is called.
/// </summary>
/// <param name="blob">The blob response to return.</param>
public void RegisterBlobResponse(BlobDataDto blob)
{
_blobResponse = blob;
}
/// <summary>
/// Resets all registered responses and captured requests, keeping only the default responses.
/// </summary>
@@ -176,6 +185,7 @@ public class StubApiHttpClient : IApiHttpClient
_postResponseFactories.Clear();
_putResponseFactories.Clear();
_deleteSuccessEndpoints.Clear();
_blobResponse = null;
GetEndpointsCalled.Clear();
PostRequests.Clear();
PutRequests.Clear();
@@ -222,6 +232,8 @@ public class StubApiHttpClient : IApiHttpClient
/// <returns>A model containing the deserialized blob.</returns>
public Task<BlobDataDto> GetBlobAsync(string endpoint, CancellationToken cancellationToken = default)
{
if (_blobResponse is not null)
return Task.FromResult(_blobResponse);
throw new NotSupportedException("Blob retrieval is not supported by the test stub.");
}
@@ -15,6 +15,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Authorization;
[ExcludeFromCodeCoverage]
public class RoleDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="RoleDto"/> instance with randomized test data.
/// </summary>
@@ -23,10 +25,9 @@ public class RoleDtoFixture
/// <returns>A configured <see cref="RoleDto"/> instance.</returns>
public RoleDto Create(Guid? id = null, string? roleName = null)
{
Faker faker = new();
return new RoleDto(
Id: id ?? Guid.NewGuid(),
RoleName: roleName ?? faker.Commerce.Department()
RoleName: roleName ?? _faker.Commerce.Department()
);
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -15,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeInfoDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ThemeInfoDto"/> instance with randomized test data.
/// </summary>
@@ -37,16 +38,15 @@ public class ThemeInfoDtoFixture
bool? isBundled = null,
bool? isDeleted = 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(),
IsDeleted: isDeleted ?? faker.Random.Bool()
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(),
IsDeleted: isDeleted ?? _faker.Random.Bool()
);
}
@@ -15,6 +15,9 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeNavMenuDtoFixture
{
private readonly Faker _faker = new();
private readonly ThemeNavSectionDtoFixture _themeNavSectionDtoFixture = new();
/// <summary>
/// Creates a new <see cref="ThemeNavMenuDto"/> instance with randomized test data.
/// </summary>
@@ -27,57 +30,14 @@ public class ThemeNavMenuDtoFixture
IReadOnlyList<ThemeNavSectionDto>? mobileSections = null,
IReadOnlyList<ThemeNavSectionDto>? menubarSections = null)
{
Faker faker = new();
ThemeNavSectionDto[] generatedSections = [CreateSection()];
ThemeNavSectionDto[] generatedSections = [_themeNavSectionDtoFixture.Create()];
return new ThemeNavMenuDto(
SiteName: siteName ?? faker.Company.CompanyName(),
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>
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -15,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemePageDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ThemePageDto"/> instance with randomized test data.
/// </summary>
@@ -29,12 +30,11 @@ public class ThemePageDtoFixture
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(),
PageKey = pageKey ?? _faker.Lorem.Word(),
Title = title ?? _faker.Lorem.Sentence(),
Description = description ?? _faker.Lorem.Sentence(),
PageData = pageData ?? new Dictionary<string, object?>()
};
}
@@ -14,6 +14,7 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeRenderDocumentDtoFixture
{
private readonly Faker _faker = new();
private readonly ThemeInfoDtoFixture _themeInfoDtoFixture = new();
/// <summary>
@@ -22,12 +23,13 @@ public class ThemeRenderDocumentDtoFixture
/// <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)
public ThemeRenderDocumentDto Create(
ThemeInfoDto? theme = null,
string? template = null)
{
Faker faker = new();
return new ThemeRenderDocumentDto(
Theme: theme ?? _themeInfoDtoFixture.Create(),
Template: template ?? faker.Lorem.Paragraph()
Template: template ?? _faker.Lorem.Paragraph()
);
}
@@ -16,6 +16,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeResponseDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ThemeResponseDto"/> instance with randomized test data.
/// </summary>
@@ -48,19 +50,18 @@ public class ThemeResponseDtoFixture
DateTime? installedAtUtc = null,
bool? isDeleted = 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,
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(),
IsDeleted: isDeleted ?? faker.Random.Bool()
IsCurrent: includeIsCurrent ? (isCurrent ?? (_faker.Random.Bool() ? true : null)) : null,
InstalledAtUtc: installedAtUtc ?? _faker.Date.Recent(),
IsDeleted: isDeleted ?? _faker.Random.Bool()
);
}
@@ -14,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeSettingsResponseDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ThemeSettingsResponseDto"/> instance with randomized test data.
/// </summary>
@@ -24,10 +26,9 @@ public class ThemeSettingsResponseDtoFixture
long? maxArchiveBytes = null,
string? defaultThemeId = null)
{
Faker faker = new();
return new ThemeSettingsResponseDto(
MaxArchiveBytes: maxArchiveBytes ?? faker.Random.Long(1024 * 1024, 256 * 1024 * 1024),
DefaultThemeId: defaultThemeId ?? faker.Lorem.Word()
MaxArchiveBytes: maxArchiveBytes ?? _faker.Random.Long(1024 * 1024, 256 * 1024 * 1024),
DefaultThemeId: defaultThemeId ?? _faker.Lorem.Word()
);
}
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.DTO.Themes;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -15,6 +14,7 @@ namespace Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
[ExcludeFromCodeCoverage]
public class ThemeTemplateResponseDtoFixture
{
private readonly Faker _faker = new();
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
/// <summary>
@@ -27,10 +27,9 @@ public class ThemeTemplateResponseDtoFixture
ThemeResponseDto? theme = null,
string? template = null)
{
Faker faker = new();
return new ThemeTemplateResponseDto(
Theme: theme ?? _themeResponseDtoFixture.Create(),
Template: template ?? faker.Lorem.Paragraph()
Template: template ?? _faker.Lorem.Paragraph()
);
}
@@ -1,6 +1,5 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -14,15 +13,17 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Models;
[ExcludeFromCodeCoverage]
public class SectionModelFixture
{
private readonly Faker _faker = new();
/// <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)
public SectionModel Create(
string? text = null)
{
Faker faker = new();
return new SectionModel { Text = text ?? faker.Lorem.Word() };
return new SectionModel { Text = text ?? _faker.Lorem.Word() };
}
/// <summary>
@@ -15,17 +15,20 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
[ExcludeFromCodeCoverage]
public class AddRoleRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="AddRoleRequest"/> instance with randomized test data.
/// </summary>
/// <param name="roleName">Optional name of the role.</param>
/// <param name="permissions">Optional collection of permission identifiers.</param>
/// <returns>A configured <see cref="AddRoleRequest"/> instance.</returns>
public AddRoleRequest Create(string? roleName = null, List<Guid>? permissions = null)
public AddRoleRequest Create(
string? roleName = null,
List<Guid>? permissions = null)
{
Faker faker = new();
return new AddRoleRequest(
RoleName: roleName ?? faker.Commerce.Department(),
RoleName: roleName ?? _faker.Commerce.Department(),
Permissions: permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
);
}
@@ -1,5 +1,4 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Presentation.Web.Common.Enums.Common;
using Lumina.Presentation.Web.Common.Requests.Libraries;
using System;
@@ -24,7 +23,7 @@ public class GetBooksLiteRequestFixture
/// <param name="perPage">Optional number of books to retrieve per page.</param>
/// <param name="searchTerm">Optional search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional alpha key used to filter the results.</param>
/// <param name="ignoreThePrefixForAlphaPicker">Whether the leading "The " prefix is ignored by the alpha picker.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix is ignored by the alpha picker.</param>
/// <param name="sortBy">Optional name of the field by which to sort the results.</param>
/// <param name="sortOrder">Optional direction in which to sort the results.</param>
/// <returns>A configured <see cref="GetBooksLiteRequest"/> instance.</returns>
@@ -34,7 +33,7 @@ public class GetBooksLiteRequestFixture
int? perPage = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool ignoreThePrefixForAlphaPicker = false,
bool shouldIgnoreThePrefixForAlphaPicker = false,
string? sortBy = null,
SortOrder? sortOrder = null)
{
@@ -45,7 +44,7 @@ public class GetBooksLiteRequestFixture
PerPage = perPage,
SearchTerm = searchTerm,
FilterAlphaKey = filterAlphaKey,
IgnoreThePrefixForAlphaPicker = ignoreThePrefixForAlphaPicker,
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker,
SortBy = sortBy,
SortOrder = sortOrder
};
@@ -14,16 +14,18 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement.Authe
[ExcludeFromCodeCoverage]
public class LoginViewRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="LoginViewRequest"/> instance with randomized test data.
/// </summary>
/// <param name="returnUrl">Optional URL to return to, after login.</param>
/// <returns>A configured <see cref="LoginViewRequest"/> instance.</returns>
public LoginViewRequest Create(string? returnUrl = null)
public LoginViewRequest Create(
string? returnUrl = null)
{
Faker faker = new();
return new LoginViewRequest(
ReturnUrl: returnUrl ?? $"/{faker.Random.AlphaNumeric(8)}"
ReturnUrl: returnUrl ?? $"/{_faker.Random.AlphaNumeric(8)}"
);
}
@@ -14,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
[ExcludeFromCodeCoverage]
public class ChangePasswordRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="ChangePasswordRequest"/> instance with randomized test data.
/// </summary>
@@ -22,13 +24,16 @@ public class ChangePasswordRequestFixture
/// <param name="newPassword">Optional new password.</param>
/// <param name="newPasswordConfirm">Optional confirmation of the new password.</param>
/// <returns>A configured <see cref="ChangePasswordRequest"/> instance.</returns>
public ChangePasswordRequest Create(string? username = null, string? currentPassword = null, string? newPassword = null, string? newPasswordConfirm = null)
public ChangePasswordRequest Create(
string? username = null,
string? currentPassword = null,
string? newPassword = null,
string? newPasswordConfirm = null)
{
Faker faker = new();
string generatedNewPassword = newPassword ?? faker.Internet.Password(12);
string generatedNewPassword = newPassword ?? _faker.Internet.Password(12);
return new ChangePasswordRequest(
Username: username ?? faker.Internet.UserName(),
CurrentPassword: currentPassword ?? faker.Internet.Password(12),
Username: username ?? _faker.Internet.UserName(),
CurrentPassword: currentPassword ?? _faker.Internet.Password(12),
NewPassword: generatedNewPassword,
NewPasswordConfirm: newPasswordConfirm ?? generatedNewPassword
);
@@ -14,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
[ExcludeFromCodeCoverage]
public class LoginRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="LoginRequest"/> instance with randomized test data.
/// </summary>
@@ -22,12 +24,15 @@ public class LoginRequestFixture
/// <param name="totpCode">Optional TOTP code.</param>
/// <param name="returnUrl">Optional URL to return to, after login.</param>
/// <returns>A configured <see cref="LoginRequest"/> instance.</returns>
public LoginRequest Create(string? username = null, string? password = null, string? totpCode = null, string? returnUrl = null)
public LoginRequest Create(
string? username = null,
string? password = null,
string? totpCode = null,
string? returnUrl = null)
{
Faker faker = new();
return new LoginRequest(
Username: username ?? faker.Internet.UserName(),
Password: password ?? faker.Internet.Password(12),
Username: username ?? _faker.Internet.UserName(),
Password: password ?? _faker.Internet.Password(12),
TotpCode: totpCode,
ReturnUrl: returnUrl
);
@@ -14,17 +14,20 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
[ExcludeFromCodeCoverage]
public class RecoverPasswordRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="RecoverPasswordRequest"/> instance with randomized test data.
/// </summary>
/// <param name="username">Optional username.</param>
/// <param name="totpCode">Optional TOTP code.</param>
/// <returns>A configured <see cref="RecoverPasswordRequest"/> instance.</returns>
public RecoverPasswordRequest Create(string? username = null, string? totpCode = null)
public RecoverPasswordRequest Create(
string? username = null,
string? totpCode = null)
{
Faker faker = new();
return new RecoverPasswordRequest(
Username: username ?? faker.Internet.UserName(),
Username: username ?? _faker.Internet.UserName(),
TotpCode: totpCode
);
}
@@ -14,6 +14,8 @@ namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
[ExcludeFromCodeCoverage]
public class RegisterRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a new <see cref="RegisterRequest"/> instance with randomized test data.
/// </summary>
@@ -23,12 +25,16 @@ public class RegisterRequestFixture
/// <param name="registrationType">Optional registration type, e.g. "Admin" or "User".</param>
/// <param name="use2fa">Whether two-factor authentication is enabled for the account.</param>
/// <returns>A configured <see cref="RegisterRequest"/> instance.</returns>
public RegisterRequest Create(string? username = null, string? password = null, string? passwordConfirm = null, string? registrationType = "User", bool use2fa = true)
public RegisterRequest Create(
string? username = null,
string? password = null,
string? passwordConfirm = null,
string? registrationType = "User",
bool use2fa = true)
{
Faker faker = new();
string generatedPassword = password ?? faker.Internet.Password(12);
string generatedPassword = password ?? _faker.Internet.Password(12);
return new RegisterRequest(
Username: username ?? faker.Internet.UserName(),
Username: username ?? _faker.Internet.UserName(),
Password: generatedPassword,
PasswordConfirm: passwordConfirm ?? generatedPassword,
RegistrationType: registrationType,