mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 18:21:10 +00:00
Standardizes test conventions and documentation
This commit is contained in:
1 parent
7aeed04255
commit
f42dc709de
190 files changed
+2180
-2814
No files matched your search
+23
-12
@@ -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(),
|
||||
|
||||
+10
-4
@@ -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
|
||||
|
||||
+40
-22
@@ -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()
|
||||
})
|
||||
|
||||
+7
-5
@@ -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();
|
||||
|
||||
+23
-7
@@ -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())
|
||||
|
||||
+5
-3
@@ -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(),
|
||||
|
||||
+8
-6
@@ -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>()
|
||||
|
||||
Reference in new issue
Block a user