mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +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();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -30,6 +30,7 @@ public class LibraryRepositoryTests
|
||||
{
|
||||
private readonly LibraryEntityFixture _libraryEntityFixture = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly LibraryContentLocationEntityFixture _libraryContentLocationEntityFixture = new();
|
||||
|
||||
[Fact]
|
||||
public async Task UpdateAsync_WhenNothingChanged_ShouldNotChangeTheLibraryAudit()
|
||||
@@ -78,7 +79,7 @@ public class LibraryRepositoryTests
|
||||
LibraryEntity incoming = await LoadDetachedLibraryAsync(context, library.Id);
|
||||
incoming.ContentLocations.Clear();
|
||||
foreach (string path in new[] { "/media/one", "/media/keep", "/media/three" })
|
||||
incoming.ContentLocations.Add(new LibraryContentLocationEntity { Path = path });
|
||||
incoming.ContentLocations.Add(_libraryContentLocationEntityFixture.Create(path: path));
|
||||
|
||||
// Act
|
||||
Result<Updated> result = await sut.UpdateAsync(incoming, CancellationToken.None);
|
||||
|
||||
+10
-6
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.DataAccess.Seed;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -32,6 +33,7 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the username of the currently created test user.
|
||||
@@ -74,9 +76,10 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// authenticate user
|
||||
LoginRequest loginRequest = new(
|
||||
Username: user.Username,
|
||||
Password: "TestPass123!"
|
||||
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||
username: user.Username,
|
||||
password: "TestPass123!",
|
||||
includeTotpCode: false
|
||||
);
|
||||
|
||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
||||
@@ -133,9 +136,10 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
||||
await dataSeedService.SetAdminRoleToAdministratorAccount(user.Id, CancellationToken.None);
|
||||
|
||||
// authenticate user
|
||||
LoginRequest loginRequest = new(
|
||||
Username: user.Username,
|
||||
Password: "TestPass123!"
|
||||
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||
username: user.Username,
|
||||
password: "TestPass123!",
|
||||
includeTotpCode: false
|
||||
);
|
||||
|
||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
||||
|
||||
+14
-12
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -33,6 +34,7 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
{
|
||||
private HttpClient _client;
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -65,9 +67,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||
PermissionEntity[] permissions = [.. dbContext.Permissions.Take(2)];
|
||||
|
||||
AddRoleRequest request = new(
|
||||
RoleName: "Editor",
|
||||
Permissions: permissions.Select(p => p.Id).ToList()
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
roleName: "Editor",
|
||||
permissions: permissions.Select(p => p.Id).ToList()
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -95,9 +97,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
{
|
||||
// Arrange
|
||||
_client = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||
AddRoleRequest request = new(
|
||||
RoleName: "Editor",
|
||||
Permissions: [Guid.NewGuid()]
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
roleName: "Editor",
|
||||
permissions: [Guid.NewGuid()]
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -122,9 +124,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
public async Task AddRole_WhenRoleAlreadyExists_ShouldReturnConflict()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new(
|
||||
RoleName: "Admin",
|
||||
Permissions: [Guid.NewGuid()]
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
roleName: "Admin",
|
||||
permissions: [Guid.NewGuid()]
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -150,9 +152,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
||||
{
|
||||
// Arrange
|
||||
using CancellationTokenSource cts = new();
|
||||
AddRoleRequest request = new(
|
||||
RoleName: "Editor",
|
||||
Permissions: [Guid.NewGuid()]
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
roleName: "Editor",
|
||||
permissions: [Guid.NewGuid()]
|
||||
);
|
||||
|
||||
// Act & Assert
|
||||
|
||||
+9
-8
@@ -17,6 +17,7 @@ using Lumina.Contracts.Fixtures.Core.DTO.Common;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
@@ -65,7 +66,9 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
private readonly UpdateTrackRequestFixture _requestTrackFixture = new();
|
||||
private readonly AudioMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
private readonly MusicTrackMetadataDtoFixture _audioMetadataDtoFixture = new();
|
||||
private readonly MusicWorkDtoFixture _musicWorkDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
@@ -127,8 +130,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
includeBpm: false,
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false);
|
||||
includeMusicBrainzTrackId: false);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}", request);
|
||||
@@ -170,8 +172,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
includeBpm: false,
|
||||
includeWork: false,
|
||||
includeMusicBrainzRecordingId: false,
|
||||
includeMusicBrainzTrackId: false,
|
||||
includeMusicBrainzWorkId: false);
|
||||
includeMusicBrainzTrackId: false);
|
||||
(HttpClient adminClient, _) = await CreateAdminClientAsync();
|
||||
|
||||
// Act
|
||||
@@ -817,7 +818,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
public async Task UpdateTrack_WhenWorkExceeds255Characters_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackRequest request = _requestTrackFixture.Create(work: new Faker().Random.String2(256));
|
||||
UpdateTrackRequest request = _requestTrackFixture.Create(work: _musicWorkDtoFixture.Create(title: new Faker().Random.String2(256)));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutTrackAsync(request);
|
||||
@@ -856,7 +857,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
public async Task UpdateTrack_WhenMusicBrainzWorkIdIsEmptyGuid_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateTrackRequest request = _requestTrackFixture.Create(musicBrainzWorkId: Guid.Empty);
|
||||
UpdateTrackRequest request = _requestTrackFixture.Create(work: _musicWorkDtoFixture.Create(musicBrainzWorkId: Guid.Empty));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutTrackAsync(request);
|
||||
@@ -1160,7 +1161,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
||||
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
client.DefaultRequestHeaders.Add("X-Forwarded-For", $"192.{Random.Shared.Next(0, 255)}.{Random.Shared.Next(0, 255)}.{Random.Shared.Next(0, 255)}");
|
||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", new LoginRequest(Username: username, Password: "TestPass123!"));
|
||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", _loginRequestFixture.Create(username: username, password: "TestPass123!"));
|
||||
string content = await loginResponse.Content.ReadAsStringAsync();
|
||||
LoginResponse? loginResult = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResult!.Token);
|
||||
|
||||
+4
-4
@@ -418,7 +418,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
public async Task UpdateBook_WhenOriginalReleaseYearIsLessThan1_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: new ReleaseInfoDto(null, 0, null, null, null, null)));
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: _releaseInfoDtoFixture.Create(originalReleaseYear: 0)));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||
@@ -431,7 +431,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
public async Task UpdateBook_WhenOriginalReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: new ReleaseInfoDto(null, 10000, null, null, null, null)));
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: _releaseInfoDtoFixture.Create(originalReleaseYear: 10000)));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||
@@ -457,7 +457,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
public async Task UpdateBook_WhenReReleaseYearIsLessThan1_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: new ReleaseInfoDto(null, null, null, 0, null, null)));
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: _releaseInfoDtoFixture.Create(reReleaseYear: 0)));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||
@@ -470,7 +470,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
||||
public async Task UpdateBook_WhenReReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
||||
{
|
||||
// Arrange
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: new ReleaseInfoDto(null, null, null, 10000, null, null)));
|
||||
UpdateBookRequest bookRequest = _requestBookFixture.Create(metadata: _writtenContentMetadataDtoFixture.Create(releaseInfo: _releaseInfoDtoFixture.Create(reReleaseYear: 10000)));
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||
|
||||
+7
-5
@@ -3,6 +3,7 @@ using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||
using Lumina.Application.Common.DataAccess.Entities.Themes;
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Infrastructure.Themes;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Contracts.Responses.Themes;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -35,6 +36,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
private HttpClient _client;
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly TestThemeArchiveFixture _themeArchiveFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
private readonly List<string> _installedThemeIds = [];
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
@@ -66,7 +68,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
// Arrange
|
||||
await ThemeTestHelpers.WaitForBundledThemeAsync(_apiFactory);
|
||||
string themeId = await InstallThemeAsync();
|
||||
SetCurrentThemeRequest request = new(ThemeId: themeId);
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: themeId);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -93,7 +95,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
{
|
||||
// Arrange
|
||||
string themeId = "nonexistent-theme";
|
||||
SetCurrentThemeRequest request = new(ThemeId: themeId);
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: themeId);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -117,7 +119,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
public async Task SetCurrentTheme_WhenThemeIdIsEmpty_ShouldReturnValidationProblem()
|
||||
{
|
||||
// Arrange
|
||||
SetCurrentThemeRequest request = new(ThemeId: string.Empty);
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: string.Empty);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -147,7 +149,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
{
|
||||
// Arrange
|
||||
HttpClient nonAdminClient = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||
SetCurrentThemeRequest request = new(ThemeId: "editorial-paper");
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "editorial-paper");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await nonAdminClient.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -172,7 +174,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
{
|
||||
// Arrange
|
||||
HttpClient anonymousClient = _apiFactory.CreateClient();
|
||||
SetCurrentThemeRequest request = new(ThemeId: "editorial-paper");
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "editorial-paper");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await anonymousClient.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
|
||||
+20
-18
@@ -2,6 +2,7 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Common.Infrastructure.Security;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.Contracts.Responses.Authentication;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
@@ -37,6 +38,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||
private readonly PasswordHashService _hashService = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly ICryptographyService _cryptographyService;
|
||||
private readonly TotpTokenGenerator _totpTokenGenerator = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
@@ -81,9 +83,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
Totp totp = new(totpSecret);
|
||||
string validTotpCode = totp.ComputeTotp(DateTime.UtcNow);
|
||||
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: user.Username,
|
||||
TotpCode: validTotpCode
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: user.Username,
|
||||
totpCode: validTotpCode
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -118,9 +120,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
public async Task RecoverPassword_WhenUserDoesNotExist_ShouldReturnNotFound()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: "nonexistentuser",
|
||||
TotpCode: "123456"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: "nonexistentuser",
|
||||
totpCode: "123456"
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -146,9 +148,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
{
|
||||
// Arrange
|
||||
UserEntity user = await CreateUserWithTotp();
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: user.Username,
|
||||
TotpCode: "000000"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: user.Username,
|
||||
totpCode: "000000"
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -210,9 +212,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
// Arrange
|
||||
UserEntity user = await CreateUserWithoutTotp();
|
||||
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: user.Username,
|
||||
TotpCode: "123456"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: user.Username,
|
||||
totpCode: "123456"
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -252,9 +254,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: "userwithoutotp2",
|
||||
TotpCode: null
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: "userwithoutotp2",
|
||||
includeTotpCode: false
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -284,9 +286,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
||||
public async Task RecoverPassword_WhenCancellationRequested_ShouldThrowTaskCanceledException()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: "testuser",
|
||||
TotpCode: "123456"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: "testuser",
|
||||
totpCode: "123456"
|
||||
);
|
||||
using CancellationTokenSource cts = new();
|
||||
|
||||
|
||||
+3
-2
@@ -1,8 +1,8 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
|
||||
using System;
|
||||
@@ -25,6 +25,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
||||
{
|
||||
private readonly LuminaWebFactory _apiFactory;
|
||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
||||
@@ -45,7 +46,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
||||
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
|
||||
HttpRequestMessage setCurrentThemeRequest = new(HttpMethod.Put, "/en-us/admin/themes/api-set-current-theme")
|
||||
{
|
||||
Content = JsonContent.Create(new SetCurrentThemeRequest(THEME_ID))
|
||||
Content = JsonContent.Create(_setCurrentThemeRequestFixture.Create(themeId: THEME_ID))
|
||||
};
|
||||
setCurrentThemeRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
+5
-3
@@ -1,4 +1,5 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||
using Lumina.Contracts.Requests.Themes;
|
||||
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -18,6 +19,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
{
|
||||
private readonly LuminaApiFactory _apiFactory;
|
||||
private readonly HttpClient _client;
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
@@ -39,7 +41,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
public async Task SetCurrentTheme_WhenUnauthorized_ShouldReturnUnauthorizedResult()
|
||||
{
|
||||
// Arrange
|
||||
SetCurrentThemeRequest request = new("some-theme");
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "some-theme");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -64,7 +66,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||
SetCurrentThemeRequest request = new("some-theme");
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "some-theme");
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
@@ -96,7 +98,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
// Arrange
|
||||
HttpClient client = _apiFactory.CreateClient();
|
||||
await _apiFactory.CreateAndAuthenticateAdminUserAsync(client);
|
||||
SetCurrentThemeRequest request = new(maliciousThemeId);
|
||||
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: maliciousThemeId);
|
||||
|
||||
// Act
|
||||
HttpResponseMessage response = await client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||
|
||||
+5
-3
@@ -30,6 +30,7 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
||||
private readonly PasswordHashService _hashService = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
private readonly string _testUsername;
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
@@ -165,9 +166,10 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// Authenticate user.
|
||||
LoginRequest loginRequest = new(
|
||||
Username: user.Username,
|
||||
Password: "TestPass123!"
|
||||
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||
username: user.Username,
|
||||
password: "TestPass123!",
|
||||
includeTotpCode: false
|
||||
);
|
||||
|
||||
HttpResponseMessage loginResponse = await _client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
||||
|
||||
+8
-6
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authentication;
|
||||
using Lumina.Contracts.Requests.Authentication;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Infrastructure.Core.Security;
|
||||
@@ -32,6 +33,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
private readonly HttpClient _client;
|
||||
private readonly PasswordHashService _hashService = new();
|
||||
private readonly UserEntityFixture _userEntityFixture = new();
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
@@ -57,9 +59,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
public async Task RecoverPassword_WhenRateLimitExceeded_ShouldReturnTooManyRequests()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: "testuser",
|
||||
TotpCode: "123456"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: "testuser",
|
||||
totpCode: "123456"
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -97,9 +99,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
||||
client.DefaultRequestHeaders.Clear();
|
||||
client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
|
||||
UserEntity legitimateUser = await CreateTestUser();
|
||||
RecoverPasswordRequest request = new(
|
||||
Username: maliciousUsername,
|
||||
TotpCode: "123456"
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username: maliciousUsername,
|
||||
totpCode: "123456"
|
||||
);
|
||||
|
||||
// Act
|
||||
|
||||
+4
-3
@@ -1,6 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||
using Lumina.Presentation.Web.Fixtures.Common.TestHelpers;
|
||||
using Lumina.Presentation.Web.SecurityTests.Common.Setup;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -18,6 +18,7 @@ namespace Lumina.Presentation.Web.SecurityTests.Core.Endpoints.Admin.Themes.SetC
|
||||
public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
||||
{
|
||||
private readonly LuminaWebFactory _apiFactory;
|
||||
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
||||
@@ -67,11 +68,11 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
||||
/// Builds a PUT request for the set current theme route with the JSON content type required by the antiforgery validation.
|
||||
/// </summary>
|
||||
/// <returns>The configured PUT request.</returns>
|
||||
private static HttpRequestMessage CreateSetCurrentThemeRequest()
|
||||
private HttpRequestMessage CreateSetCurrentThemeRequest()
|
||||
{
|
||||
HttpRequestMessage setCurrentThemeRequest = new(HttpMethod.Put, "/en-us/admin/themes/api-set-current-theme")
|
||||
{
|
||||
Content = JsonContent.Create(new SetCurrentThemeRequest("test-theme"))
|
||||
Content = JsonContent.Create(_setCurrentThemeRequestFixture.Create(themeId: "test-theme"))
|
||||
};
|
||||
setCurrentThemeRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
+12
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ChangePasswordRequestMappingTests
|
||||
{
|
||||
private readonly ChangePasswordRequestFixture _fixture = new();
|
||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = _fixture.Create();
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
@@ -37,7 +37,7 @@ public class ChangePasswordRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(null, null, null, null);
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create(includeUsername: false, includeCurrentPassword: false, includeNewPassword: false, includeNewPasswordConfirm: false);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
@@ -61,7 +61,15 @@ public class ChangePasswordRequestMappingTests
|
||||
string? newPasswordConfirm)
|
||||
{
|
||||
// Arrange
|
||||
ChangePasswordRequest request = new(username, currentPassword, newPassword, newPasswordConfirm);
|
||||
ChangePasswordRequest request = _changePasswordRequestFixture.Create(
|
||||
username,
|
||||
currentPassword,
|
||||
newPassword,
|
||||
newPasswordConfirm,
|
||||
includeUsername: username is not null,
|
||||
includeCurrentPassword: currentPassword is not null,
|
||||
includeNewPassword: newPassword is not null,
|
||||
includeNewPasswordConfirm: newPasswordConfirm is not null);
|
||||
|
||||
// Act
|
||||
ChangePasswordCommand result = request.ToCommand();
|
||||
|
||||
+10
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LoginRequestMappingTests
|
||||
{
|
||||
private readonly LoginRequestFixture _fixture = new();
|
||||
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = _fixture.Create();
|
||||
LoginRequest request = _loginRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
@@ -36,7 +36,7 @@ public class LoginRequestMappingTests
|
||||
public void ToQuery_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(null, null);
|
||||
LoginRequest request = _loginRequestFixture.Create(includeUsername: false, includePassword: false, includeTotpCode: false);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
@@ -59,7 +59,13 @@ public class LoginRequestMappingTests
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
LoginRequest request = new(username, password, totpCode);
|
||||
LoginRequest request = _loginRequestFixture.Create(
|
||||
username,
|
||||
password,
|
||||
totpCode,
|
||||
includeUsername: username is not null,
|
||||
includePassword: password is not null,
|
||||
includeTotpCode: totpCode is not null);
|
||||
|
||||
// Act
|
||||
LoginUserQuery result = request.ToQuery();
|
||||
|
||||
+8
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RecoverPasswordRequestMappingTests
|
||||
{
|
||||
private readonly RecoverPasswordRequestFixture _fixture = new();
|
||||
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = _fixture.Create();
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
@@ -35,7 +35,7 @@ public class RecoverPasswordRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(null, null);
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(includeUsername: false, includeTotpCode: false);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
@@ -56,7 +56,11 @@ public class RecoverPasswordRequestMappingTests
|
||||
string? totpCode)
|
||||
{
|
||||
// Arrange
|
||||
RecoverPasswordRequest request = new(username, totpCode);
|
||||
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||
username,
|
||||
totpCode,
|
||||
includeUsername: username is not null,
|
||||
includeTotpCode: totpCode is not null);
|
||||
|
||||
// Act
|
||||
RecoverPasswordCommand result = request.ToCommand();
|
||||
|
||||
+21
-7
@@ -15,13 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RegistrationRequestMappingTests
|
||||
{
|
||||
private readonly RegistrationRequestFixture _fixture = new();
|
||||
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToSetupCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.Create();
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
@@ -38,7 +38,7 @@ public class RegistrationRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = _fixture.Create();
|
||||
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
@@ -55,7 +55,7 @@ public class RegistrationRequestMappingTests
|
||||
public void ToSetupCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
RegistrationRequest request = _registrationRequestFixture.Create(includeUsername: false, includePassword: false, includePasswordConfirm: false, use2fa: true);
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
@@ -72,7 +72,7 @@ public class RegistrationRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new();
|
||||
RegistrationRequest request = _registrationRequestFixture.Create(includeUsername: false, includePassword: false, includePasswordConfirm: false, use2fa: true);
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
@@ -97,7 +97,14 @@ public class RegistrationRequestMappingTests
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
RegistrationRequest request = _registrationRequestFixture.Create(
|
||||
username,
|
||||
password,
|
||||
passwordConfirm,
|
||||
use2fa,
|
||||
includeUsername: username is not null,
|
||||
includePassword: password is not null,
|
||||
includePasswordConfirm: passwordConfirm is not null);
|
||||
|
||||
// Act
|
||||
SetupApplicationCommand result = request.ToSetupCommand();
|
||||
@@ -122,7 +129,14 @@ public class RegistrationRequestMappingTests
|
||||
bool use2fa)
|
||||
{
|
||||
// Arrange
|
||||
RegistrationRequest request = new(username, password, passwordConfirm, use2fa);
|
||||
RegistrationRequest request = _registrationRequestFixture.Create(
|
||||
username,
|
||||
password,
|
||||
passwordConfirm,
|
||||
use2fa,
|
||||
includeUsername: username is not null,
|
||||
includePassword: password is not null,
|
||||
includePasswordConfirm: passwordConfirm is not null);
|
||||
|
||||
// Act
|
||||
RegisterUserCommand result = request.ToCommand();
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddRoleRequestMappingTests
|
||||
{
|
||||
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new(
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
"Admin",
|
||||
[Guid.NewGuid(), Guid.NewGuid()]
|
||||
);
|
||||
@@ -37,7 +40,7 @@ public class AddRoleRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithEmptyPermissions_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new(
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
"Guest",
|
||||
[]
|
||||
);
|
||||
@@ -58,7 +61,7 @@ public class AddRoleRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
||||
{
|
||||
// Arrange
|
||||
AddRoleRequest request = new(
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||
roleName,
|
||||
[Guid.NewGuid()]
|
||||
);
|
||||
@@ -82,7 +85,7 @@ public class AddRoleRequestMappingTests
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||
];
|
||||
AddRoleRequest request = new("SuperAdmin", permissions);
|
||||
AddRoleRequest request = _addRoleRequestFixture.Create("SuperAdmin", permissions);
|
||||
|
||||
// Act
|
||||
AddRoleCommand result = request.ToCommand();
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteRoleRequestMappingTests
|
||||
{
|
||||
private readonly DeleteRoleRequestFixture _deleteRoleRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
DeleteRoleRequest request = new(roleId);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId);
|
||||
|
||||
// Act
|
||||
DeleteRoleCommand result = request.ToCommand();
|
||||
@@ -37,7 +40,7 @@ public class DeleteRoleRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.Parse(roleIdString);
|
||||
DeleteRoleRequest request = new(roleId);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId);
|
||||
|
||||
// Act
|
||||
DeleteRoleCommand result = request.ToCommand();
|
||||
@@ -51,7 +54,7 @@ public class DeleteRoleRequestMappingTests
|
||||
public void ToCommand_WhenRoleIdIsNull_ShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(null);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(includeRoleId: false);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidOperationException>(() => request.ToCommand());
|
||||
@@ -61,7 +64,7 @@ public class DeleteRoleRequestMappingTests
|
||||
public void ToCommand_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DeleteRoleRequest request = new(Guid.Empty);
|
||||
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(Guid.Empty);
|
||||
|
||||
// Act
|
||||
DeleteRoleCommand result = request.ToCommand();
|
||||
|
||||
+6
-3
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetAuthorizationRequestMappingTests
|
||||
{
|
||||
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetAuthorizationRequest request = new(userId);
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
@@ -33,7 +36,7 @@ public class GetAuthorizationRequestMappingTests
|
||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetAuthorizationRequest request = new(null);
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(includeUserId: false);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
@@ -51,7 +54,7 @@ public class GetAuthorizationRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.Parse(userIdString);
|
||||
GetAuthorizationRequest request = new(userId);
|
||||
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetAuthorizationQuery result = request.ToQuery();
|
||||
|
||||
+6
-3
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetRolePermissionsRequestMappingTests
|
||||
{
|
||||
private readonly GetRolePermissionsRequestFixture _getRolePermissionsRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.NewGuid();
|
||||
GetRolePermissionsRequest request = new(roleId);
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId);
|
||||
|
||||
// Act
|
||||
GetRolePermissionsQuery result = request.ToQuery();
|
||||
@@ -37,7 +40,7 @@ public class GetRolePermissionsRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid roleId = Guid.Parse(roleIdString);
|
||||
GetRolePermissionsRequest request = new(roleId);
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId);
|
||||
|
||||
// Act
|
||||
GetRolePermissionsQuery result = request.ToQuery();
|
||||
@@ -51,7 +54,7 @@ public class GetRolePermissionsRequestMappingTests
|
||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetRolePermissionsRequest request = new(Guid.Empty);
|
||||
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(Guid.Empty);
|
||||
|
||||
// Act
|
||||
GetRolePermissionsQuery result = request.ToQuery();
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserPermissionsRequestMappingTests
|
||||
{
|
||||
private readonly GetUserPermissionsRequestFixture _getUserPermissionsRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetUserPermissionsQuery result = request.ToQuery();
|
||||
@@ -33,7 +36,7 @@ public class GetUserPermissionsRequestMappingTests
|
||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(null);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(includeUserId: false);
|
||||
|
||||
// Act
|
||||
GetUserPermissionsQuery result = request.ToQuery();
|
||||
@@ -51,7 +54,7 @@ public class GetUserPermissionsRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.Parse(userIdString);
|
||||
GetUserPermissionsRequest request = new(userId);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetUserPermissionsQuery result = request.ToQuery();
|
||||
@@ -65,7 +68,7 @@ public class GetUserPermissionsRequestMappingTests
|
||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetUserPermissionsRequest request = new(Guid.Empty);
|
||||
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(Guid.Empty);
|
||||
|
||||
// Act
|
||||
GetUserPermissionsQuery result = request.ToQuery();
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetUserRoleRequestMappingTests
|
||||
{
|
||||
private readonly GetUserRoleRequestFixture _getUserRoleRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
GetUserRoleRequest request = new(userId);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetUserRoleQuery result = request.ToQuery();
|
||||
@@ -33,7 +36,7 @@ public class GetUserRoleRequestMappingTests
|
||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(null);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(includeUserId: false);
|
||||
|
||||
// Act
|
||||
GetUserRoleQuery result = request.ToQuery();
|
||||
@@ -51,7 +54,7 @@ public class GetUserRoleRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.Parse(userIdString);
|
||||
GetUserRoleRequest request = new(userId);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId);
|
||||
|
||||
// Act
|
||||
GetUserRoleQuery result = request.ToQuery();
|
||||
@@ -65,7 +68,7 @@ public class GetUserRoleRequestMappingTests
|
||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetUserRoleRequest request = new(Guid.Empty);
|
||||
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(Guid.Empty);
|
||||
|
||||
// Act
|
||||
GetUserRoleQuery result = request.ToQuery();
|
||||
|
||||
+7
-4
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,12 +16,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateRoleRequestMappingTests
|
||||
{
|
||||
private readonly UpdateRoleRequestFixture _updateRoleRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Guid> permissions = [Guid.NewGuid(), Guid.NewGuid()];
|
||||
UpdateRoleRequest request = new(
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||
Guid.NewGuid(),
|
||||
"Admin",
|
||||
permissions
|
||||
@@ -43,7 +46,7 @@ public class UpdateRoleRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||
Guid.NewGuid(),
|
||||
roleName,
|
||||
[Guid.NewGuid()]
|
||||
@@ -64,7 +67,7 @@ public class UpdateRoleRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentRoleIds_ShouldMapCorrectly(string roleIdString)
|
||||
{
|
||||
// Arrange
|
||||
UpdateRoleRequest request = new(
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||
Guid.Parse(roleIdString),
|
||||
"Admin",
|
||||
[Guid.NewGuid()]
|
||||
@@ -88,7 +91,7 @@ public class UpdateRoleRequestMappingTests
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||
];
|
||||
UpdateRoleRequest request = new(Guid.NewGuid(), "Admin", permissions);
|
||||
UpdateRoleRequest request = _updateRoleRequestFixture.Create(Guid.NewGuid(), "Admin", permissions);
|
||||
|
||||
// Act
|
||||
UpdateRoleCommand result = request.ToCommand();
|
||||
|
||||
+10
-6
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Authorization;
|
||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||
using Lumina.Contracts.Requests.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,12 +16,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateUserRoleAndPermissionsRequestMappingTests
|
||||
{
|
||||
private readonly UpdateUserRoleAndPermissionsRequestFixture _updateUserRoleAndPermissionsRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<Guid> permissions = [Guid.NewGuid()];
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
permissions
|
||||
@@ -41,10 +44,11 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
||||
{
|
||||
// Arrange
|
||||
List<Guid> permissions = [Guid.NewGuid()];
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||
Guid.NewGuid(),
|
||||
null,
|
||||
permissions
|
||||
roleId: null,
|
||||
permissions: permissions,
|
||||
includeRoleId: false
|
||||
);
|
||||
|
||||
// Act
|
||||
@@ -64,7 +68,7 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
||||
{
|
||||
// Arrange
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||
Guid.Parse(userIdString),
|
||||
Guid.NewGuid(),
|
||||
[Guid.NewGuid()]
|
||||
@@ -88,7 +92,7 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||
];
|
||||
UpdateUserRoleAndPermissionsRequest request = new(
|
||||
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||
Guid.NewGuid(),
|
||||
Guid.NewGuid(),
|
||||
permissions
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class CheckPathExistsRequestMappingTests
|
||||
public void ToQuery_WhenMappingWithDifferentPathsAndHiddenElementsFlag_ShouldMapCorrectly(string path, bool shouldIncludeHiddenElements)
|
||||
{
|
||||
// Arrange
|
||||
CheckPathExistsRequest request = new(path, shouldIncludeHiddenElements);
|
||||
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path, shouldIncludeHiddenElements);
|
||||
|
||||
// Act
|
||||
CheckPathExistsQuery result = request.ToQuery();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class CombinePathRequestMappingTests
|
||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string originalPath, string newPath)
|
||||
{
|
||||
// Arrange
|
||||
CombinePathRequest request = new(originalPath, newPath);
|
||||
CombinePathRequest request = _combinePathRequestFixture.Create(originalPath, newPath);
|
||||
|
||||
// Act
|
||||
CombinePathCommand result = request.ToCommand();
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class GetPathParentRequestMappingTests
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
GetPathParentRequest request = new(path);
|
||||
GetPathParentRequest request = _getPathParentRequestFixture.Create(path);
|
||||
|
||||
// Act
|
||||
GetPathParentQuery result = request.ToQuery();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class GetPathRootRequestMappingTests
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
GetPathRootRequest request = new(path);
|
||||
GetPathRootRequest request = _getPathRootRequestFixture.Create(path);
|
||||
|
||||
// Act
|
||||
GetPathRootQuery result = request.ToQuery();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class SplitPathRequestMappingTests
|
||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
SplitPathRequest request = new(path);
|
||||
SplitPathRequest request = _splitPathRequestFixture.Create(path);
|
||||
|
||||
// Act
|
||||
SplitPathCommand result = request.ToCommand();
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class ValidatePathRequestMappingTests
|
||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||
{
|
||||
// Arrange
|
||||
ValidatePathRequest request = new(path);
|
||||
ValidatePathRequest request = _validatePathRequestFixture.Create(path);
|
||||
|
||||
// Act
|
||||
ValidatePathQuery result = request.ToQuery();
|
||||
|
||||
+1
-1
@@ -40,7 +40,7 @@ public class GetThumbnailRequestMappingTests
|
||||
public void ToQuery_WhenMappingWithDifferentPathsAndQualities_ShouldMapCorrectly(string path, int quality)
|
||||
{
|
||||
// Arrange
|
||||
GetThumbnailRequest request = new(path, quality);
|
||||
GetThumbnailRequest request = _getThumbnailRequestFixture.Create(path, quality);
|
||||
|
||||
// Act
|
||||
GetThumbnailQuery result = request.ToQuery();
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ public class ThumbnailMappingTests
|
||||
{
|
||||
// Arrange
|
||||
byte[] bytes = [.. _fixture.CreateMany<byte>(100)];
|
||||
Thumbnail domainModel = new(imageType, bytes);
|
||||
Thumbnail domainModel = _thumbnailFixture.Create(imageType, bytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
@@ -70,7 +70,7 @@ public class ThumbnailMappingTests
|
||||
// Arrange
|
||||
ImageType imageType = _fixture.Create<ImageType>();
|
||||
byte[] emptyBytes = [];
|
||||
Thumbnail domainModel = new(imageType, emptyBytes);
|
||||
Thumbnail domainModel = _thumbnailFixture.Create(imageType, emptyBytes);
|
||||
|
||||
// Act
|
||||
ThumbnailResponse result = domainModel.ToResponse();
|
||||
|
||||
+15
-10
@@ -6,6 +6,8 @@ using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -29,6 +31,9 @@ public class AlbumEntityMappingTests
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
||||
private readonly TrackIsrcEntityFixture _trackIsrcEntityFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidAlbumEntity_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -64,13 +69,13 @@ public class AlbumEntityMappingTests
|
||||
Assert.Equal(entity.OriginalLanguageCode!.ToLowerInvariant(), album.Metadata.OriginalLanguage.Value.LanguageCode);
|
||||
Assert.Equal(entity.OriginalLanguageName, album.Metadata.OriginalLanguage.Value.LanguageName);
|
||||
Assert.Equal(entity.OriginalLanguageNativeName, album.Metadata.OriginalLanguage.Value.NativeName.Value);
|
||||
Assert.Equal(entity.ReleaseType, album.Metadata.ReleaseType.Value);
|
||||
Assert.Equal(entity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType), album.Metadata.ReleaseTypes);
|
||||
Assert.Equal(entity.ReleaseStatus, album.Metadata.ReleaseStatus.Value);
|
||||
Assert.Equal(entity.TotalDiscs, album.Metadata.TotalDiscs.Value);
|
||||
Assert.Equal(entity.TotalTracks, album.Metadata.TotalTracks);
|
||||
Assert.Equal(entity.MediaFormat, album.MediaFormat.Value);
|
||||
Assert.Equal(entity.Barcode, album.Barcode.Value.Value);
|
||||
Assert.Equal(entity.CatalogNumber, album.CatalogNumber.Value);
|
||||
Assert.Equal(entity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber), album.CatalogNumbers);
|
||||
Assert.Equal(entity.MusicBrainzReleaseId, album.MusicBrainzReleaseId.Value.Value);
|
||||
Assert.Equal(entity.MusicBrainzReleaseGroupId, album.MusicBrainzReleaseGroupId.Value.Value);
|
||||
Assert.Equal(entity.MusicBrainzReleaseArtistId, album.MusicBrainzReleaseArtistId.Value.Value);
|
||||
@@ -102,7 +107,7 @@ public class AlbumEntityMappingTests
|
||||
includeReleaseStatus: false,
|
||||
includeTotalDiscs: false,
|
||||
includeMediaFormat: false,
|
||||
includeCatalogNumber: false,
|
||||
includeCatalogNumbers: false,
|
||||
includeMusicBrainzReleaseId: false,
|
||||
includeMusicBrainzReleaseGroupId: false,
|
||||
includeMusicBrainzReleaseArtistId: false);
|
||||
@@ -123,12 +128,12 @@ public class AlbumEntityMappingTests
|
||||
Assert.Empty(album.Metadata.Tags);
|
||||
Assert.False(album.Metadata.Language.HasValue);
|
||||
Assert.False(album.Metadata.OriginalLanguage.HasValue);
|
||||
Assert.False(album.Metadata.ReleaseType.HasValue);
|
||||
Assert.Empty(album.Metadata.ReleaseTypes);
|
||||
Assert.False(album.Metadata.ReleaseStatus.HasValue);
|
||||
Assert.False(album.Metadata.TotalDiscs.HasValue);
|
||||
Assert.False(album.MediaFormat.HasValue);
|
||||
Assert.False(album.Barcode.HasValue);
|
||||
Assert.False(album.CatalogNumber.HasValue);
|
||||
Assert.Empty(album.CatalogNumbers);
|
||||
Assert.False(album.MusicBrainzReleaseId.HasValue);
|
||||
Assert.False(album.MusicBrainzReleaseGroupId.HasValue);
|
||||
Assert.False(album.MusicBrainzReleaseArtistId.HasValue);
|
||||
@@ -231,7 +236,7 @@ public class AlbumEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
TrackEntity trackEntity = _trackEntityFixture.Create();
|
||||
trackEntity.Isrcs = [new TrackIsrcEntity("not-an-isrc")];
|
||||
trackEntity.Isrcs = [_trackIsrcEntityFixture.Create(value: "not-an-isrc")];
|
||||
AlbumEntity entity = _albumEntityFixture.Create(tracks: [trackEntity]);
|
||||
|
||||
// Act
|
||||
@@ -275,20 +280,20 @@ public class AlbumEntityMappingTests
|
||||
Assert.Equal(entity.OriginalLanguageNativeName, result.Metadata.OriginalLanguage.NativeName);
|
||||
Assert.Equal(entity.Tags.Select(tag => tag.Name).OrderBy(name => name), result.Metadata.Tags!.Select(tag => tag.Name).OrderBy(name => name));
|
||||
Assert.Equal(entity.Genres.Select(genre => genre.Name).OrderBy(name => name), result.Metadata.Genres!.Select(genre => genre.Name).OrderBy(name => name));
|
||||
Assert.Equal(entity.ReleaseType, result.Metadata.ReleaseType);
|
||||
Assert.Equal(entity.ReleaseTypes.Select(releaseType => releaseType.ReleaseType), result.Metadata.ReleaseTypes);
|
||||
Assert.Equal(entity.ReleaseStatus, result.Metadata.ReleaseStatus);
|
||||
Assert.Equal(entity.TotalDiscs, result.Metadata.TotalDiscs);
|
||||
Assert.Equal(entity.TotalTracks, result.Metadata.TotalTracks);
|
||||
Assert.Equal(entity.MediaFormat, result.MediaFormat);
|
||||
Assert.Equal(entity.Barcode, result.Barcode);
|
||||
Assert.Equal(entity.CatalogNumber, result.CatalogNumber);
|
||||
Assert.Equal(entity.CatalogNumbers.Select(catalogNumber => catalogNumber.CatalogNumber), result.CatalogNumbers);
|
||||
Assert.Equal(entity.MusicBrainzReleaseId, result.MusicBrainzReleaseId);
|
||||
Assert.Equal(entity.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
||||
Assert.Equal(entity.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
||||
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
|
||||
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||
Assert.Equal(entity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Ratings.Select(rating => new AudioRatingDto(rating.Value, rating.MaxValue, rating.Source, rating.VoteCount)), result.Ratings);
|
||||
Assert.Equal(entity.Contributors.Select(contributor => _mediaContributorReferenceDtoFixture.Create(contributorId: contributor.MediaContributorId, role: contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Ratings.Select(rating => _audioRatingDtoFixture.Create(value: rating.Value, maxValue: rating.MaxValue, source: rating.Source, voteCount: rating.VoteCount)), result.Ratings);
|
||||
Assert.Equal(entity.Tracks.Select(track => track.Id), result.Tracks!.Select(track => track.Id));
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -5,6 +5,7 @@ using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.A
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
@@ -27,6 +28,7 @@ public class ArtistEntityMappingTests
|
||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||
private readonly PaginatedResultDtoFixture<ArtistEntity> _paginatedResultDtoFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidArtistEntity_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -111,10 +113,10 @@ public class ArtistEntityMappingTests
|
||||
Assert.NotNull(result);
|
||||
Assert.Equal(entity.Id, result.Id);
|
||||
Assert.Equal(entity.LibraryId, result.LibraryId);
|
||||
Assert.Equal(entity.Name, result.Name);
|
||||
Assert.Equal(entity.Name, result.Metadata.Name);
|
||||
Assert.Equal(entity.Website, result.Website);
|
||||
Assert.Equal(entity.MusicBrainzArtistId, result.MusicBrainzArtistId);
|
||||
Assert.Equal(entity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Contributors.Select(contributor => _mediaContributorReferenceDtoFixture.Create(contributorId: contributor.MediaContributorId, role: contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Albums.Count, result.Albums!.Count);
|
||||
Assert.Equal(entity.Albums.Select(album => album.Id), result.Albums.Select(album => album.Id));
|
||||
Assert.Equal(entity.Albums.Select(album => album.Title), result.Albums.Select(album => album.Metadata.Title));
|
||||
@@ -157,7 +159,7 @@ public class ArtistEntityMappingTests
|
||||
for (int i = 0; i < entities.Count; i++)
|
||||
{
|
||||
Assert.Equal(entities[i].Id, results[i].Id);
|
||||
Assert.Equal(entities[i].Name, results[i].Name);
|
||||
Assert.Equal(entities[i].Name, results[i].Metadata.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-10
@@ -2,10 +2,13 @@
|
||||
using Lumina.Application.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Common;
|
||||
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.DTO.MediaContributors;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
@@ -26,6 +29,12 @@ public class TrackEntityMappingTests
|
||||
{
|
||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||
private readonly TrackMoodEntityFixture _trackMoodEntityFixture = new();
|
||||
private readonly TrackIsrcEntityFixture _trackIsrcEntityFixture = new();
|
||||
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToDomainEntity_WhenMappingValidTrackEntity_ShouldMapAllPropertiesCorrectly()
|
||||
@@ -73,10 +82,10 @@ public class TrackEntityMappingTests
|
||||
Assert.Equal(entity.Script, track.Script.Value);
|
||||
Assert.Equal(entity.Key, track.Key.Value);
|
||||
Assert.Equal(entity.Bpm, track.Bpm.Value);
|
||||
Assert.Equal(entity.Work, track.Work.Value);
|
||||
Assert.Equal(entity.WorkTitle, track.Work.Value.Title);
|
||||
Assert.Equal(entity.MusicBrainzRecordingId, track.MusicBrainzRecordingId.Value.Value);
|
||||
Assert.Equal(entity.MusicBrainzTrackId, track.MusicBrainzTrackId.Value.Value);
|
||||
Assert.Equal(entity.MusicBrainzWorkId, track.MusicBrainzWorkId.Value.Value);
|
||||
Assert.Equal(entity.MusicBrainzWorkId, track.Work.Value.MusicBrainzWorkId.Value);
|
||||
Assert.Equal(entity.Moods.Select(mood => mood.Name), track.Moods.Select(mood => mood.Name));
|
||||
Assert.Equal(entity.Isrcs.Select(isrc => isrc.Value), track.Isrcs.Select(isrc => isrc.Value));
|
||||
Assert.Equal(entity.Ratings.Select(rating => rating.Value), track.Ratings.Select(rating => (decimal?)rating.Value));
|
||||
@@ -107,7 +116,7 @@ public class TrackEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
TrackEntity entity = _trackEntityFixture.Create();
|
||||
entity.Genres = [new GenreEntity(string.Empty)];
|
||||
entity.Genres = [_genreEntityFixture.Create(name: string.Empty)];
|
||||
|
||||
// Act
|
||||
Result<Track> result = entity.ToDomainEntity();
|
||||
@@ -122,7 +131,7 @@ public class TrackEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
TrackEntity entity = _trackEntityFixture.Create();
|
||||
entity.Tags = [new TagEntity(" ")];
|
||||
entity.Tags = [_tagEntityFixture.Create(name: " ")];
|
||||
|
||||
// Act
|
||||
Result<Track> result = entity.ToDomainEntity();
|
||||
@@ -137,7 +146,7 @@ public class TrackEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
TrackEntity entity = _trackEntityFixture.Create();
|
||||
entity.Moods = [new TrackMoodEntity(string.Empty)];
|
||||
entity.Moods = [_trackMoodEntityFixture.Create(name: string.Empty)];
|
||||
|
||||
// Act
|
||||
Result<Track> result = entity.ToDomainEntity();
|
||||
@@ -152,7 +161,7 @@ public class TrackEntityMappingTests
|
||||
{
|
||||
// Arrange
|
||||
TrackEntity entity = _trackEntityFixture.Create();
|
||||
entity.Isrcs = [new TrackIsrcEntity("not-an-isrc")];
|
||||
entity.Isrcs = [_trackIsrcEntityFixture.Create(value: "not-an-isrc")];
|
||||
|
||||
// Act
|
||||
Result<Track> result = entity.ToDomainEntity();
|
||||
@@ -222,16 +231,16 @@ public class TrackEntityMappingTests
|
||||
Assert.Equal(entity.Script, result.Script);
|
||||
Assert.Equal(entity.Key, result.Key);
|
||||
Assert.Equal(entity.Bpm, result.Bpm);
|
||||
Assert.Equal(entity.Work, result.Work);
|
||||
Assert.Equal(entity.WorkTitle, result.Work!.Title);
|
||||
Assert.Equal(entity.MusicBrainzRecordingId, result.MusicBrainzRecordingId);
|
||||
Assert.Equal(entity.MusicBrainzTrackId, result.MusicBrainzTrackId);
|
||||
Assert.Equal(entity.MusicBrainzWorkId, result.MusicBrainzWorkId);
|
||||
Assert.Equal(entity.MusicBrainzWorkId, result.Work!.MusicBrainzWorkId);
|
||||
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
|
||||
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||
Assert.Equal(entity.Moods.Select(mood => mood.Name), result.Moods!.Select(mood => mood.Name));
|
||||
Assert.Equal(entity.Isrcs.Select(isrc => isrc.Value), result.Isrcs!.Select(isrc => isrc.Value));
|
||||
Assert.Equal(entity.Contributors.Select(contributor => new MediaContributorReferenceDto(contributor.MediaContributorId, contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Ratings.Select(rating => new AudioRatingDto(rating.Value, rating.MaxValue, rating.Source, rating.VoteCount)), result.Ratings);
|
||||
Assert.Equal(entity.Contributors.Select(contributor => _mediaContributorReferenceDtoFixture.Create(contributorId: contributor.MediaContributorId, role: contributor.Role)), result.Contributors);
|
||||
Assert.Equal(entity.Ratings.Select(rating => _audioRatingDtoFixture.Create(value: rating.Value, maxValue: rating.MaxValue, source: rating.Source, voteCount: rating.VoteCount)), result.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
+8
-5
@@ -25,6 +25,9 @@ public class BookMetadataDtoMappingTests
|
||||
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
|
||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItToTheBook()
|
||||
@@ -126,7 +129,7 @@ public class BookMetadataDtoMappingTests
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
tags: [new TagDto(" ")]);
|
||||
tags: [_tagDtoFixture.Create(name: " ")]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
@@ -142,7 +145,7 @@ public class BookMetadataDtoMappingTests
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [new IsbnDto("not-an-isbn", IsbnFormat.Isbn13)]);
|
||||
isbns: [_isbnDtoFixture.Create(value: "not-an-isbn", format: IsbnFormat.Isbn13)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
@@ -158,7 +161,7 @@ public class BookMetadataDtoMappingTests
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
ratings: [new BookRatingDto(-1m, 5m, null, null)]);
|
||||
ratings: [_bookRatingDtoFixture.Create(value: -1m, maxValue: 5m, includeSource: false, includeVoteCount: false)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
@@ -196,8 +199,8 @@ public class BookMetadataDtoMappingTests
|
||||
Book book = _bookFixture.Create();
|
||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||
title: "A valid title",
|
||||
isbns: [new IsbnDto("9780306406157", IsbnFormat.Isbn13)],
|
||||
ratings: [new BookRatingDto(4m, 5m, null, 10)]);
|
||||
isbns: [_isbnDtoFixture.Create(value: "9780306406157", format: IsbnFormat.Isbn13)],
|
||||
ratings: [_bookRatingDtoFixture.Create(value: 4m, maxValue: 5m, voteCount: 10, includeSource: false)]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = book.ApplyMetadata(metadata);
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryMetadataProvidersRequestMappingTests
|
||||
{
|
||||
private readonly GetLibraryMetadataProvidersRequestFixture _getLibraryMetadataProvidersRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetLibraryMetadataProvidersRequest request = new(LibraryId: Guid.NewGuid());
|
||||
GetLibraryMetadataProvidersRequest request = _getLibraryMetadataProvidersRequestFixture.Create(Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
GetLibraryMetadataProvidersQuery result = request.ToQuery();
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetPluginSettingsRequestMappingTests
|
||||
{
|
||||
private readonly GetPluginSettingsRequestFixture _getPluginSettingsRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
GetPluginSettingsRequest request = new(PluginId: Guid.NewGuid());
|
||||
GetPluginSettingsRequest request = _getPluginSettingsRequestFixture.Create(Guid.NewGuid());
|
||||
|
||||
// Act
|
||||
GetPluginSettingsQuery result = request.ToQuery();
|
||||
|
||||
+6
-3
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||
using Lumina.Plugins.Contracts.Fixtures.Common.Models.DTO.Settings;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginSettingDescriptorMappingTests
|
||||
{
|
||||
private readonly PluginSettingDescriptorDtoFixture _pluginSettingDescriptorDtoFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingValidDescriptor_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorDto descriptor = new("apiKey", "API Key", PluginSettingType.Text, "default", null);
|
||||
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("apiKey", "API Key", PluginSettingType.Text, "default", null);
|
||||
|
||||
// Act
|
||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||
@@ -41,7 +44,7 @@ public class PluginSettingDescriptorMappingTests
|
||||
public void ToResponse_WhenMappingDifferentSettingTypes_ShouldMapTypeCorrectly(PluginSettingType type)
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorDto descriptor = new("key", "Label", type, null, null);
|
||||
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("key", "Label", type, null, null);
|
||||
|
||||
// Act
|
||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||
@@ -54,7 +57,7 @@ public class PluginSettingDescriptorMappingTests
|
||||
public void ToResponse_WhenMappingDescriptorWithAllowedValues_ShouldMapAllowedValues()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorDto descriptor = new("mode", "Mode", PluginSettingType.Select, null, ["fast", "slow"]);
|
||||
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("mode", "Mode", PluginSettingType.Select, null, ["fast", "slow"]);
|
||||
|
||||
// Act
|
||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReorderLibraryMetadataProvidersRequestMappingTests
|
||||
{
|
||||
private readonly ReorderLibraryMetadataProvidersRequestFixture _reorderLibraryMetadataProvidersRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
ReorderLibraryMetadataProvidersRequest request = new(LibraryId: Guid.NewGuid(), PluginIds: [Guid.NewGuid(), Guid.NewGuid()]);
|
||||
ReorderLibraryMetadataProvidersRequest request = _reorderLibraryMetadataProvidersRequestFixture.Create(Guid.NewGuid(), [Guid.NewGuid(), Guid.NewGuid()]);
|
||||
|
||||
// Act
|
||||
ReorderLibraryMetadataProvidersCommand result = request.ToCommand();
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SetLibraryMetadataProviderEnabledRequestMappingTests
|
||||
{
|
||||
private readonly SetLibraryMetadataProviderEnabledRequestFixture _setLibraryMetadataProviderEnabledRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
SetLibraryMetadataProviderEnabledRequest request = new(LibraryId: Guid.NewGuid(), PluginId: Guid.NewGuid(), IsEnabled: true);
|
||||
SetLibraryMetadataProviderEnabledRequest request = _setLibraryMetadataProviderEnabledRequestFixture.Create(Guid.NewGuid(), Guid.NewGuid(), true);
|
||||
|
||||
// Act
|
||||
SetLibraryMetadataProviderEnabledCommand result = request.ToCommand();
|
||||
|
||||
+5
-2
@@ -1,6 +1,7 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Mapping.Plugins;
|
||||
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||
using Lumina.Contracts.Requests.Plugins;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdatePluginSettingsRequestMappingTests
|
||||
{
|
||||
private readonly UpdatePluginSettingsRequestFixture _updatePluginSettingsRequestFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
UpdatePluginSettingsRequest request = new(PluginId: Guid.NewGuid(), Settings: new Dictionary<string, string> { ["key"] = "value" });
|
||||
UpdatePluginSettingsRequest request = _updatePluginSettingsRequestFixture.Create(Guid.NewGuid(), new Dictionary<string, string> { ["key"] = "value" });
|
||||
|
||||
// Act
|
||||
UpdatePluginSettingsCommand result = request.ToCommand();
|
||||
@@ -34,7 +37,7 @@ public class UpdatePluginSettingsRequestMappingTests
|
||||
public void ToCommand_WhenMappingRequestWithNullSettings_ShouldMapNullSettings()
|
||||
{
|
||||
// Arrange
|
||||
UpdatePluginSettingsRequest request = new(PluginId: Guid.NewGuid(), Settings: null);
|
||||
UpdatePluginSettingsRequest request = _updatePluginSettingsRequestFixture.Create(Guid.NewGuid(), includeSettings: false);
|
||||
|
||||
// Act
|
||||
UpdatePluginSettingsCommand result = request.ToCommand();
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ public class DeleteThemeRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
||||
{
|
||||
// Arrange
|
||||
DeleteThemeRequest request = new(themeId);
|
||||
DeleteThemeRequest request = _deleteThemeRequestFixture.Create(themeId);
|
||||
|
||||
// Act
|
||||
DeleteThemeCommand result = request.ToCommand();
|
||||
@@ -53,7 +53,7 @@ public class DeleteThemeRequestMappingTests
|
||||
public void ToCommand_WhenThemeIdIsNull_ShouldMapNull()
|
||||
{
|
||||
// Arrange
|
||||
DeleteThemeRequest request = new(null);
|
||||
DeleteThemeRequest request = _deleteThemeRequestFixture.Create(includeThemeId: false);
|
||||
|
||||
// Act
|
||||
DeleteThemeCommand result = request.ToCommand();
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@ public class GetThemeArchiveRequestMappingTests
|
||||
public void ToQuery_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
||||
{
|
||||
// Arrange
|
||||
GetThemeArchiveRequest request = new(themeId);
|
||||
GetThemeArchiveRequest request = _getThemeArchiveRequestFixture.Create(themeId);
|
||||
|
||||
// Act
|
||||
GetThemeArchiveQuery result = request.ToQuery();
|
||||
@@ -53,7 +53,7 @@ public class GetThemeArchiveRequestMappingTests
|
||||
public void ToQuery_WhenThemeIdIsNull_ShouldMapNull()
|
||||
{
|
||||
// Arrange
|
||||
GetThemeArchiveRequest request = new(null);
|
||||
GetThemeArchiveRequest request = _getThemeArchiveRequestFixture.Create(includeThemeId: false);
|
||||
|
||||
// Act
|
||||
GetThemeArchiveQuery result = request.ToQuery();
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ public class GetThemeAssetRequestMappingTests
|
||||
public void ToQuery_WhenMappingDifferentThemeIdsAndAssetPaths_ShouldMapCorrectly(string themeId, string assetPath)
|
||||
{
|
||||
// Arrange
|
||||
GetThemeAssetRequest request = new(themeId, assetPath);
|
||||
GetThemeAssetRequest request = _getThemeAssetRequestFixture.Create(themeId, assetPath);
|
||||
|
||||
// Act
|
||||
GetThemeAssetQuery result = request.ToQuery();
|
||||
@@ -55,7 +55,7 @@ public class GetThemeAssetRequestMappingTests
|
||||
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
||||
{
|
||||
// Arrange
|
||||
GetThemeAssetRequest request = new(null, null);
|
||||
GetThemeAssetRequest request = _getThemeAssetRequestFixture.Create(includeThemeId: false, includeAssetPath: false);
|
||||
|
||||
// Act
|
||||
GetThemeAssetQuery result = request.ToQuery();
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ public class GetThemeTemplateRequestMappingTests
|
||||
public void ToQuery_WhenMappingDifferentThemeIdsAndPageKeys_ShouldMapCorrectly(string themeId, string pageKey)
|
||||
{
|
||||
// Arrange
|
||||
GetThemeTemplateRequest request = new(themeId, pageKey);
|
||||
GetThemeTemplateRequest request = _getThemeTemplateRequestFixture.Create(themeId, pageKey);
|
||||
|
||||
// Act
|
||||
GetThemeTemplateQuery result = request.ToQuery();
|
||||
@@ -55,7 +55,7 @@ public class GetThemeTemplateRequestMappingTests
|
||||
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
||||
{
|
||||
// Arrange
|
||||
GetThemeTemplateRequest request = new(null, null);
|
||||
GetThemeTemplateRequest request = _getThemeTemplateRequestFixture.Create(includeThemeId: false, includePageKey: false);
|
||||
|
||||
// Act
|
||||
GetThemeTemplateQuery result = request.ToQuery();
|
||||
|
||||
Loaded 100 of 157 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user