mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 10:11:10 +00:00
Refactors the test fixtures and their consumers to compose other fixtures instead of instantiating models inline
This commit is contained in:
1 parent
0abda472c6
commit
3aadd6de84
157 files changed
+1312
-597
No files matched your search
+9
-3
@@ -21,16 +21,22 @@ public class PermissionEntityFixture
|
||||
/// </summary>
|
||||
/// <param name="id">Optional. The permission Id.</param>
|
||||
/// <param name="permissionName">Optional. The permission name.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the permission.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the permission was created.</param>
|
||||
/// <returns>The created <see cref="PermissionEntity"/>.</returns>
|
||||
public PermissionEntity Create(Guid? id = null, AuthorizationPermission? permissionName = null)
|
||||
public PermissionEntity Create(
|
||||
Guid? id = null,
|
||||
AuthorizationPermission? permissionName = null,
|
||||
Guid? createdBy = null,
|
||||
DateTime? createdOnUtc = null)
|
||||
{
|
||||
return new Faker<PermissionEntity>()
|
||||
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
||||
.RuleFor(x => x.PermissionName, f => permissionName ?? f.PickRandom<AuthorizationPermission>())
|
||||
.RuleFor(x => x.RolePermissions, [])
|
||||
.RuleFor(x => x.UserPermissions, [])
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.CreatedBy, f => f.Random.Guid())
|
||||
.RuleFor(x => x.CreatedOnUtc, f => createdOnUtc ?? f.Date.Past())
|
||||
.RuleFor(x => x.CreatedBy, f => createdBy ?? f.Random.Guid())
|
||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||
.RuleFor(x => x.UpdatedBy, f => f.Random.Guid())
|
||||
.Generate();
|
||||
|
||||
+12
-24
@@ -1,7 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
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;
|
||||
@@ -16,7 +15,9 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RolePermissionEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
// RoleEntityFixture composes this fixture, so the role fixture is resolved lazily to avoid an eager mutual composition cycle.
|
||||
private readonly Lazy<RoleEntityFixture> _roleEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="RolePermissionEntity"/>.
|
||||
@@ -26,33 +27,20 @@ public class RolePermissionEntityFixture
|
||||
/// <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>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the association was created.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the association.</param>
|
||||
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
|
||||
public RolePermissionEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? roleId = null,
|
||||
RoleEntity? role = null,
|
||||
Guid? permissionId = null,
|
||||
PermissionEntity? permission = null)
|
||||
PermissionEntity? permission = null,
|
||||
DateTime? createdOnUtc = null,
|
||||
Guid? createdBy = null)
|
||||
{
|
||||
RoleEntity resolvedRole = role ?? new RoleEntity
|
||||
{
|
||||
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()
|
||||
};
|
||||
|
||||
PermissionEntity resolvedPermission = permission ?? new PermissionEntity
|
||||
{
|
||||
Id = permissionId ?? _faker.Random.Guid(),
|
||||
PermissionName = _faker.PickRandom<AuthorizationPermission>(),
|
||||
CreatedOnUtc = _faker.Date.Past(),
|
||||
CreatedBy = _faker.Random.Guid(),
|
||||
UpdatedOnUtc = _faker.Date.Recent(),
|
||||
UpdatedBy = _faker.Random.Guid()
|
||||
};
|
||||
RoleEntity resolvedRole = role ?? _roleEntityFixture.Value.Create(id: roleId);
|
||||
PermissionEntity resolvedPermission = permission ?? _permissionEntityFixture.Create(id: permissionId);
|
||||
|
||||
return new Faker<RolePermissionEntity>()
|
||||
.CustomInstantiator(f => new RolePermissionEntity
|
||||
@@ -62,8 +50,8 @@ public class RolePermissionEntityFixture
|
||||
Role = role ?? resolvedRole,
|
||||
PermissionId = resolvedPermission.Id,
|
||||
Permission = permission ?? resolvedPermission,
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid(),
|
||||
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||
CreatedBy = createdBy ?? f.Random.Guid(),
|
||||
UpdatedOnUtc = f.Date.Recent(),
|
||||
UpdatedBy = f.Random.Guid()
|
||||
})
|
||||
|
||||
+10
-3
@@ -2,6 +2,7 @@
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -18,8 +19,14 @@ public class UserPermissionEntityFixture
|
||||
/// </summary>
|
||||
/// <param name="user">The user the permission is granted to.</param>
|
||||
/// <param name="permission">The permission granted to the user.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the association was created.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the association.</param>
|
||||
/// <returns>The created <see cref="UserPermissionEntity"/>.</returns>
|
||||
public UserPermissionEntity Create(UserEntity user, PermissionEntity permission)
|
||||
public UserPermissionEntity Create(
|
||||
UserEntity user,
|
||||
PermissionEntity permission,
|
||||
DateTime? createdOnUtc = null,
|
||||
Guid? createdBy = null)
|
||||
{
|
||||
return new Faker<UserPermissionEntity>()
|
||||
.CustomInstantiator(f => new UserPermissionEntity
|
||||
@@ -29,8 +36,8 @@ public class UserPermissionEntityFixture
|
||||
User = user,
|
||||
PermissionId = permission.Id,
|
||||
Permission = permission,
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = user.Id,
|
||||
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||
CreatedBy = createdBy ?? user.Id,
|
||||
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
|
||||
UpdatedBy = f.Random.Bool() ? user.Id : null
|
||||
})
|
||||
|
||||
+15
-24
@@ -2,6 +2,7 @@
|
||||
using Bogus;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -16,7 +17,8 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserRoleEntityFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="UserRoleEntity"/>.
|
||||
@@ -26,44 +28,33 @@ public class UserRoleEntityFixture
|
||||
/// <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>
|
||||
/// <param name="includeUser">Whether the user should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the association was created.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the association.</param>
|
||||
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
|
||||
public UserRoleEntity Create(
|
||||
Guid? id = null,
|
||||
Guid? userId = null,
|
||||
UserEntity? user = null,
|
||||
Guid? roleId = null,
|
||||
RoleEntity? role = null)
|
||||
RoleEntity? role = null,
|
||||
bool includeUser = true,
|
||||
DateTime? createdOnUtc = null,
|
||||
Guid? createdBy = 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()
|
||||
};
|
||||
UserEntity resolvedUser = user ?? _userEntityFixture.Create(id: userId);
|
||||
RoleEntity resolvedRole = role ?? _roleEntityFixture.Create(id: roleId);
|
||||
|
||||
return new Faker<UserRoleEntity>()
|
||||
.CustomInstantiator(f => new UserRoleEntity
|
||||
{
|
||||
Id = id ?? f.Random.Guid(),
|
||||
UserId = resolvedUser.Id,
|
||||
User = user ?? resolvedUser,
|
||||
User = includeUser ? (user ?? resolvedUser) : null!,
|
||||
RoleId = resolvedRole.Id,
|
||||
Role = role ?? resolvedRole,
|
||||
CreatedOnUtc = f.Date.Past(),
|
||||
CreatedBy = f.Random.Guid()
|
||||
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||
CreatedBy = createdBy ?? f.Random.Guid()
|
||||
})
|
||||
.Generate();
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Ma
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryEntityFixture
|
||||
{
|
||||
private readonly LibraryContentLocationEntityFixture _libraryContentLocationEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="LibraryEntity"/>.
|
||||
/// </summary>
|
||||
@@ -76,7 +78,7 @@ public class LibraryEntityFixture
|
||||
.RuleFor(library => library.ContentLocations, f =>
|
||||
{
|
||||
IEnumerable<string> paths = contentLocations ?? [f.System.DirectoryPath(), f.System.DirectoryPath()];
|
||||
return [.. paths.Select(path => new LibraryContentLocationEntity() { Path = path })];
|
||||
return [.. paths.Select(path => _libraryContentLocationEntityFixture.Create(path: path))];
|
||||
})
|
||||
.RuleFor(library => library.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(library => library.CreatedBy, f => f.Random.Guid())
|
||||
|
||||
+7
-3
@@ -32,6 +32,8 @@ public class UserEntityFixture
|
||||
/// <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>
|
||||
/// <param name="includeUserRole">Whether the user role association should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeUserPermissions">Whether the user permission associations should be included, or forced to an empty collection.</param>
|
||||
/// <param name="createdBy">Optional. The Id of the user that created the user.</param>
|
||||
/// <param name="createdOnUtc">Optional. The time and date when the user was created.</param>
|
||||
/// <returns>The created user entity.</returns>
|
||||
public UserEntity Create(
|
||||
int libraryCount = 0,
|
||||
@@ -42,7 +44,9 @@ public class UserEntityFixture
|
||||
IEnumerable<UserPermissionEntity>? userPermissions = null,
|
||||
ICollection<LibraryEntity>? libraries = null,
|
||||
bool includeUserRole = false,
|
||||
bool includeUserPermissions = false)
|
||||
bool includeUserPermissions = false,
|
||||
Guid? createdBy = null,
|
||||
DateTime? createdOnUtc = null)
|
||||
{
|
||||
Guid userId = id ?? Guid.NewGuid();
|
||||
ICollection<LibraryEntity> resolvedLibraries = libraries ?? (libraryCount > 0
|
||||
@@ -60,11 +64,11 @@ public class UserEntityFixture
|
||||
Libraries = resolvedLibraries,
|
||||
UserPermissions = includeUserPermissions ? (userPermissions ?? []).ToList() : [],
|
||||
UserRole = includeUserRole ? userRole : null,
|
||||
CreatedBy = userId
|
||||
CreatedBy = createdBy ?? userId
|
||||
})
|
||||
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
|
||||
.RuleFor(x => x.Password, f => password ?? Uri.EscapeDataString(f.Internet.Password()))
|
||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
||||
.RuleFor(x => x.CreatedOnUtc, f => createdOnUtc ?? f.Date.Past())
|
||||
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
|
||||
.Generate();
|
||||
}
|
||||
|
||||
+3
-2
@@ -19,15 +19,16 @@ public class CheckPathExistsQueryFixture
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path.</param>
|
||||
/// <param name="shouldIncludeHiddenElements">Whether to include hidden file system elements or not.</param>
|
||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public CheckPathExistsQuery Create(string? path = null, bool shouldIncludeHiddenElements = true)
|
||||
public CheckPathExistsQuery Create(string? path = null, bool shouldIncludeHiddenElements = true, bool includePath = true)
|
||||
{
|
||||
return new Faker<CheckPathExistsQuery>()
|
||||
.CustomInstantiator(f => new CheckPathExistsQuery(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
|
||||
.RuleFor(x => x.Path, f => includePath ? (path ?? f.System.FilePath()) : null)
|
||||
.RuleFor(x => x.ShouldIncludeHiddenElements, shouldIncludeHiddenElements);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -18,13 +18,14 @@ public class ValidatePathQueryFixture
|
||||
/// Creates a random valid query to validate a path.
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path.</param>
|
||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public ValidatePathQuery Create(string? path = null)
|
||||
public ValidatePathQuery Create(string? path = null, bool includePath = true)
|
||||
{
|
||||
return new Faker<ValidatePathQuery>()
|
||||
.CustomInstantiator(f => new ValidatePathQuery(
|
||||
default!))
|
||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
|
||||
.RuleFor(x => x.Path, f => includePath ? (path ?? f.System.FilePath()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-2
@@ -19,15 +19,16 @@ public class GetThumbnailQueryFixture
|
||||
/// </summary>
|
||||
/// <param name="path">Optional. The file system path.</param>
|
||||
/// <param name="quality">Optional. The thumbnail quality.</param>
|
||||
/// <param name="includePath">Whether the path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetThumbnailQuery Create(string? path = null, int? quality = null)
|
||||
public GetThumbnailQuery Create(string? path = null, int? quality = null, bool includePath = true)
|
||||
{
|
||||
return new Faker<GetThumbnailQuery>()
|
||||
.CustomInstantiator(f => new GetThumbnailQuery(
|
||||
default!,
|
||||
default
|
||||
))
|
||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
|
||||
.RuleFor(x => x.Path, f => includePath ? (path ?? f.System.FilePath()) : null)
|
||||
.RuleFor(x => x.Quality, f => quality ?? f.Random.Int());
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -19,8 +19,9 @@ public class RecoverPasswordCommandFixture
|
||||
/// </summary>
|
||||
/// <param name="username">Optional. The username.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public RecoverPasswordCommand Create(string? username = null, string? totpCode = null)
|
||||
public RecoverPasswordCommand Create(string? username = null, string? totpCode = null, bool includeTotpCode = true)
|
||||
{
|
||||
return new Faker<RecoverPasswordCommand>()
|
||||
.CustomInstantiator(f => new RecoverPasswordCommand(
|
||||
@@ -28,7 +29,7 @@ public class RecoverPasswordCommandFixture
|
||||
default!
|
||||
))
|
||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
||||
.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######"));
|
||||
.RuleFor(x => x.TotpCode, f => includeTotpCode ? (totpCode ?? f.Random.Replace("######")) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+6
-3
@@ -20,13 +20,16 @@ public class LoginUserQueryFixture
|
||||
/// <param name="username">Optional. The username.</param>
|
||||
/// <param name="password">Optional. The password.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code. When provided, the TOTP code is included even if <paramref name="includeTotpCode"/> is <see langword="false"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public LoginUserQuery Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
bool includeTotpCode = false)
|
||||
bool includeTotpCode = false,
|
||||
string? totpCode = null)
|
||||
{
|
||||
string resolvedPassword = password ?? "Abcd123$";
|
||||
bool shouldIncludeTotpCode = includeTotpCode || totpCode is not null;
|
||||
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
|
||||
.CustomInstantiator(f => new LoginUserQuery(
|
||||
default!,
|
||||
@@ -36,8 +39,8 @@ public class LoginUserQueryFixture
|
||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
||||
.RuleFor(x => x.Password, resolvedPassword);
|
||||
|
||||
if (includeTotpCode)
|
||||
faker.RuleFor(x => x.TotpCode, f => f.Random.Replace("######")); // generates 6 random digits
|
||||
if (shouldIncludeTotpCode)
|
||||
faker.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######")); // generates 6 random digits when no code is pinned
|
||||
return faker.Generate();
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -22,19 +22,23 @@ public class UpdateUserRoleAndPermissionsCommandFixture
|
||||
/// <param name="roleId">Optional. The role Id to assign. If null, no role will be assigned.</param>
|
||||
/// <param name="permissions">Optional. The permission Ids to assign.</param>
|
||||
/// <param name="permissionCount">The number of permissions to generate when none are provided.</param>
|
||||
/// <param name="includePermissions">Whether the permissions should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created command.</returns>
|
||||
public UpdateUserRoleAndPermissionsCommand Create(
|
||||
Guid? userId = null,
|
||||
Guid? roleId = null,
|
||||
IEnumerable<Guid>? permissions = null,
|
||||
int permissionCount = 3)
|
||||
int permissionCount = 3,
|
||||
bool includePermissions = true)
|
||||
{
|
||||
return new Faker<UpdateUserRoleAndPermissionsCommand>()
|
||||
.CustomInstantiator(f => new UpdateUserRoleAndPermissionsCommand(
|
||||
userId ?? Guid.NewGuid(),
|
||||
roleId,
|
||||
default!))
|
||||
.RuleFor(x => x.Permissions, f => [.. permissions ?? Enumerable.Range(0, permissionCount).Select(_ => Guid.NewGuid())])
|
||||
.RuleFor(x => x.Permissions, f => includePermissions
|
||||
? [.. permissions ?? Enumerable.Range(0, permissionCount).Select(_ => Guid.NewGuid())]
|
||||
: null!)
|
||||
.Generate();
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -19,12 +19,13 @@ public class GetUserPermissionsQueryFixture
|
||||
/// Creates a random valid query to get user permissions.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The user Id.</param>
|
||||
/// <param name="includeUserId">Whether the user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetUserPermissionsQuery Create(Guid? userId = null)
|
||||
public GetUserPermissionsQuery Create(Guid? userId = null, bool includeUserId = true)
|
||||
{
|
||||
return new Faker<GetUserPermissionsQuery>()
|
||||
.CustomInstantiator(f => new GetUserPermissionsQuery(
|
||||
userId ?? Guid.NewGuid()))
|
||||
includeUserId ? (userId ?? Guid.NewGuid()) : null))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -19,12 +19,13 @@ public class GetUserRoleQueryFixture
|
||||
/// Creates a random valid query to get a user's role.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The user Id.</param>
|
||||
/// <param name="includeUserId">Whether the user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created query.</returns>
|
||||
public GetUserRoleQuery Create(Guid? userId = null)
|
||||
public GetUserRoleQuery Create(Guid? userId = null, bool includeUserId = true)
|
||||
{
|
||||
return new Faker<GetUserRoleQuery>()
|
||||
.CustomInstantiator(f => new GetUserRoleQuery(
|
||||
userId ?? Guid.NewGuid()))
|
||||
includeUserId ? (userId ?? Guid.NewGuid()) : null))
|
||||
.Generate();
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Contracts.DTO.Common.Pagination;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.Fixtures.Core.DTO.Common.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>
|
||||
/// <param name="includeCurrentPage">Whether the current page should be included, or left at its default value.</param>
|
||||
/// <param name="includePerPage">Whether the per page count should be included, or left at its default value.</param>
|
||||
/// <returns>The created <see cref="PaginationDataDto"/>.</returns>
|
||||
public PaginationDataDto Create(
|
||||
int? currentPage = null,
|
||||
int? perPage = null,
|
||||
bool includeCurrentPage = true,
|
||||
bool includePerPage = true)
|
||||
{
|
||||
PaginationDataDto dto = new();
|
||||
if (includeCurrentPage)
|
||||
dto.CurrentPage = currentPage ?? _faker.Random.Int(1, 100);
|
||||
if (includePerPage)
|
||||
dto.PerPage = perPage ?? _faker.Random.Int(1, 200);
|
||||
return dto;
|
||||
}
|
||||
|
||||
/// <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())];
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -16,6 +16,7 @@ namespace Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
public class MediaContributorDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random valid <see cref="MediaContributorDto"/>.
|
||||
@@ -38,9 +39,12 @@ public class MediaContributorDtoFixture
|
||||
bool includeRole = true)
|
||||
{
|
||||
return new MediaContributorDto(
|
||||
Name: includeName ? new MediaContributorNameDto(
|
||||
DisplayName: includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
||||
LegalName: includeLegalName ? legalName : null) : null,
|
||||
Name: includeName ? _mediaContributorNameDtoFixture.Create(
|
||||
displayName: displayName,
|
||||
legalName: legalName,
|
||||
includeDisplayName: includeDisplayName,
|
||||
// this fixture historically left the legal name null unless one was explicitly supplied, so the name fixture is only asked for one when a value is passed
|
||||
includeLegalName: includeLegalName && legalName is not null) : null,
|
||||
Role: includeRole ? role ?? _faker.PickRandom<MediaContributorRole>() : null);
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -21,14 +21,18 @@ public class MediaContributorNameDtoFixture
|
||||
/// </summary>
|
||||
/// <param name="displayName">Optional. The display name of the media contributor.</param>
|
||||
/// <param name="legalName">Optional. The legal name of the media contributor.</param>
|
||||
/// <param name="includeDisplayName">Whether the display name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeLegalName">Whether the legal name should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="MediaContributorNameDto"/>.</returns>
|
||||
public MediaContributorNameDto Create(
|
||||
string? displayName = null,
|
||||
string? legalName = null)
|
||||
string? legalName = null,
|
||||
bool includeDisplayName = true,
|
||||
bool includeLegalName = true)
|
||||
{
|
||||
return new MediaContributorNameDto(
|
||||
displayName ?? _faker.Name.FullName(),
|
||||
legalName ?? _faker.Name.FullName());
|
||||
includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
||||
includeLegalName ? legalName ?? _faker.Name.FullName() : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+13
-5
@@ -23,19 +23,27 @@ public class ChangePasswordRequestFixture
|
||||
/// <param name="currentPassword">Optional. The current password.</param>
|
||||
/// <param name="newPassword">Optional. The new password.</param>
|
||||
/// <param name="newPasswordConfirm">Optional. The new password confirmation.</param>
|
||||
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeCurrentPassword">Whether the current password should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeNewPassword">Whether the new password should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeNewPasswordConfirm">Whether the new password confirmation should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ChangePasswordRequest"/>.</returns>
|
||||
public ChangePasswordRequest Create(
|
||||
string? username = null,
|
||||
string? currentPassword = null,
|
||||
string? newPassword = null,
|
||||
string? newPasswordConfirm = null)
|
||||
string? newPasswordConfirm = null,
|
||||
bool includeUsername = true,
|
||||
bool includeCurrentPassword = true,
|
||||
bool includeNewPassword = true,
|
||||
bool includeNewPasswordConfirm = true)
|
||||
{
|
||||
string generatedNewPassword = newPassword ?? _faker.Internet.Password();
|
||||
return new ChangePasswordRequest(
|
||||
username ?? _faker.Internet.UserName(),
|
||||
currentPassword ?? _faker.Internet.Password(),
|
||||
generatedNewPassword,
|
||||
newPasswordConfirm ?? generatedNewPassword
|
||||
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||
includeCurrentPassword ? (currentPassword ?? _faker.Internet.Password()) : null,
|
||||
includeNewPassword ? generatedNewPassword : null,
|
||||
includeNewPasswordConfirm ? (newPasswordConfirm ?? generatedNewPassword) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -22,16 +22,22 @@ public class LoginRequestFixture
|
||||
/// <param name="username">Optional. The username for login.</param>
|
||||
/// <param name="password">Optional. The password for login.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code for two-factor authentication.</param>
|
||||
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePassword">Whether the password should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="LoginRequest"/>.</returns>
|
||||
public LoginRequest Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
string? totpCode = null)
|
||||
string? totpCode = null,
|
||||
bool includeUsername = true,
|
||||
bool includePassword = true,
|
||||
bool includeTotpCode = true)
|
||||
{
|
||||
return new LoginRequest(
|
||||
username ?? _faker.Internet.UserName(),
|
||||
password ?? _faker.Internet.Password(),
|
||||
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
||||
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||
includePassword ? (password ?? _faker.Internet.Password()) : null,
|
||||
includeTotpCode ? (totpCode ?? _faker.Random.Number(100000, 999999).ToString()) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -21,14 +21,18 @@ public class RecoverPasswordRequestFixture
|
||||
/// </summary>
|
||||
/// <param name="username">Optional. The username for password recovery.</param>
|
||||
/// <param name="totpCode">Optional. The TOTP code for verification.</param>
|
||||
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeTotpCode">Whether the TOTP code should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="RecoverPasswordRequest"/>.</returns>
|
||||
public RecoverPasswordRequest Create(
|
||||
string? username = null,
|
||||
string? totpCode = null)
|
||||
string? totpCode = null,
|
||||
bool includeUsername = true,
|
||||
bool includeTotpCode = true)
|
||||
{
|
||||
return new RecoverPasswordRequest(
|
||||
username ?? _faker.Internet.UserName(),
|
||||
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
||||
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||
includeTotpCode ? (totpCode ?? _faker.Random.Number(100000, 999999).ToString()) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -23,18 +23,24 @@ public class RegistrationRequestFixture
|
||||
/// <param name="password">Optional. The password for registration.</param>
|
||||
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
|
||||
/// <param name="use2fa">Optional. Whether to use two-factor authentication.</param>
|
||||
/// <param name="includeUsername">Whether the username should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePassword">Whether the password should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePasswordConfirm">Whether the password confirmation should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
|
||||
public RegistrationRequest Create(
|
||||
string? username = null,
|
||||
string? password = null,
|
||||
string? passwordConfirm = null,
|
||||
bool? use2fa = null)
|
||||
bool? use2fa = null,
|
||||
bool includeUsername = true,
|
||||
bool includePassword = true,
|
||||
bool includePasswordConfirm = true)
|
||||
{
|
||||
string generatedPassword = password ?? _faker.Internet.Password();
|
||||
return new RegistrationRequest(
|
||||
username ?? _faker.Internet.UserName(),
|
||||
generatedPassword,
|
||||
passwordConfirm ?? generatedPassword,
|
||||
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||
includePassword ? generatedPassword : null,
|
||||
includePasswordConfirm ? (passwordConfirm ?? generatedPassword) : null,
|
||||
use2fa ?? _faker.Random.Bool()
|
||||
);
|
||||
}
|
||||
|
||||
+4
-2
@@ -22,12 +22,14 @@ public class AddRoleRequestFixture
|
||||
/// </summary>
|
||||
/// <param name="roleName">Optional. The name of the role.</param>
|
||||
/// <param name="permissions">Optional. The Ids of the permissions granted to the role.</param>
|
||||
/// <param name="includePermissions">Whether the permissions should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="AddRoleRequest"/>.</returns>
|
||||
public AddRoleRequest Create(
|
||||
string? roleName = null,
|
||||
List<Guid>? permissions = null)
|
||||
List<Guid>? permissions = null,
|
||||
bool includePermissions = true)
|
||||
{
|
||||
return new AddRoleRequest(roleName ?? _faker.Commerce.Department(), permissions ?? []);
|
||||
return new AddRoleRequest(roleName ?? _faker.Commerce.Department(), includePermissions ? (permissions ?? []) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-2
@@ -21,11 +21,13 @@ public class DeleteRoleRequestFixture
|
||||
/// Creates a random valid <see cref="DeleteRoleRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="roleId">Optional. The Id of the role to delete.</param>
|
||||
/// <param name="includeRoleId">Whether the role Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="DeleteRoleRequest"/>.</returns>
|
||||
public DeleteRoleRequest Create(
|
||||
Guid? roleId = null)
|
||||
Guid? roleId = null,
|
||||
bool includeRoleId = true)
|
||||
{
|
||||
return new DeleteRoleRequest(roleId ?? Guid.NewGuid());
|
||||
return new DeleteRoleRequest(includeRoleId ? (roleId ?? Guid.NewGuid()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-2
@@ -18,11 +18,12 @@ public class GetAuthorizationRequestFixture
|
||||
/// Creates a <see cref="GetAuthorizationRequest"/> with default or specified values.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The user Id to use.</param>
|
||||
/// <param name="includeUserId">Whether the user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetAuthorizationRequest"/>.</returns>
|
||||
public GetAuthorizationRequest Create(Guid? userId = null)
|
||||
public GetAuthorizationRequest Create(Guid? userId = null, bool includeUserId = true)
|
||||
{
|
||||
return new GetAuthorizationRequest(
|
||||
UserId: userId ?? Guid.NewGuid()
|
||||
UserId: includeUserId ? (userId ?? Guid.NewGuid()) : null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -18,11 +18,13 @@ public class GetUserPermissionsRequestFixture
|
||||
/// Creates a random valid <see cref="GetUserPermissionsRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The Id of the user whose permissions are retrieved.</param>
|
||||
/// <param name="includeUserId">Whether the user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetUserPermissionsRequest"/>.</returns>
|
||||
public GetUserPermissionsRequest Create(
|
||||
Guid? userId = null)
|
||||
Guid? userId = null,
|
||||
bool includeUserId = true)
|
||||
{
|
||||
return new GetUserPermissionsRequest(userId ?? Guid.NewGuid());
|
||||
return new GetUserPermissionsRequest(includeUserId ? (userId ?? Guid.NewGuid()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-2
@@ -18,11 +18,13 @@ public class GetUserRoleRequestFixture
|
||||
/// Creates a random valid <see cref="GetUserRoleRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="userId">Optional. The Id of the user whose role is retrieved.</param>
|
||||
/// <param name="includeUserId">Whether the user Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetUserRoleRequest"/>.</returns>
|
||||
public GetUserRoleRequest Create(
|
||||
Guid? userId = null)
|
||||
Guid? userId = null,
|
||||
bool includeUserId = true)
|
||||
{
|
||||
return new GetUserRoleRequest(userId ?? Guid.NewGuid());
|
||||
return new GetUserRoleRequest(includeUserId ? (userId ?? Guid.NewGuid()) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-2
@@ -23,15 +23,17 @@ public class UpdateUserRoleAndPermissionsRequestFixture
|
||||
/// <param name="userId">Optional. The Id of the user whose role and permissions are updated.</param>
|
||||
/// <param name="roleId">Optional. The Id of the role assigned to the user.</param>
|
||||
/// <param name="permissions">Optional. The Ids of the permissions assigned to the user.</param>
|
||||
/// <param name="includeRoleId">Whether the role Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="UpdateUserRoleAndPermissionsRequest"/>.</returns>
|
||||
public UpdateUserRoleAndPermissionsRequest Create(
|
||||
Guid? userId = null,
|
||||
Guid? roleId = null,
|
||||
List<Guid>? permissions = null)
|
||||
List<Guid>? permissions = null,
|
||||
bool includeRoleId = true)
|
||||
{
|
||||
return new UpdateUserRoleAndPermissionsRequest(
|
||||
userId ?? Guid.NewGuid(),
|
||||
roleId ?? Guid.NewGuid(),
|
||||
includeRoleId ? (roleId ?? Guid.NewGuid()) : null,
|
||||
permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
|
||||
);
|
||||
}
|
||||
|
||||
+9
-5
@@ -22,17 +22,21 @@ public class UpdatePluginSettingsRequestFixture
|
||||
/// </summary>
|
||||
/// <param name="pluginId">Optional. The Id of the plugin whose settings are updated.</param>
|
||||
/// <param name="settings">Optional. The settings to apply to the plugin.</param>
|
||||
/// <param name="includeSettings">Whether the settings should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="UpdatePluginSettingsRequest"/>.</returns>
|
||||
public UpdatePluginSettingsRequest Create(
|
||||
Guid? pluginId = null,
|
||||
IReadOnlyDictionary<string, string>? settings = null)
|
||||
IReadOnlyDictionary<string, string>? settings = null,
|
||||
bool includeSettings = true)
|
||||
{
|
||||
return new UpdatePluginSettingsRequest(
|
||||
pluginId ?? _faker.Random.Guid(),
|
||||
settings ?? new Dictionary<string, string>
|
||||
{
|
||||
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
||||
}
|
||||
includeSettings
|
||||
? settings ?? new Dictionary<string, string>
|
||||
{
|
||||
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
||||
}
|
||||
: null
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -20,10 +20,11 @@ public class DeleteThemeRequestFixture
|
||||
/// Creates a random valid <see cref="DeleteThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme to delete.</param>
|
||||
/// <param name="includeThemeId">Whether the theme Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="DeleteThemeRequest"/>.</returns>
|
||||
public DeleteThemeRequest Create(string? themeId = null)
|
||||
public DeleteThemeRequest Create(string? themeId = null, bool includeThemeId = true)
|
||||
{
|
||||
return new DeleteThemeRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
return new DeleteThemeRequest(includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-2
@@ -20,10 +20,11 @@ public class GetThemeArchiveRequestFixture
|
||||
/// Creates a random valid <see cref="GetThemeArchiveRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="includeThemeId">Whether the theme Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetThemeArchiveRequest"/>.</returns>
|
||||
public GetThemeArchiveRequest Create(string? themeId = null)
|
||||
public GetThemeArchiveRequest Create(string? themeId = null, bool includeThemeId = true)
|
||||
{
|
||||
return new GetThemeArchiveRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
return new GetThemeArchiveRequest(includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+10
-3
@@ -21,12 +21,19 @@ public class GetThemeAssetRequestFixture
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="assetPath">Optional. The asset path relative to the theme pack root.</param>
|
||||
/// <param name="includeThemeId">Whether the theme Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeAssetPath">Whether the asset path should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetThemeAssetRequest"/>.</returns>
|
||||
public GetThemeAssetRequest Create(string? themeId = null, string? assetPath = null)
|
||||
public GetThemeAssetRequest Create(
|
||||
string? themeId = null,
|
||||
string? assetPath = null,
|
||||
bool includeThemeId = true,
|
||||
bool includeAssetPath = true)
|
||||
{
|
||||
return new GetThemeAssetRequest(
|
||||
themeId ?? _faker.Lorem.Slug(2),
|
||||
assetPath ?? _faker.System.FilePath());
|
||||
includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null,
|
||||
includeAssetPath ? (assetPath ?? _faker.System.FilePath()) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+10
-3
@@ -21,12 +21,19 @@ public class GetThemeTemplateRequestFixture
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
||||
/// <param name="pageKey">Optional. The page key that selects the template.</param>
|
||||
/// <param name="includeThemeId">Whether the theme Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includePageKey">Whether the page key should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="GetThemeTemplateRequest"/>.</returns>
|
||||
public GetThemeTemplateRequest Create(string? themeId = null, string? pageKey = null)
|
||||
public GetThemeTemplateRequest Create(
|
||||
string? themeId = null,
|
||||
string? pageKey = null,
|
||||
bool includeThemeId = true,
|
||||
bool includePageKey = true)
|
||||
{
|
||||
return new GetThemeTemplateRequest(
|
||||
themeId ?? _faker.Lorem.Slug(2),
|
||||
pageKey ?? _faker.Lorem.Word());
|
||||
includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null,
|
||||
includePageKey ? (pageKey ?? _faker.Lorem.Word()) : null
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+3
-2
@@ -20,10 +20,11 @@ public class SetCurrentThemeRequestFixture
|
||||
/// Creates a random valid <see cref="SetCurrentThemeRequest"/>.
|
||||
/// </summary>
|
||||
/// <param name="themeId">Optional. The manifest id of the theme to activate.</param>
|
||||
/// <param name="includeThemeId">Whether the theme Id should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="SetCurrentThemeRequest"/>.</returns>
|
||||
public SetCurrentThemeRequest Create(string? themeId = null)
|
||||
public SetCurrentThemeRequest Create(string? themeId = null, bool includeThemeId = true)
|
||||
{
|
||||
return new SetCurrentThemeRequest(themeId ?? _faker.Lorem.Slug(2));
|
||||
return new SetCurrentThemeRequest(includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+9
-2
@@ -5,10 +5,17 @@ using System.Diagnostics.CodeAnalysis;
|
||||
namespace Lumina.Infrastructure.Fixtures.Common.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support placeholder class for validation options tests.
|
||||
/// Test-support placeholder options type used as the validated options in validation options tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidationOptionsFixture
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValidationOptionsFixture"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>A configured <see cref="ValidationOptionsFixture"/> instance.</returns>
|
||||
public ValidationOptionsFixture Create()
|
||||
{
|
||||
return new ValidationOptionsFixture();
|
||||
}
|
||||
}
|
||||
+49
-64
@@ -1,6 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using Lumina.Infrastructure.Core.Authorization;
|
||||
using System;
|
||||
@@ -16,6 +18,13 @@ namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AuthorizationServiceFixture
|
||||
{
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||
private readonly PermissionEntityFixture _permissionEntityFixture = new();
|
||||
private readonly RolePermissionEntityFixture _rolePermissionEntityFixture = new();
|
||||
private readonly UserRoleEntityFixture _userRoleEntityFixture = new();
|
||||
private readonly UserPermissionEntityFixture _userPermissionEntityFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a user entity with specified permissions and roles.
|
||||
/// </summary>
|
||||
@@ -28,7 +37,6 @@ public class AuthorizationServiceFixture
|
||||
{
|
||||
Guid userId = Guid.NewGuid();
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
List<UserPermissionEntity> userPermissions = [];
|
||||
UserRoleEntity? userRole = null;
|
||||
|
||||
if (rolePermissions is not null)
|
||||
@@ -36,86 +44,63 @@ public class AuthorizationServiceFixture
|
||||
foreach (KeyValuePair<string, IEnumerable<AuthorizationPermission>> rolePerm in rolePermissions)
|
||||
{
|
||||
Guid roleId = Guid.NewGuid();
|
||||
RoleEntity role = new()
|
||||
{
|
||||
Id = roleId,
|
||||
RoleName = rolePerm.Key,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId,
|
||||
RolePermissions = []
|
||||
};
|
||||
RoleEntity role = _roleEntityFixture.Create(
|
||||
id: roleId,
|
||||
roleName: rolePerm.Key,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
foreach (AuthorizationPermission permission in rolePerm.Value)
|
||||
{
|
||||
Guid permissionId = Guid.NewGuid();
|
||||
PermissionEntity permissionEntity = new()
|
||||
{
|
||||
Id = permissionId,
|
||||
PermissionName = permission,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId
|
||||
};
|
||||
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||
id: permissionId,
|
||||
permissionName: permission,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
role.RolePermissions.Add(new RolePermissionEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
RoleId = roleId,
|
||||
Role = role,
|
||||
PermissionId = permissionId,
|
||||
Permission = permissionEntity,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId
|
||||
});
|
||||
role.RolePermissions.Add(_rolePermissionEntityFixture.Create(
|
||||
role: role,
|
||||
permission: permissionEntity,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow));
|
||||
}
|
||||
|
||||
userRole = new UserRoleEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
User = null!,
|
||||
RoleId = roleId,
|
||||
Role = role,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId
|
||||
};
|
||||
userRole = _userRoleEntityFixture.Create(
|
||||
userId: userId,
|
||||
roleId: roleId,
|
||||
role: role,
|
||||
includeUser: false,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
}
|
||||
}
|
||||
|
||||
UserEntity user = new()
|
||||
{
|
||||
Id = userId,
|
||||
Username = "test-user",
|
||||
Password = "hashed-password",
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId,
|
||||
Libraries = [],
|
||||
UserPermissions = userPermissions,
|
||||
UserRole = userRole
|
||||
};
|
||||
UserEntity user = _userEntityFixture.Create(
|
||||
username: "test-user",
|
||||
password: "hashed-password",
|
||||
id: userId,
|
||||
userRole: userRole,
|
||||
includeUserRole: true,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
if (directPermissions is not null)
|
||||
{
|
||||
foreach (AuthorizationPermission permission in directPermissions)
|
||||
{
|
||||
Guid permissionId = Guid.NewGuid();
|
||||
PermissionEntity permissionEntity = new()
|
||||
{
|
||||
Id = permissionId,
|
||||
PermissionName = permission,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId
|
||||
};
|
||||
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||
id: permissionId,
|
||||
permissionName: permission,
|
||||
createdBy: userId,
|
||||
createdOnUtc: utcNow);
|
||||
|
||||
userPermissions.Add(new UserPermissionEntity
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = userId,
|
||||
User = user,
|
||||
PermissionId = permissionId,
|
||||
Permission = permissionEntity,
|
||||
CreatedOnUtc = utcNow,
|
||||
CreatedBy = userId
|
||||
});
|
||||
user.UserPermissions.Add(_userPermissionEntityFixture.Create(
|
||||
user,
|
||||
permissionEntity,
|
||||
createdOnUtc: utcNow,
|
||||
createdBy: userId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
@@ -16,21 +17,20 @@ namespace Lumina.Infrastructure.Fixtures.Core.Security;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CryptographyServiceFixture
|
||||
{
|
||||
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a valid encryption settings model for testing.
|
||||
/// </summary>
|
||||
/// <returns>The configured options.</returns>
|
||||
public static IOptions<EncryptionSettingsDto> CreateEncryptionSettings()
|
||||
public IOptions<EncryptionSettingsDto> CreateEncryptionSettings()
|
||||
{
|
||||
// Generate a valid 256-bit (32 byte) key for AES-256
|
||||
byte[] key = new byte[32];
|
||||
RandomNumberGenerator.Fill(key);
|
||||
string base64Key = Convert.ToBase64String(key);
|
||||
|
||||
EncryptionSettingsDto settings = new()
|
||||
{
|
||||
SecretKey = base64Key
|
||||
};
|
||||
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: base64Key);
|
||||
|
||||
IOptions<EncryptionSettingsDto> options = Substitute.For<IOptions<EncryptionSettingsDto>>();
|
||||
options.Value.Returns(settings);
|
||||
@@ -42,7 +42,7 @@ public class CryptographyServiceFixture
|
||||
/// Creates test data for encryption/decryption.
|
||||
/// </summary>
|
||||
/// <returns>A string to be encrypted/decrypted.</returns>
|
||||
public static string CreateTestData()
|
||||
public string CreateTestData()
|
||||
{
|
||||
return new Faker().Lorem.Sentence();
|
||||
}
|
||||
|
||||
@@ -20,5 +20,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\src\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Lumina.Application.Fixtures\Lumina.Application.Fixtures.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+20
-7
@@ -23,21 +23,34 @@ internal class OpenLibrarySettingsDtoFixture
|
||||
/// <param name="searchResultLimit">Optional. The maximum number of search results.</param>
|
||||
/// <param name="workEditionLimit">Optional. The maximum number of editions fetched per work.</param>
|
||||
/// <param name="minimumRequestInterval">Optional. The minimum interval between consecutive requests.</param>
|
||||
/// <param name="includeUserAgent">Whether the user agent should be included, or left at its default value.</param>
|
||||
/// <param name="includeSearchResultLimit">Whether the search result limit should be included, or left at its default value.</param>
|
||||
/// <param name="includeWorkEditionLimit">Whether the work edition limit should be included, or left at its default value.</param>
|
||||
/// <param name="includeMinimumRequestInterval">Whether the minimum request interval should be included, or left at its default value.</param>
|
||||
/// <returns>The created <see cref="OpenLibrarySettingsDto"/>.</returns>
|
||||
public OpenLibrarySettingsDto Create(
|
||||
string? userAgent = null,
|
||||
string? contactEmail = null,
|
||||
int? searchResultLimit = null,
|
||||
int? workEditionLimit = null,
|
||||
TimeSpan? minimumRequestInterval = null)
|
||||
TimeSpan? minimumRequestInterval = null,
|
||||
bool includeUserAgent = true,
|
||||
bool includeSearchResultLimit = true,
|
||||
bool includeWorkEditionLimit = true,
|
||||
bool includeMinimumRequestInterval = true)
|
||||
{
|
||||
return new OpenLibrarySettingsDto
|
||||
OpenLibrarySettingsDto settings = new()
|
||||
{
|
||||
UserAgent = userAgent ?? _faker.Internet.UserAgent(),
|
||||
ContactEmail = contactEmail,
|
||||
SearchResultLimit = searchResultLimit ?? _faker.Random.Number(1, 50),
|
||||
WorkEditionLimit = workEditionLimit ?? _faker.Random.Number(1, 200),
|
||||
MinimumRequestInterval = minimumRequestInterval ?? TimeSpan.FromMilliseconds(_faker.Random.Number(100, 2000))
|
||||
ContactEmail = contactEmail
|
||||
};
|
||||
if (includeUserAgent)
|
||||
settings.UserAgent = userAgent ?? _faker.Internet.UserAgent();
|
||||
if (includeSearchResultLimit)
|
||||
settings.SearchResultLimit = searchResultLimit ?? _faker.Random.Number(1, 50);
|
||||
if (includeWorkEditionLimit)
|
||||
settings.WorkEditionLimit = workEditionLimit ?? _faker.Random.Number(1, 200);
|
||||
if (includeMinimumRequestInterval)
|
||||
settings.MinimumRequestInterval = minimumRequestInterval ?? TimeSpan.FromMilliseconds(_faker.Random.Number(100, 2000));
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
+7
-3
@@ -24,20 +24,24 @@ public class ProblemDetailsDtoFixture
|
||||
/// <param name="status">Optional. The HTTP status code generated by the server.</param>
|
||||
/// <param name="detail">Optional. A detailed explanation specific to this occurrence of the problem.</param>
|
||||
/// <param name="instance">Optional. A URI reference that identifies the specific occurrence of the problem.</param>
|
||||
/// <param name="includeType">Whether the problem type should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <param name="includeDetail">Whether the problem detail should be included, or forced to <see langword="null"/>.</param>
|
||||
/// <returns>The created <see cref="ProblemDetailsDto"/>.</returns>
|
||||
public ProblemDetailsDto Create(
|
||||
string? type = null,
|
||||
string? title = null,
|
||||
int? status = null,
|
||||
string? detail = null,
|
||||
string? instance = null)
|
||||
string? instance = null,
|
||||
bool includeType = true,
|
||||
bool includeDetail = true)
|
||||
{
|
||||
return new ProblemDetailsDto
|
||||
{
|
||||
Type = type ?? "https://tools.ietf.org/html/rfc4918#section-11.2",
|
||||
Type = includeType ? (type ?? "https://tools.ietf.org/html/rfc4918#section-11.2") : null,
|
||||
Title = title ?? _faker.Lorem.Word(),
|
||||
Status = status ?? _faker.Random.Int(400, 599),
|
||||
Detail = detail ?? _faker.Lorem.Sentence(),
|
||||
Detail = includeDetail ? (detail ?? _faker.Lorem.Sentence()) : null,
|
||||
Instance = instance
|
||||
};
|
||||
}
|
||||
|
||||
+3
-8
@@ -1,5 +1,4 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
||||
using System.Collections.Generic;
|
||||
@@ -10,12 +9,12 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="MediaContributorDto"/> test data.
|
||||
/// Fixture class for the <see cref="MediaContributorDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaContributorDto"/> instance with randomized test data.
|
||||
@@ -31,11 +30,7 @@ public class MediaContributorDtoFixture
|
||||
{
|
||||
return new MediaContributorDto
|
||||
{
|
||||
Name = new MediaContributorNameDto
|
||||
{
|
||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
||||
LegalName = legalName ?? _faker.Name.FullName()
|
||||
},
|
||||
Name = _mediaContributorNameDtoFixture.Create(displayName, legalName),
|
||||
Role = role ?? MediaContributorRole.Author
|
||||
};
|
||||
}
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Bogus;
|
||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for the <see cref="MediaContributorNameDto"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorNameDtoFixture
|
||||
{
|
||||
private readonly Faker _faker = new();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="MediaContributorNameDto"/> instance with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="displayName">Optional. The name by which the contributor is popularly known.</param>
|
||||
/// <param name="legalName">Optional. The legal name of the contributor.</param>
|
||||
/// <returns>A configured <see cref="MediaContributorNameDto"/> instance.</returns>
|
||||
public MediaContributorNameDto Create(
|
||||
string? displayName = null,
|
||||
string? legalName = null)
|
||||
{
|
||||
return new MediaContributorNameDto
|
||||
{
|
||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
||||
LegalName = legalName ?? _faker.Name.FullName()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates multiple <see cref="MediaContributorNameDto"/> instances with randomized test data.
|
||||
/// </summary>
|
||||
/// <param name="count">Number of instances to create.</param>
|
||||
/// <returns>List of configured <see cref="MediaContributorNameDto"/> instances.</returns>
|
||||
public List<MediaContributorNameDto> CreateMany(int count = 3)
|
||||
{
|
||||
return [.. Enumerable.Range(0, count).Select(_ => Create())];
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="AddRoleRequest"/> test data.
|
||||
/// Fixture class for the <see cref="AddRoleRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddRoleRequestFixture
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="DeleteRoleRequest"/> test data.
|
||||
/// Fixture class for the <see cref="DeleteRoleRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteRoleRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="UpdateUserRoleAndPermissionsRequest"/> test data.
|
||||
/// Fixture class for the <see cref="UpdateUserRoleAndPermissionsRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserRoleAndPermissionsRequestFixture
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="UpdatePluginSettingsRequest"/> test data.
|
||||
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdatePluginSettingsRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="DeleteThemeRequest"/> test data.
|
||||
/// Fixture class for the <see cref="DeleteThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteThemeRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GetThemeArchiveRequest"/> test data.
|
||||
/// Fixture class for the <see cref="GetThemeArchiveRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeArchiveRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="GetThemeAssetRequest"/> test data.
|
||||
/// Fixture class for the <see cref="GetThemeAssetRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetThemeAssetRequestFixture
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="SetCurrentThemeRequest"/> test data.
|
||||
/// Fixture class for the <see cref="SetCurrentThemeRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetCurrentThemeRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="ChangePasswordRequest"/> test data.
|
||||
/// Fixture class for the <see cref="ChangePasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="LoginRequest"/> test data.
|
||||
/// Fixture class for the <see cref="LoginRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestFixture
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
|
||||
/// <summary>
|
||||
/// Fixture class for generating <see cref="RecoverPasswordRequest"/> test data.
|
||||
/// Fixture class for the <see cref="RecoverPasswordRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestFixture
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web;
|
||||
using Lumina.Presentation.Web.Common.Requests.UsersManagement;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -28,6 +28,8 @@ public record AuthenticatedWebClient(HttpClient Client, string AntiforgeryToken)
|
||||
[ExcludeFromCodeCoverage]
|
||||
public static partial class WebTestHelpers
|
||||
{
|
||||
private static readonly LoginRequestFixture s_loginRequestFixture = new();
|
||||
|
||||
private const string LOGIN_PAGE_PATH = "/en-us/auth/login";
|
||||
private const string LOGIN_ENDPOINT_PATH = "/en-us/auth/api-login";
|
||||
// the change password page renders an antiforgery token for the authenticated user without calling the remote API
|
||||
@@ -81,7 +83,7 @@ public static partial class WebTestHelpers
|
||||
{
|
||||
HttpRequestMessage loginRequest = new(HttpMethod.Post, LOGIN_ENDPOINT_PATH)
|
||||
{
|
||||
Content = JsonContent.Create(new LoginRequest(Username: username, Password: password))
|
||||
Content = JsonContent.Create(s_loginRequestFixture.Create(username: username, password: password))
|
||||
};
|
||||
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted
|
||||
loginRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Presentation.Web.Fixtures.Common.Validation;
|
||||
|
||||
/// <summary>
|
||||
/// Test-support placeholder options type used as the validated options in validation options tests.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ValidationOptionsFixture
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="ValidationOptionsFixture"/> instance.
|
||||
/// </summary>
|
||||
/// <returns>A configured <see cref="ValidationOptionsFixture"/> instance.</returns>
|
||||
public ValidationOptionsFixture Create()
|
||||
{
|
||||
return new ValidationOptionsFixture();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user