Merge branch 'refactor/standardize-test-fixtures-and-docs' into feature/add-artwork-provider-and-metadata-aggregation

This commit is contained in:
BinaryAlley committed 2026-08-24 22:56:22 -07:00
commit 4ff184d8a5
388 files changed
+13829 -2814

No files matched your search

@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Filtering;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.Filtering;
/// <summary>
/// Fixture class for the <see cref="BaseFilterDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class BaseFilterDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BaseFilterDto"/>.
/// </summary>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <returns>The created <see cref="BaseFilterDto"/>.</returns>
public BaseFilterDto Create(string? searchTerm = null)
{
return new BaseFilterDto
{
SearchTerm = searchTerm ?? _faker.Lorem.Sentence()
};
}
/// <summary>
/// Creates a list of <see cref="BaseFilterDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BaseFilterDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Filtering;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.Filtering;
/// <summary>
/// Fixture class for the <see cref="LibraryFilterDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryFilterDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LibraryFilterDto"/>.
/// </summary>
/// <param name="libraryId">Optional. The Id of the media library used to filter data.</param>
/// <param name="searchTerm">Optional. The search term used to filter results.</param>
/// <param name="filterAlphaKey">Optional. The alpha key used to filter by the first character of the item title.</param>
/// <param name="shouldIgnoreThePrefixForAlphaPicker">Whether the leading "The " prefix should be ignored when computing the alpha key, or not.</param>
/// <returns>The created <see cref="LibraryFilterDto"/>.</returns>
public LibraryFilterDto Create(
Guid? libraryId = null,
string? searchTerm = null,
string? filterAlphaKey = null,
bool shouldIgnoreThePrefixForAlphaPicker = false)
{
return new LibraryFilterDto
{
LibraryId = libraryId ?? _faker.Random.Guid(),
SearchTerm = searchTerm,
FilterAlphaKey = filterAlphaKey,
ShouldIgnoreThePrefixForAlphaPicker = shouldIgnoreThePrefixForAlphaPicker
};
}
/// <summary>
/// Creates a list of <see cref="LibraryFilterDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="LibraryFilterDto"/> instances.</returns>
public List<LibraryFilterDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Pagination;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.Pagination;
/// <summary>
/// Fixture class for the <see cref="PaginatedResultDto{TData}"/> record.
/// </summary>
/// <typeparam name="TData">The type of the data items contained in the paginated result.</typeparam>
[ExcludeFromCodeCoverage]
public class PaginatedResultDtoFixture<TData>
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PaginatedResultDto{TData}"/>.
/// </summary>
/// <param name="data">Optional. The collection of data items.</param>
/// <param name="currentPage">Optional. The current page number.</param>
/// <param name="perPage">Optional. The number of items per page.</param>
/// <param name="count">Optional. The total number of elements available.</param>
/// <param name="numberOfPages">Optional. The total number of pages.</param>
/// <returns>The created <see cref="PaginatedResultDto{TData}"/>.</returns>
public PaginatedResultDto<TData> Create(
IReadOnlyList<TData>? data = null,
int? currentPage = null,
int? perPage = null,
int? count = null,
int? numberOfPages = null)
{
return new PaginatedResultDto<TData>
{
Data = data ?? [],
CurrentPage = currentPage ?? _faker.Random.Int(1, 10),
PerPage = perPage ?? _faker.Random.Int(1, 100),
Count = count ?? _faker.Random.Int(0, 1000),
NumberOfPages = numberOfPages ?? _faker.Random.Int(1, 100)
};
}
/// <summary>
/// Creates a list of <see cref="PaginatedResultDto{TData}"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PaginatedResultDto{TData}"/> instances.</returns>
public List<PaginatedResultDto<TData>> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,45 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DTO.Pagination;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DTO.Pagination;
/// <summary>
/// Fixture class for the <see cref="PaginationDataDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class PaginationDataDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PaginationDataDto"/>.
/// </summary>
/// <param name="currentPage">Optional. The current page number in a paginated collection.</param>
/// <param name="perPage">Optional. The number of items to include per page in paginated results.</param>
/// <returns>The created <see cref="PaginationDataDto"/>.</returns>
public PaginationDataDto Create(
int? currentPage = null,
int? perPage = null)
{
return new PaginationDataDto
{
CurrentPage = currentPage ?? _faker.Random.Int(1, 100),
PerPage = perPage ?? _faker.Random.Int(1, 200)
};
}
/// <summary>
/// Creates a list of <see cref="PaginationDataDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PaginationDataDto"/> instances.</returns>
public List<PaginationDataDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,61 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="RoleEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class RoleEntityFixture
{
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
/// <summary>
/// Creates a random valid <see cref="RoleEntity"/>.
/// </summary>
/// <param name="id">Optional. The Id of the role.</param>
/// <param name="roleName">Optional. The name of the role.</param>
/// <param name="rolePermissions">Optional. The role permission associations of the role.</param>
/// <param name="includeRolePermissions">Whether the role should include role permission associations or not.</param>
/// <param name="createdBy">Optional. The Id of the user that created the role.</param>
/// <param name="createdOnUtc">Optional. The time and date when the role was added.</param>
/// <returns>The created <see cref="RoleEntity"/>.</returns>
public RoleEntity Create(
Guid? id = null,
string? roleName = null,
IEnumerable<RolePermissionEntity>? rolePermissions = null,
bool includeRolePermissions = false,
Guid? createdBy = null,
DateTime? createdOnUtc = null)
{
return new Faker<RoleEntity>()
.CustomInstantiator(faker => new RoleEntity
{
Id = id ?? faker.Random.Guid(),
RoleName = roleName ?? faker.Random.String2(faker.Random.Number(1, 50)),
RolePermissions = includeRolePermissions ? (rolePermissions ?? _rolePermissionEntityFixture.CreateMany()).ToList() : [],
CreatedOnUtc = createdOnUtc ?? faker.Date.Past(),
CreatedBy = createdBy ?? faker.Random.Guid(),
UpdatedOnUtc = null,
UpdatedBy = null
})
.Generate();
}
/// <summary>
/// Creates a list of <see cref="RoleEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="RoleEntity"/> instances.</returns>
public List<RoleEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -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()
})
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
/// <summary>
/// Fixture class for the <see cref="GenreEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GenreEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="GenreEntity"/>.
/// </summary>
/// <param name="name">Optional. The name of the genre.</param>
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="GenreEntity"/>.</returns>
public GenreEntity Create(
string? name = null,
bool includeName = true)
{
return new GenreEntity(includeName ? name ?? _faker.Lorem.Word() : null);
}
/// <summary>
/// Creates a list of <see cref="GenreEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GenreEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
/// <summary>
/// Fixture class for the <see cref="TagEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class TagEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="TagEntity"/>.
/// </summary>
/// <param name="name">Optional. The name of the tag.</param>
/// <param name="includeName">Whether the name should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="TagEntity"/>.</returns>
public TagEntity Create(
string? name = null,
bool includeName = true)
{
return new TagEntity(includeName ? name ?? _faker.Lorem.Word() : null);
}
/// <summary>
/// Creates a list of <see cref="TagEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<TagEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -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();
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="IsbnEntity"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnEntityFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="value">Optional. The ISBN value.</param>
/// <param name="format">Optional. The format of the ISBN.</param>
/// <param name="includeValue">Whether the value should be included, or forced to <see langword="null"/>.</param>
/// <returns>The created <see cref="IsbnEntity"/>.</returns>
public IsbnEntity Create(
string? value = null,
IsbnFormat? format = null,
bool includeValue = true)
{
return new IsbnEntity(
includeValue ? value ?? _faker.Random.String2(13, "0123456789") : null,
format);
}
/// <summary>
/// Creates a list of <see cref="IsbnEntity"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<IsbnEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -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())
@@ -0,0 +1,46 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
/// <summary>
/// Fixture class for the <see cref="ThemeArchiveDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThemeArchiveDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ThemeArchiveDto"/>.
/// </summary>
/// <param name="bytes">Optional. The bytes of the ZIP archive.</param>
/// <param name="fileName">Optional. The file name to expose when downloading the archive.</param>
/// <param name="contentType">Optional. The MIME content type of the archive.</param>
/// <returns>The created <see cref="ThemeArchiveDto"/>.</returns>
public ThemeArchiveDto Create(
byte[]? bytes = null,
string? fileName = null,
string? contentType = null)
{
return new ThemeArchiveDto(
bytes ?? _faker.Random.Bytes(10),
fileName ?? _faker.System.FileName(),
contentType ?? _faker.System.MimeType());
}
/// <summary>
/// Creates a list of <see cref="ThemeArchiveDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ThemeArchiveDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.Infrastructure.Models.DTO.Themes;
/// <summary>
/// Fixture class for the <see cref="ThemeAssetDto"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThemeAssetDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ThemeAssetDto"/>.
/// </summary>
/// <param name="bytes">Optional. The bytes of the asset file.</param>
/// <param name="contentType">Optional. The MIME content type of the asset file.</param>
/// <returns>The created <see cref="ThemeAssetDto"/>.</returns>
public ThemeAssetDto Create(
byte[]? bytes = null,
string? contentType = null)
{
return new ThemeAssetDto(
bytes ?? _faker.Random.Bytes(10),
contentType ?? _faker.System.MimeType());
}
/// <summary>
/// Creates a list of <see cref="ThemeAssetDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ThemeAssetDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}