mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13:11:10 +00:00
Refactors the test fixtures and their consumers to compose other fixtures instead of instantiating models inline
This commit is contained in:
1 parent
0abda472c6
commit
3aadd6de84
157 files changed
+1312
-597
No files matched your search
+9
-3
@@ -21,16 +21,22 @@ public class PermissionEntityFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="id">Optional. The permission Id.</param>
|
/// <param name="id">Optional. The permission Id.</param>
|
||||||
/// <param name="permissionName">Optional. The permission name.</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>
|
/// <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>()
|
return new Faker<PermissionEntity>()
|
||||||
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
|
||||||
.RuleFor(x => x.PermissionName, f => permissionName ?? f.PickRandom<AuthorizationPermission>())
|
.RuleFor(x => x.PermissionName, f => permissionName ?? f.PickRandom<AuthorizationPermission>())
|
||||||
.RuleFor(x => x.RolePermissions, [])
|
.RuleFor(x => x.RolePermissions, [])
|
||||||
.RuleFor(x => x.UserPermissions, [])
|
.RuleFor(x => x.UserPermissions, [])
|
||||||
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
|
.RuleFor(x => x.CreatedOnUtc, f => createdOnUtc ?? f.Date.Past())
|
||||||
.RuleFor(x => x.CreatedBy, f => f.Random.Guid())
|
.RuleFor(x => x.CreatedBy, f => createdBy ?? f.Random.Guid())
|
||||||
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
|
||||||
.RuleFor(x => x.UpdatedBy, f => f.Random.Guid())
|
.RuleFor(x => x.UpdatedBy, f => f.Random.Guid())
|
||||||
.Generate();
|
.Generate();
|
||||||
|
|||||||
+12
-24
@@ -1,7 +1,6 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Bogus;
|
using Bogus;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -16,7 +15,9 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class RolePermissionEntityFixture
|
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>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="RolePermissionEntity"/>.
|
/// 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="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="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="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>
|
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
|
||||||
public RolePermissionEntity Create(
|
public RolePermissionEntity Create(
|
||||||
Guid? id = null,
|
Guid? id = null,
|
||||||
Guid? roleId = null,
|
Guid? roleId = null,
|
||||||
RoleEntity? role = null,
|
RoleEntity? role = null,
|
||||||
Guid? permissionId = null,
|
Guid? permissionId = null,
|
||||||
PermissionEntity? permission = null)
|
PermissionEntity? permission = null,
|
||||||
|
DateTime? createdOnUtc = null,
|
||||||
|
Guid? createdBy = null)
|
||||||
{
|
{
|
||||||
RoleEntity resolvedRole = role ?? new RoleEntity
|
RoleEntity resolvedRole = role ?? _roleEntityFixture.Value.Create(id: roleId);
|
||||||
{
|
PermissionEntity resolvedPermission = permission ?? _permissionEntityFixture.Create(id: permissionId);
|
||||||
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()
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Faker<RolePermissionEntity>()
|
return new Faker<RolePermissionEntity>()
|
||||||
.CustomInstantiator(f => new RolePermissionEntity
|
.CustomInstantiator(f => new RolePermissionEntity
|
||||||
@@ -62,8 +50,8 @@ public class RolePermissionEntityFixture
|
|||||||
Role = role ?? resolvedRole,
|
Role = role ?? resolvedRole,
|
||||||
PermissionId = resolvedPermission.Id,
|
PermissionId = resolvedPermission.Id,
|
||||||
Permission = permission ?? resolvedPermission,
|
Permission = permission ?? resolvedPermission,
|
||||||
CreatedOnUtc = f.Date.Past(),
|
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||||
CreatedBy = f.Random.Guid(),
|
CreatedBy = createdBy ?? f.Random.Guid(),
|
||||||
UpdatedOnUtc = f.Date.Recent(),
|
UpdatedOnUtc = f.Date.Recent(),
|
||||||
UpdatedBy = f.Random.Guid()
|
UpdatedBy = f.Random.Guid()
|
||||||
})
|
})
|
||||||
|
|||||||
+10
-3
@@ -2,6 +2,7 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -18,8 +19,14 @@ public class UserPermissionEntityFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The user the permission is granted to.</param>
|
/// <param name="user">The user the permission is granted to.</param>
|
||||||
/// <param name="permission">The permission granted to the user.</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>
|
/// <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>()
|
return new Faker<UserPermissionEntity>()
|
||||||
.CustomInstantiator(f => new UserPermissionEntity
|
.CustomInstantiator(f => new UserPermissionEntity
|
||||||
@@ -29,8 +36,8 @@ public class UserPermissionEntityFixture
|
|||||||
User = user,
|
User = user,
|
||||||
PermissionId = permission.Id,
|
PermissionId = permission.Id,
|
||||||
Permission = permission,
|
Permission = permission,
|
||||||
CreatedOnUtc = f.Date.Past(),
|
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||||
CreatedBy = user.Id,
|
CreatedBy = createdBy ?? user.Id,
|
||||||
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
|
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
|
||||||
UpdatedBy = f.Random.Bool() ? user.Id : null
|
UpdatedBy = f.Random.Bool() ? user.Id : null
|
||||||
})
|
})
|
||||||
|
|||||||
+15
-24
@@ -2,6 +2,7 @@
|
|||||||
using Bogus;
|
using Bogus;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
|
using Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -16,7 +17,8 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UserRoleEntityFixture
|
public class UserRoleEntityFixture
|
||||||
{
|
{
|
||||||
private readonly Faker _faker = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
|
private readonly RoleEntityFixture _roleEntityFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="UserRoleEntity"/>.
|
/// 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="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="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="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>
|
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
|
||||||
public UserRoleEntity Create(
|
public UserRoleEntity Create(
|
||||||
Guid? id = null,
|
Guid? id = null,
|
||||||
Guid? userId = null,
|
Guid? userId = null,
|
||||||
UserEntity? user = null,
|
UserEntity? user = null,
|
||||||
Guid? roleId = null,
|
Guid? roleId = null,
|
||||||
RoleEntity? role = null)
|
RoleEntity? role = null,
|
||||||
|
bool includeUser = true,
|
||||||
|
DateTime? createdOnUtc = null,
|
||||||
|
Guid? createdBy = null)
|
||||||
{
|
{
|
||||||
UserEntity resolvedUser = user ?? new UserEntity
|
UserEntity resolvedUser = user ?? _userEntityFixture.Create(id: userId);
|
||||||
{
|
RoleEntity resolvedRole = role ?? _roleEntityFixture.Create(id: roleId);
|
||||||
Id = userId ?? _faker.Random.Guid(),
|
|
||||||
Username = _faker.Internet.UserName(),
|
|
||||||
Password = _faker.Internet.Password(),
|
|
||||||
Libraries = [],
|
|
||||||
UserRole = null,
|
|
||||||
UserPermissions = [],
|
|
||||||
CreatedOnUtc = _faker.Date.Past(),
|
|
||||||
CreatedBy = _faker.Random.Guid()
|
|
||||||
};
|
|
||||||
|
|
||||||
RoleEntity resolvedRole = role ?? new RoleEntity
|
|
||||||
{
|
|
||||||
Id = roleId ?? _faker.Random.Guid(),
|
|
||||||
RoleName = _faker.Random.String2(_faker.Random.Number(1, 50)),
|
|
||||||
CreatedOnUtc = _faker.Date.Past(),
|
|
||||||
CreatedBy = _faker.Random.Guid()
|
|
||||||
};
|
|
||||||
|
|
||||||
return new Faker<UserRoleEntity>()
|
return new Faker<UserRoleEntity>()
|
||||||
.CustomInstantiator(f => new UserRoleEntity
|
.CustomInstantiator(f => new UserRoleEntity
|
||||||
{
|
{
|
||||||
Id = id ?? f.Random.Guid(),
|
Id = id ?? f.Random.Guid(),
|
||||||
UserId = resolvedUser.Id,
|
UserId = resolvedUser.Id,
|
||||||
User = user ?? resolvedUser,
|
User = includeUser ? (user ?? resolvedUser) : null!,
|
||||||
RoleId = resolvedRole.Id,
|
RoleId = resolvedRole.Id,
|
||||||
Role = role ?? resolvedRole,
|
Role = role ?? resolvedRole,
|
||||||
CreatedOnUtc = f.Date.Past(),
|
CreatedOnUtc = createdOnUtc ?? f.Date.Past(),
|
||||||
CreatedBy = f.Random.Guid()
|
CreatedBy = createdBy ?? f.Random.Guid()
|
||||||
})
|
})
|
||||||
.Generate();
|
.Generate();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -16,6 +16,8 @@ namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Ma
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LibraryEntityFixture
|
public class LibraryEntityFixture
|
||||||
{
|
{
|
||||||
|
private readonly LibraryContentLocationEntityFixture _libraryContentLocationEntityFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="LibraryEntity"/>.
|
/// Creates a random valid <see cref="LibraryEntity"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -76,7 +78,7 @@ public class LibraryEntityFixture
|
|||||||
.RuleFor(library => library.ContentLocations, f =>
|
.RuleFor(library => library.ContentLocations, f =>
|
||||||
{
|
{
|
||||||
IEnumerable<string> paths = contentLocations ?? [f.System.DirectoryPath(), f.System.DirectoryPath()];
|
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.CreatedOnUtc, f => f.Date.Past())
|
||||||
.RuleFor(library => library.CreatedBy, f => f.Random.Guid())
|
.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="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="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="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>
|
/// <returns>The created user entity.</returns>
|
||||||
public UserEntity Create(
|
public UserEntity Create(
|
||||||
int libraryCount = 0,
|
int libraryCount = 0,
|
||||||
@@ -42,7 +44,9 @@ public class UserEntityFixture
|
|||||||
IEnumerable<UserPermissionEntity>? userPermissions = null,
|
IEnumerable<UserPermissionEntity>? userPermissions = null,
|
||||||
ICollection<LibraryEntity>? libraries = null,
|
ICollection<LibraryEntity>? libraries = null,
|
||||||
bool includeUserRole = false,
|
bool includeUserRole = false,
|
||||||
bool includeUserPermissions = false)
|
bool includeUserPermissions = false,
|
||||||
|
Guid? createdBy = null,
|
||||||
|
DateTime? createdOnUtc = null)
|
||||||
{
|
{
|
||||||
Guid userId = id ?? Guid.NewGuid();
|
Guid userId = id ?? Guid.NewGuid();
|
||||||
ICollection<LibraryEntity> resolvedLibraries = libraries ?? (libraryCount > 0
|
ICollection<LibraryEntity> resolvedLibraries = libraries ?? (libraryCount > 0
|
||||||
@@ -60,11 +64,11 @@ public class UserEntityFixture
|
|||||||
Libraries = resolvedLibraries,
|
Libraries = resolvedLibraries,
|
||||||
UserPermissions = includeUserPermissions ? (userPermissions ?? []).ToList() : [],
|
UserPermissions = includeUserPermissions ? (userPermissions ?? []).ToList() : [],
|
||||||
UserRole = includeUserRole ? userRole : null,
|
UserRole = includeUserRole ? userRole : null,
|
||||||
CreatedBy = userId
|
CreatedBy = createdBy ?? userId
|
||||||
})
|
})
|
||||||
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
|
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
|
||||||
.RuleFor(x => x.Password, f => password ?? Uri.EscapeDataString(f.Internet.Password()))
|
.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)
|
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
|
||||||
.Generate();
|
.Generate();
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -19,15 +19,16 @@ public class CheckPathExistsQueryFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Optional. The file system path.</param>
|
/// <param name="path">Optional. The file system path.</param>
|
||||||
/// <param name="shouldIncludeHiddenElements">Whether to include hidden file system elements or not.</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>
|
/// <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>()
|
return new Faker<CheckPathExistsQuery>()
|
||||||
.CustomInstantiator(f => new CheckPathExistsQuery(
|
.CustomInstantiator(f => new CheckPathExistsQuery(
|
||||||
default!,
|
default!,
|
||||||
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);
|
.RuleFor(x => x.ShouldIncludeHiddenElements, shouldIncludeHiddenElements);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -18,13 +18,14 @@ public class ValidatePathQueryFixture
|
|||||||
/// Creates a random valid query to validate a path.
|
/// Creates a random valid query to validate a path.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Optional. The file system path.</param>
|
/// <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>
|
/// <returns>The created query.</returns>
|
||||||
public ValidatePathQuery Create(string? path = null)
|
public ValidatePathQuery Create(string? path = null, bool includePath = true)
|
||||||
{
|
{
|
||||||
return new Faker<ValidatePathQuery>()
|
return new Faker<ValidatePathQuery>()
|
||||||
.CustomInstantiator(f => new ValidatePathQuery(
|
.CustomInstantiator(f => new ValidatePathQuery(
|
||||||
default!))
|
default!))
|
||||||
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
|
.RuleFor(x => x.Path, f => includePath ? (path ?? f.System.FilePath()) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+3
-2
@@ -19,15 +19,16 @@ public class GetThumbnailQueryFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">Optional. The file system path.</param>
|
/// <param name="path">Optional. The file system path.</param>
|
||||||
/// <param name="quality">Optional. The thumbnail quality.</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>
|
/// <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>()
|
return new Faker<GetThumbnailQuery>()
|
||||||
.CustomInstantiator(f => new GetThumbnailQuery(
|
.CustomInstantiator(f => new GetThumbnailQuery(
|
||||||
default!,
|
default!,
|
||||||
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());
|
.RuleFor(x => x.Quality, f => quality ?? f.Random.Int());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -19,8 +19,9 @@ public class RecoverPasswordCommandFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">Optional. The username.</param>
|
/// <param name="username">Optional. The username.</param>
|
||||||
/// <param name="totpCode">Optional. The TOTP code.</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>
|
/// <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>()
|
return new Faker<RecoverPasswordCommand>()
|
||||||
.CustomInstantiator(f => new RecoverPasswordCommand(
|
.CustomInstantiator(f => new RecoverPasswordCommand(
|
||||||
@@ -28,7 +29,7 @@ public class RecoverPasswordCommandFixture
|
|||||||
default!
|
default!
|
||||||
))
|
))
|
||||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
.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>
|
/// <summary>
|
||||||
|
|||||||
+6
-3
@@ -20,13 +20,16 @@ public class LoginUserQueryFixture
|
|||||||
/// <param name="username">Optional. The username.</param>
|
/// <param name="username">Optional. The username.</param>
|
||||||
/// <param name="password">Optional. The password.</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="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>
|
/// <returns>The created query.</returns>
|
||||||
public LoginUserQuery Create(
|
public LoginUserQuery Create(
|
||||||
string? username = null,
|
string? username = null,
|
||||||
string? password = null,
|
string? password = null,
|
||||||
bool includeTotpCode = false)
|
bool includeTotpCode = false,
|
||||||
|
string? totpCode = null)
|
||||||
{
|
{
|
||||||
string resolvedPassword = password ?? "Abcd123$";
|
string resolvedPassword = password ?? "Abcd123$";
|
||||||
|
bool shouldIncludeTotpCode = includeTotpCode || totpCode is not null;
|
||||||
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
|
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
|
||||||
.CustomInstantiator(f => new LoginUserQuery(
|
.CustomInstantiator(f => new LoginUserQuery(
|
||||||
default!,
|
default!,
|
||||||
@@ -36,8 +39,8 @@ public class LoginUserQueryFixture
|
|||||||
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
|
||||||
.RuleFor(x => x.Password, resolvedPassword);
|
.RuleFor(x => x.Password, resolvedPassword);
|
||||||
|
|
||||||
if (includeTotpCode)
|
if (shouldIncludeTotpCode)
|
||||||
faker.RuleFor(x => x.TotpCode, f => f.Random.Replace("######")); // generates 6 random digits
|
faker.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######")); // generates 6 random digits when no code is pinned
|
||||||
return faker.Generate();
|
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="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="permissions">Optional. The permission Ids to assign.</param>
|
||||||
/// <param name="permissionCount">The number of permissions to generate when none are provided.</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>
|
/// <returns>The created command.</returns>
|
||||||
public UpdateUserRoleAndPermissionsCommand Create(
|
public UpdateUserRoleAndPermissionsCommand Create(
|
||||||
Guid? userId = null,
|
Guid? userId = null,
|
||||||
Guid? roleId = null,
|
Guid? roleId = null,
|
||||||
IEnumerable<Guid>? permissions = null,
|
IEnumerable<Guid>? permissions = null,
|
||||||
int permissionCount = 3)
|
int permissionCount = 3,
|
||||||
|
bool includePermissions = true)
|
||||||
{
|
{
|
||||||
return new Faker<UpdateUserRoleAndPermissionsCommand>()
|
return new Faker<UpdateUserRoleAndPermissionsCommand>()
|
||||||
.CustomInstantiator(f => new UpdateUserRoleAndPermissionsCommand(
|
.CustomInstantiator(f => new UpdateUserRoleAndPermissionsCommand(
|
||||||
userId ?? Guid.NewGuid(),
|
userId ?? Guid.NewGuid(),
|
||||||
roleId,
|
roleId,
|
||||||
default!))
|
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();
|
.Generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -19,12 +19,13 @@ public class GetUserPermissionsQueryFixture
|
|||||||
/// Creates a random valid query to get user permissions.
|
/// Creates a random valid query to get user permissions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Optional. The user Id.</param>
|
/// <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>
|
/// <returns>The created query.</returns>
|
||||||
public GetUserPermissionsQuery Create(Guid? userId = null)
|
public GetUserPermissionsQuery Create(Guid? userId = null, bool includeUserId = true)
|
||||||
{
|
{
|
||||||
return new Faker<GetUserPermissionsQuery>()
|
return new Faker<GetUserPermissionsQuery>()
|
||||||
.CustomInstantiator(f => new GetUserPermissionsQuery(
|
.CustomInstantiator(f => new GetUserPermissionsQuery(
|
||||||
userId ?? Guid.NewGuid()))
|
includeUserId ? (userId ?? Guid.NewGuid()) : null))
|
||||||
.Generate();
|
.Generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -19,12 +19,13 @@ public class GetUserRoleQueryFixture
|
|||||||
/// Creates a random valid query to get a user's role.
|
/// Creates a random valid query to get a user's role.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Optional. The user Id.</param>
|
/// <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>
|
/// <returns>The created query.</returns>
|
||||||
public GetUserRoleQuery Create(Guid? userId = null)
|
public GetUserRoleQuery Create(Guid? userId = null, bool includeUserId = true)
|
||||||
{
|
{
|
||||||
return new Faker<GetUserRoleQuery>()
|
return new Faker<GetUserRoleQuery>()
|
||||||
.CustomInstantiator(f => new GetUserRoleQuery(
|
.CustomInstantiator(f => new GetUserRoleQuery(
|
||||||
userId ?? Guid.NewGuid()))
|
includeUserId ? (userId ?? Guid.NewGuid()) : null))
|
||||||
.Generate();
|
.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
|
public class MediaContributorDtoFixture
|
||||||
{
|
{
|
||||||
private readonly Faker _faker = new();
|
private readonly Faker _faker = new();
|
||||||
|
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a random valid <see cref="MediaContributorDto"/>.
|
/// Creates a random valid <see cref="MediaContributorDto"/>.
|
||||||
@@ -38,9 +39,12 @@ public class MediaContributorDtoFixture
|
|||||||
bool includeRole = true)
|
bool includeRole = true)
|
||||||
{
|
{
|
||||||
return new MediaContributorDto(
|
return new MediaContributorDto(
|
||||||
Name: includeName ? new MediaContributorNameDto(
|
Name: includeName ? _mediaContributorNameDtoFixture.Create(
|
||||||
DisplayName: includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
displayName: displayName,
|
||||||
LegalName: includeLegalName ? legalName : null) : null,
|
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);
|
Role: includeRole ? role ?? _faker.PickRandom<MediaContributorRole>() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -21,14 +21,18 @@ public class MediaContributorNameDtoFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="displayName">Optional. The display name of the media contributor.</param>
|
/// <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="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>
|
/// <returns>The created <see cref="MediaContributorNameDto"/>.</returns>
|
||||||
public MediaContributorNameDto Create(
|
public MediaContributorNameDto Create(
|
||||||
string? displayName = null,
|
string? displayName = null,
|
||||||
string? legalName = null)
|
string? legalName = null,
|
||||||
|
bool includeDisplayName = true,
|
||||||
|
bool includeLegalName = true)
|
||||||
{
|
{
|
||||||
return new MediaContributorNameDto(
|
return new MediaContributorNameDto(
|
||||||
displayName ?? _faker.Name.FullName(),
|
includeDisplayName ? displayName ?? _faker.Name.FullName() : null,
|
||||||
legalName ?? _faker.Name.FullName());
|
includeLegalName ? legalName ?? _faker.Name.FullName() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+13
-5
@@ -23,19 +23,27 @@ public class ChangePasswordRequestFixture
|
|||||||
/// <param name="currentPassword">Optional. The current password.</param>
|
/// <param name="currentPassword">Optional. The current password.</param>
|
||||||
/// <param name="newPassword">Optional. The new password.</param>
|
/// <param name="newPassword">Optional. The new password.</param>
|
||||||
/// <param name="newPasswordConfirm">Optional. The new password confirmation.</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>
|
/// <returns>The created <see cref="ChangePasswordRequest"/>.</returns>
|
||||||
public ChangePasswordRequest Create(
|
public ChangePasswordRequest Create(
|
||||||
string? username = null,
|
string? username = null,
|
||||||
string? currentPassword = null,
|
string? currentPassword = null,
|
||||||
string? newPassword = 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();
|
string generatedNewPassword = newPassword ?? _faker.Internet.Password();
|
||||||
return new ChangePasswordRequest(
|
return new ChangePasswordRequest(
|
||||||
username ?? _faker.Internet.UserName(),
|
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||||
currentPassword ?? _faker.Internet.Password(),
|
includeCurrentPassword ? (currentPassword ?? _faker.Internet.Password()) : null,
|
||||||
generatedNewPassword,
|
includeNewPassword ? generatedNewPassword : null,
|
||||||
newPasswordConfirm ?? generatedNewPassword
|
includeNewPasswordConfirm ? (newPasswordConfirm ?? generatedNewPassword) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+10
-4
@@ -22,16 +22,22 @@ public class LoginRequestFixture
|
|||||||
/// <param name="username">Optional. The username for login.</param>
|
/// <param name="username">Optional. The username for login.</param>
|
||||||
/// <param name="password">Optional. The password 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="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>
|
/// <returns>The created <see cref="LoginRequest"/>.</returns>
|
||||||
public LoginRequest Create(
|
public LoginRequest Create(
|
||||||
string? username = null,
|
string? username = null,
|
||||||
string? password = null,
|
string? password = null,
|
||||||
string? totpCode = null)
|
string? totpCode = null,
|
||||||
|
bool includeUsername = true,
|
||||||
|
bool includePassword = true,
|
||||||
|
bool includeTotpCode = true)
|
||||||
{
|
{
|
||||||
return new LoginRequest(
|
return new LoginRequest(
|
||||||
username ?? _faker.Internet.UserName(),
|
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||||
password ?? _faker.Internet.Password(),
|
includePassword ? (password ?? _faker.Internet.Password()) : null,
|
||||||
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
includeTotpCode ? (totpCode ?? _faker.Random.Number(100000, 999999).ToString()) : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -21,14 +21,18 @@ public class RecoverPasswordRequestFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="username">Optional. The username for password recovery.</param>
|
/// <param name="username">Optional. The username for password recovery.</param>
|
||||||
/// <param name="totpCode">Optional. The TOTP code for verification.</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>
|
/// <returns>The created <see cref="RecoverPasswordRequest"/>.</returns>
|
||||||
public RecoverPasswordRequest Create(
|
public RecoverPasswordRequest Create(
|
||||||
string? username = null,
|
string? username = null,
|
||||||
string? totpCode = null)
|
string? totpCode = null,
|
||||||
|
bool includeUsername = true,
|
||||||
|
bool includeTotpCode = true)
|
||||||
{
|
{
|
||||||
return new RecoverPasswordRequest(
|
return new RecoverPasswordRequest(
|
||||||
username ?? _faker.Internet.UserName(),
|
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||||
totpCode ?? _faker.Random.Number(100000, 999999).ToString()
|
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="password">Optional. The password for registration.</param>
|
||||||
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
|
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
|
||||||
/// <param name="use2fa">Optional. Whether to use two-factor authentication.</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>
|
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
|
||||||
public RegistrationRequest Create(
|
public RegistrationRequest Create(
|
||||||
string? username = null,
|
string? username = null,
|
||||||
string? password = null,
|
string? password = null,
|
||||||
string? passwordConfirm = 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();
|
string generatedPassword = password ?? _faker.Internet.Password();
|
||||||
return new RegistrationRequest(
|
return new RegistrationRequest(
|
||||||
username ?? _faker.Internet.UserName(),
|
includeUsername ? (username ?? _faker.Internet.UserName()) : null,
|
||||||
generatedPassword,
|
includePassword ? generatedPassword : null,
|
||||||
passwordConfirm ?? generatedPassword,
|
includePasswordConfirm ? (passwordConfirm ?? generatedPassword) : null,
|
||||||
use2fa ?? _faker.Random.Bool()
|
use2fa ?? _faker.Random.Bool()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -22,12 +22,14 @@ public class AddRoleRequestFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleName">Optional. The name of the role.</param>
|
/// <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="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>
|
/// <returns>The created <see cref="AddRoleRequest"/>.</returns>
|
||||||
public AddRoleRequest Create(
|
public AddRoleRequest Create(
|
||||||
string? roleName = null,
|
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>
|
/// <summary>
|
||||||
|
|||||||
+4
-2
@@ -21,11 +21,13 @@ public class DeleteRoleRequestFixture
|
|||||||
/// Creates a random valid <see cref="DeleteRoleRequest"/>.
|
/// Creates a random valid <see cref="DeleteRoleRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="roleId">Optional. The Id of the role to delete.</param>
|
/// <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>
|
/// <returns>The created <see cref="DeleteRoleRequest"/>.</returns>
|
||||||
public DeleteRoleRequest Create(
|
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>
|
/// <summary>
|
||||||
|
|||||||
+3
-2
@@ -18,11 +18,12 @@ public class GetAuthorizationRequestFixture
|
|||||||
/// Creates a <see cref="GetAuthorizationRequest"/> with default or specified values.
|
/// Creates a <see cref="GetAuthorizationRequest"/> with default or specified values.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Optional. The user Id to use.</param>
|
/// <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>
|
/// <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(
|
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"/>.
|
/// Creates a random valid <see cref="GetUserPermissionsRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Optional. The Id of the user whose permissions are retrieved.</param>
|
/// <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>
|
/// <returns>The created <see cref="GetUserPermissionsRequest"/>.</returns>
|
||||||
public GetUserPermissionsRequest Create(
|
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>
|
/// <summary>
|
||||||
|
|||||||
+4
-2
@@ -18,11 +18,13 @@ public class GetUserRoleRequestFixture
|
|||||||
/// Creates a random valid <see cref="GetUserRoleRequest"/>.
|
/// Creates a random valid <see cref="GetUserRoleRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="userId">Optional. The Id of the user whose role is retrieved.</param>
|
/// <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>
|
/// <returns>The created <see cref="GetUserRoleRequest"/>.</returns>
|
||||||
public GetUserRoleRequest Create(
|
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>
|
/// <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="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="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="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>
|
/// <returns>The created <see cref="UpdateUserRoleAndPermissionsRequest"/>.</returns>
|
||||||
public UpdateUserRoleAndPermissionsRequest Create(
|
public UpdateUserRoleAndPermissionsRequest Create(
|
||||||
Guid? userId = null,
|
Guid? userId = null,
|
||||||
Guid? roleId = null,
|
Guid? roleId = null,
|
||||||
List<Guid>? permissions = null)
|
List<Guid>? permissions = null,
|
||||||
|
bool includeRoleId = true)
|
||||||
{
|
{
|
||||||
return new UpdateUserRoleAndPermissionsRequest(
|
return new UpdateUserRoleAndPermissionsRequest(
|
||||||
userId ?? Guid.NewGuid(),
|
userId ?? Guid.NewGuid(),
|
||||||
roleId ?? Guid.NewGuid(),
|
includeRoleId ? (roleId ?? Guid.NewGuid()) : null,
|
||||||
permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
|
permissions ?? [Guid.NewGuid(), Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-5
@@ -22,17 +22,21 @@ public class UpdatePluginSettingsRequestFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pluginId">Optional. The Id of the plugin whose settings are updated.</param>
|
/// <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="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>
|
/// <returns>The created <see cref="UpdatePluginSettingsRequest"/>.</returns>
|
||||||
public UpdatePluginSettingsRequest Create(
|
public UpdatePluginSettingsRequest Create(
|
||||||
Guid? pluginId = null,
|
Guid? pluginId = null,
|
||||||
IReadOnlyDictionary<string, string>? settings = null)
|
IReadOnlyDictionary<string, string>? settings = null,
|
||||||
|
bool includeSettings = true)
|
||||||
{
|
{
|
||||||
return new UpdatePluginSettingsRequest(
|
return new UpdatePluginSettingsRequest(
|
||||||
pluginId ?? _faker.Random.Guid(),
|
pluginId ?? _faker.Random.Guid(),
|
||||||
settings ?? new Dictionary<string, string>
|
includeSettings
|
||||||
{
|
? settings ?? new Dictionary<string, string>
|
||||||
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
{
|
||||||
}
|
[_faker.Lorem.Word()] = _faker.Lorem.Word()
|
||||||
|
}
|
||||||
|
: null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -20,10 +20,11 @@ public class DeleteThemeRequestFixture
|
|||||||
/// Creates a random valid <see cref="DeleteThemeRequest"/>.
|
/// Creates a random valid <see cref="DeleteThemeRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="themeId">Optional. The manifest id of the theme to delete.</param>
|
/// <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>
|
/// <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>
|
/// <summary>
|
||||||
|
|||||||
+3
-2
@@ -20,10 +20,11 @@ public class GetThemeArchiveRequestFixture
|
|||||||
/// Creates a random valid <see cref="GetThemeArchiveRequest"/>.
|
/// Creates a random valid <see cref="GetThemeArchiveRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
/// <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>
|
/// <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>
|
/// <summary>
|
||||||
|
|||||||
+10
-3
@@ -21,12 +21,19 @@ public class GetThemeAssetRequestFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
/// <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="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>
|
/// <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(
|
return new GetThemeAssetRequest(
|
||||||
themeId ?? _faker.Lorem.Slug(2),
|
includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null,
|
||||||
assetPath ?? _faker.System.FilePath());
|
includeAssetPath ? (assetPath ?? _faker.System.FilePath()) : null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+10
-3
@@ -21,12 +21,19 @@ public class GetThemeTemplateRequestFixture
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="themeId">Optional. The manifest id of the theme.</param>
|
/// <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="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>
|
/// <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(
|
return new GetThemeTemplateRequest(
|
||||||
themeId ?? _faker.Lorem.Slug(2),
|
includeThemeId ? (themeId ?? _faker.Lorem.Slug(2)) : null,
|
||||||
pageKey ?? _faker.Lorem.Word());
|
includePageKey ? (pageKey ?? _faker.Lorem.Word()) : null
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+3
-2
@@ -20,10 +20,11 @@ public class SetCurrentThemeRequestFixture
|
|||||||
/// Creates a random valid <see cref="SetCurrentThemeRequest"/>.
|
/// Creates a random valid <see cref="SetCurrentThemeRequest"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="themeId">Optional. The manifest id of the theme to activate.</param>
|
/// <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>
|
/// <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>
|
/// <summary>
|
||||||
|
|||||||
+9
-2
@@ -5,10 +5,17 @@ using System.Diagnostics.CodeAnalysis;
|
|||||||
namespace Lumina.Infrastructure.Fixtures.Common.Validation;
|
namespace Lumina.Infrastructure.Fixtures.Common.Validation;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test-support placeholder class for validation options tests.
|
/// Test-support placeholder options type used as the validated options in validation options tests.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ValidationOptionsFixture
|
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 =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
using Lumina.Application.Common.DataAccess.Entities.Authorization;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
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.Domain.SharedKernel.Common.Enums.Authorization;
|
||||||
using Lumina.Infrastructure.Core.Authorization;
|
using Lumina.Infrastructure.Core.Authorization;
|
||||||
using System;
|
using System;
|
||||||
@@ -16,6 +18,13 @@ namespace Lumina.Infrastructure.Fixtures.Core.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class AuthorizationServiceFixture
|
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>
|
/// <summary>
|
||||||
/// Creates a user entity with specified permissions and roles.
|
/// Creates a user entity with specified permissions and roles.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -28,7 +37,6 @@ public class AuthorizationServiceFixture
|
|||||||
{
|
{
|
||||||
Guid userId = Guid.NewGuid();
|
Guid userId = Guid.NewGuid();
|
||||||
DateTime utcNow = DateTime.UtcNow;
|
DateTime utcNow = DateTime.UtcNow;
|
||||||
List<UserPermissionEntity> userPermissions = [];
|
|
||||||
UserRoleEntity? userRole = null;
|
UserRoleEntity? userRole = null;
|
||||||
|
|
||||||
if (rolePermissions is not null)
|
if (rolePermissions is not null)
|
||||||
@@ -36,86 +44,63 @@ public class AuthorizationServiceFixture
|
|||||||
foreach (KeyValuePair<string, IEnumerable<AuthorizationPermission>> rolePerm in rolePermissions)
|
foreach (KeyValuePair<string, IEnumerable<AuthorizationPermission>> rolePerm in rolePermissions)
|
||||||
{
|
{
|
||||||
Guid roleId = Guid.NewGuid();
|
Guid roleId = Guid.NewGuid();
|
||||||
RoleEntity role = new()
|
RoleEntity role = _roleEntityFixture.Create(
|
||||||
{
|
id: roleId,
|
||||||
Id = roleId,
|
roleName: rolePerm.Key,
|
||||||
RoleName = rolePerm.Key,
|
createdBy: userId,
|
||||||
CreatedOnUtc = utcNow,
|
createdOnUtc: utcNow);
|
||||||
CreatedBy = userId,
|
|
||||||
RolePermissions = []
|
|
||||||
};
|
|
||||||
|
|
||||||
foreach (AuthorizationPermission permission in rolePerm.Value)
|
foreach (AuthorizationPermission permission in rolePerm.Value)
|
||||||
{
|
{
|
||||||
Guid permissionId = Guid.NewGuid();
|
Guid permissionId = Guid.NewGuid();
|
||||||
PermissionEntity permissionEntity = new()
|
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||||
{
|
id: permissionId,
|
||||||
Id = permissionId,
|
permissionName: permission,
|
||||||
PermissionName = permission,
|
createdBy: userId,
|
||||||
CreatedOnUtc = utcNow,
|
createdOnUtc: utcNow);
|
||||||
CreatedBy = userId
|
|
||||||
};
|
|
||||||
|
|
||||||
role.RolePermissions.Add(new RolePermissionEntity
|
role.RolePermissions.Add(_rolePermissionEntityFixture.Create(
|
||||||
{
|
role: role,
|
||||||
Id = Guid.NewGuid(),
|
permission: permissionEntity,
|
||||||
RoleId = roleId,
|
createdBy: userId,
|
||||||
Role = role,
|
createdOnUtc: utcNow));
|
||||||
PermissionId = permissionId,
|
|
||||||
Permission = permissionEntity,
|
|
||||||
CreatedOnUtc = utcNow,
|
|
||||||
CreatedBy = userId
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
userRole = new UserRoleEntity
|
userRole = _userRoleEntityFixture.Create(
|
||||||
{
|
userId: userId,
|
||||||
Id = Guid.NewGuid(),
|
roleId: roleId,
|
||||||
UserId = userId,
|
role: role,
|
||||||
User = null!,
|
includeUser: false,
|
||||||
RoleId = roleId,
|
createdBy: userId,
|
||||||
Role = role,
|
createdOnUtc: utcNow);
|
||||||
CreatedOnUtc = utcNow,
|
|
||||||
CreatedBy = userId
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UserEntity user = new()
|
UserEntity user = _userEntityFixture.Create(
|
||||||
{
|
username: "test-user",
|
||||||
Id = userId,
|
password: "hashed-password",
|
||||||
Username = "test-user",
|
id: userId,
|
||||||
Password = "hashed-password",
|
userRole: userRole,
|
||||||
CreatedOnUtc = utcNow,
|
includeUserRole: true,
|
||||||
CreatedBy = userId,
|
createdBy: userId,
|
||||||
Libraries = [],
|
createdOnUtc: utcNow);
|
||||||
UserPermissions = userPermissions,
|
|
||||||
UserRole = userRole
|
|
||||||
};
|
|
||||||
|
|
||||||
if (directPermissions is not null)
|
if (directPermissions is not null)
|
||||||
{
|
{
|
||||||
foreach (AuthorizationPermission permission in directPermissions)
|
foreach (AuthorizationPermission permission in directPermissions)
|
||||||
{
|
{
|
||||||
Guid permissionId = Guid.NewGuid();
|
Guid permissionId = Guid.NewGuid();
|
||||||
PermissionEntity permissionEntity = new()
|
PermissionEntity permissionEntity = _permissionEntityFixture.Create(
|
||||||
{
|
id: permissionId,
|
||||||
Id = permissionId,
|
permissionName: permission,
|
||||||
PermissionName = permission,
|
createdBy: userId,
|
||||||
CreatedOnUtc = utcNow,
|
createdOnUtc: utcNow);
|
||||||
CreatedBy = userId
|
|
||||||
};
|
|
||||||
|
|
||||||
userPermissions.Add(new UserPermissionEntity
|
user.UserPermissions.Add(_userPermissionEntityFixture.Create(
|
||||||
{
|
user,
|
||||||
Id = Guid.NewGuid(),
|
permissionEntity,
|
||||||
UserId = userId,
|
createdOnUtc: utcNow,
|
||||||
User = user,
|
createdBy: userId));
|
||||||
PermissionId = permissionId,
|
|
||||||
Permission = permissionEntity,
|
|
||||||
CreatedOnUtc = utcNow,
|
|
||||||
CreatedBy = userId
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Bogus;
|
using Bogus;
|
||||||
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
|
||||||
|
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using System;
|
using System;
|
||||||
@@ -16,21 +17,20 @@ namespace Lumina.Infrastructure.Fixtures.Core.Security;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class CryptographyServiceFixture
|
public class CryptographyServiceFixture
|
||||||
{
|
{
|
||||||
|
private readonly EncryptionSettingsDtoFixture _encryptionSettingsDtoFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a valid encryption settings model for testing.
|
/// Creates a valid encryption settings model for testing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The configured options.</returns>
|
/// <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
|
// Generate a valid 256-bit (32 byte) key for AES-256
|
||||||
byte[] key = new byte[32];
|
byte[] key = new byte[32];
|
||||||
RandomNumberGenerator.Fill(key);
|
RandomNumberGenerator.Fill(key);
|
||||||
string base64Key = Convert.ToBase64String(key);
|
string base64Key = Convert.ToBase64String(key);
|
||||||
|
|
||||||
EncryptionSettingsDto settings = new()
|
EncryptionSettingsDto settings = _encryptionSettingsDtoFixture.Create(secretKey: base64Key);
|
||||||
{
|
|
||||||
SecretKey = base64Key
|
|
||||||
};
|
|
||||||
|
|
||||||
IOptions<EncryptionSettingsDto> options = Substitute.For<IOptions<EncryptionSettingsDto>>();
|
IOptions<EncryptionSettingsDto> options = Substitute.For<IOptions<EncryptionSettingsDto>>();
|
||||||
options.Value.Returns(settings);
|
options.Value.Returns(settings);
|
||||||
@@ -42,7 +42,7 @@ public class CryptographyServiceFixture
|
|||||||
/// Creates test data for encryption/decryption.
|
/// Creates test data for encryption/decryption.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A string to be encrypted/decrypted.</returns>
|
/// <returns>A string to be encrypted/decrypted.</returns>
|
||||||
public static string CreateTestData()
|
public string CreateTestData()
|
||||||
{
|
{
|
||||||
return new Faker().Lorem.Sentence();
|
return new Faker().Lorem.Sentence();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,5 +20,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\src\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
<ProjectReference Include="..\..\..\src\Lumina.Infrastructure\Lumina.Infrastructure.csproj" />
|
||||||
|
<ProjectReference Include="..\Lumina.Application.Fixtures\Lumina.Application.Fixtures.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
+20
-7
@@ -23,21 +23,34 @@ internal class OpenLibrarySettingsDtoFixture
|
|||||||
/// <param name="searchResultLimit">Optional. The maximum number of search results.</param>
|
/// <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="workEditionLimit">Optional. The maximum number of editions fetched per work.</param>
|
||||||
/// <param name="minimumRequestInterval">Optional. The minimum interval between consecutive requests.</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>
|
/// <returns>The created <see cref="OpenLibrarySettingsDto"/>.</returns>
|
||||||
public OpenLibrarySettingsDto Create(
|
public OpenLibrarySettingsDto Create(
|
||||||
string? userAgent = null,
|
string? userAgent = null,
|
||||||
string? contactEmail = null,
|
string? contactEmail = null,
|
||||||
int? searchResultLimit = null,
|
int? searchResultLimit = null,
|
||||||
int? workEditionLimit = 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
|
||||||
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))
|
|
||||||
};
|
};
|
||||||
|
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="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="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="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>
|
/// <returns>The created <see cref="ProblemDetailsDto"/>.</returns>
|
||||||
public ProblemDetailsDto Create(
|
public ProblemDetailsDto Create(
|
||||||
string? type = null,
|
string? type = null,
|
||||||
string? title = null,
|
string? title = null,
|
||||||
int? status = null,
|
int? status = null,
|
||||||
string? detail = null,
|
string? detail = null,
|
||||||
string? instance = null)
|
string? instance = null,
|
||||||
|
bool includeType = true,
|
||||||
|
bool includeDetail = true)
|
||||||
{
|
{
|
||||||
return new ProblemDetailsDto
|
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(),
|
Title = title ?? _faker.Lorem.Word(),
|
||||||
Status = status ?? _faker.Random.Int(400, 599),
|
Status = status ?? _faker.Random.Int(400, 599),
|
||||||
Detail = detail ?? _faker.Lorem.Sentence(),
|
Detail = includeDetail ? (detail ?? _faker.Lorem.Sentence()) : null,
|
||||||
Instance = instance
|
Instance = instance
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-8
@@ -1,5 +1,4 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Bogus;
|
|
||||||
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
using Lumina.Presentation.Web.Common.DTO.MediaContributors;
|
||||||
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
using Lumina.Presentation.Web.Common.Enums.MediaContributors;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -10,12 +9,12 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
namespace Lumina.Presentation.Web.Fixtures.Common.DTO.MediaContributors;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="MediaContributorDto"/> test data.
|
/// Fixture class for the <see cref="MediaContributorDto"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class MediaContributorDtoFixture
|
public class MediaContributorDtoFixture
|
||||||
{
|
{
|
||||||
private readonly Faker _faker = new();
|
private readonly MediaContributorNameDtoFixture _mediaContributorNameDtoFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="MediaContributorDto"/> instance with randomized test data.
|
/// Creates a new <see cref="MediaContributorDto"/> instance with randomized test data.
|
||||||
@@ -31,11 +30,7 @@ public class MediaContributorDtoFixture
|
|||||||
{
|
{
|
||||||
return new MediaContributorDto
|
return new MediaContributorDto
|
||||||
{
|
{
|
||||||
Name = new MediaContributorNameDto
|
Name = _mediaContributorNameDtoFixture.Create(displayName, legalName),
|
||||||
{
|
|
||||||
DisplayName = displayName ?? _faker.Name.FullName(),
|
|
||||||
LegalName = legalName ?? _faker.Name.FullName()
|
|
||||||
},
|
|
||||||
Role = role ?? MediaContributorRole.Author
|
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;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="AddRoleRequest"/> test data.
|
/// Fixture class for the <see cref="AddRoleRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class AddRoleRequestFixture
|
public class AddRoleRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="DeleteRoleRequest"/> test data.
|
/// Fixture class for the <see cref="DeleteRoleRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class DeleteRoleRequestFixture
|
public class DeleteRoleRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Authorization;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="UpdateUserRoleAndPermissionsRequest"/> test data.
|
/// Fixture class for the <see cref="UpdateUserRoleAndPermissionsRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UpdateUserRoleAndPermissionsRequestFixture
|
public class UpdateUserRoleAndPermissionsRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Plugins;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="UpdatePluginSettingsRequest"/> test data.
|
/// Fixture class for the <see cref="UpdatePluginSettingsRequest"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UpdatePluginSettingsRequestFixture
|
public class UpdatePluginSettingsRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="DeleteThemeRequest"/> test data.
|
/// Fixture class for the <see cref="DeleteThemeRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class DeleteThemeRequestFixture
|
public class DeleteThemeRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="GetThemeArchiveRequest"/> test data.
|
/// Fixture class for the <see cref="GetThemeArchiveRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetThemeArchiveRequestFixture
|
public class GetThemeArchiveRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="GetThemeAssetRequest"/> test data.
|
/// Fixture class for the <see cref="GetThemeAssetRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetThemeAssetRequestFixture
|
public class GetThemeAssetRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.Themes;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="SetCurrentThemeRequest"/> test data.
|
/// Fixture class for the <see cref="SetCurrentThemeRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class SetCurrentThemeRequestFixture
|
public class SetCurrentThemeRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="ChangePasswordRequest"/> test data.
|
/// Fixture class for the <see cref="ChangePasswordRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ChangePasswordRequestFixture
|
public class ChangePasswordRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="LoginRequest"/> test data.
|
/// Fixture class for the <see cref="LoginRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LoginRequestFixture
|
public class LoginRequestFixture
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ using System.Linq;
|
|||||||
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
namespace Lumina.Presentation.Web.Fixtures.Common.Requests.UsersManagement;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fixture class for generating <see cref="RecoverPasswordRequest"/> test data.
|
/// Fixture class for the <see cref="RecoverPasswordRequest"/> record.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class RecoverPasswordRequestFixture
|
public class RecoverPasswordRequestFixture
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Presentation.Web;
|
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 Microsoft.AspNetCore.Mvc.Testing;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -28,6 +28,8 @@ public record AuthenticatedWebClient(HttpClient Client, string AntiforgeryToken)
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public static partial class WebTestHelpers
|
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_PAGE_PATH = "/en-us/auth/login";
|
||||||
private const string LOGIN_ENDPOINT_PATH = "/en-us/auth/api-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
|
// 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)
|
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
|
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted
|
||||||
loginRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
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 LibraryEntityFixture _libraryEntityFixture = new();
|
||||||
private readonly UserEntityFixture _userEntityFixture = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
|
private readonly LibraryContentLocationEntityFixture _libraryContentLocationEntityFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task UpdateAsync_WhenNothingChanged_ShouldNotChangeTheLibraryAudit()
|
public async Task UpdateAsync_WhenNothingChanged_ShouldNotChangeTheLibraryAudit()
|
||||||
@@ -78,7 +79,7 @@ public class LibraryRepositoryTests
|
|||||||
LibraryEntity incoming = await LoadDetachedLibraryAsync(context, library.Id);
|
LibraryEntity incoming = await LoadDetachedLibraryAsync(context, library.Id);
|
||||||
incoming.ContentLocations.Clear();
|
incoming.ContentLocations.Clear();
|
||||||
foreach (string path in new[] { "/media/one", "/media/keep", "/media/three" })
|
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
|
// Act
|
||||||
Result<Updated> result = await sut.UpdateAsync(incoming, CancellationToken.None);
|
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.Entities.UsersManagement;
|
||||||
using Lumina.Application.Common.DataAccess.Seed;
|
using Lumina.Application.Common.DataAccess.Seed;
|
||||||
using Lumina.Application.Fixtures.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.Contracts.Requests.Authentication;
|
||||||
using Lumina.Contracts.Responses.Authentication;
|
using Lumina.Contracts.Responses.Authentication;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
@@ -32,6 +33,7 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
|||||||
PropertyNameCaseInsensitive = true
|
PropertyNameCaseInsensitive = true
|
||||||
};
|
};
|
||||||
private readonly UserEntityFixture _userEntityFixture = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
|
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the username of the currently created test user.
|
/// Gets the username of the currently created test user.
|
||||||
@@ -74,9 +76,10 @@ public class AuthenticatedLuminaApiFactory : LuminaApiFactory, IDisposable
|
|||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
// authenticate user
|
// authenticate user
|
||||||
LoginRequest loginRequest = new(
|
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
Password: "TestPass123!"
|
password: "TestPass123!",
|
||||||
|
includeTotpCode: false
|
||||||
);
|
);
|
||||||
|
|
||||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
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);
|
await dataSeedService.SetAdminRoleToAdministratorAccount(user.Id, CancellationToken.None);
|
||||||
|
|
||||||
// authenticate user
|
// authenticate user
|
||||||
LoginRequest loginRequest = new(
|
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
Password: "TestPass123!"
|
password: "TestPass123!",
|
||||||
|
includeTotpCode: false
|
||||||
);
|
);
|
||||||
|
|
||||||
HttpResponseMessage loginResponse = await client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
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.Authorization;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
using Lumina.Contracts.DTO.Authentication;
|
using Lumina.Contracts.DTO.Authentication;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using Lumina.Contracts.Responses.Authorization;
|
using Lumina.Contracts.Responses.Authorization;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
@@ -33,6 +34,7 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
|||||||
{
|
{
|
||||||
private HttpClient _client;
|
private HttpClient _client;
|
||||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||||
|
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
@@ -65,9 +67,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
|||||||
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
LuminaDbContext dbContext = scope.ServiceProvider.GetRequiredService<LuminaDbContext>();
|
||||||
PermissionEntity[] permissions = [.. dbContext.Permissions.Take(2)];
|
PermissionEntity[] permissions = [.. dbContext.Permissions.Take(2)];
|
||||||
|
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
RoleName: "Editor",
|
roleName: "Editor",
|
||||||
Permissions: permissions.Select(p => p.Id).ToList()
|
permissions: permissions.Select(p => p.Id).ToList()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -95,9 +97,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
_client = await _apiFactory.CreateAuthenticatedClientAsync();
|
_client = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
RoleName: "Editor",
|
roleName: "Editor",
|
||||||
Permissions: [Guid.NewGuid()]
|
permissions: [Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -122,9 +124,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
|||||||
public async Task AddRole_WhenRoleAlreadyExists_ShouldReturnConflict()
|
public async Task AddRole_WhenRoleAlreadyExists_ShouldReturnConflict()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
RoleName: "Admin",
|
roleName: "Admin",
|
||||||
Permissions: [Guid.NewGuid()]
|
permissions: [Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -150,9 +152,9 @@ public class AddRoleEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
using CancellationTokenSource cts = new();
|
using CancellationTokenSource cts = new();
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
RoleName: "Editor",
|
roleName: "Editor",
|
||||||
Permissions: [Guid.NewGuid()]
|
permissions: [Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act & Assert
|
// 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.MediaContributors;
|
||||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
|
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary;
|
||||||
using Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
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.Fixtures.Core.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||||
using Lumina.Contracts.Requests.Authentication;
|
using Lumina.Contracts.Requests.Authentication;
|
||||||
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
using Lumina.Contracts.Requests.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||||
@@ -65,7 +66,9 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||||
};
|
};
|
||||||
private readonly UpdateTrackRequestFixture _requestTrackFixture = new();
|
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 ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||||
private readonly TagDtoFixture _tagDtoFixture = new();
|
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||||
@@ -127,8 +130,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
includeBpm: false,
|
includeBpm: false,
|
||||||
includeWork: false,
|
includeWork: false,
|
||||||
includeMusicBrainzRecordingId: false,
|
includeMusicBrainzRecordingId: false,
|
||||||
includeMusicBrainzTrackId: false,
|
includeMusicBrainzTrackId: false);
|
||||||
includeMusicBrainzWorkId: false);
|
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _client.PutAsJsonAsync($"/api/v1/libraries/{libraryId}/artists/{artistId}/albums/{albumId}/tracks/{trackId}", request);
|
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,
|
includeBpm: false,
|
||||||
includeWork: false,
|
includeWork: false,
|
||||||
includeMusicBrainzRecordingId: false,
|
includeMusicBrainzRecordingId: false,
|
||||||
includeMusicBrainzTrackId: false,
|
includeMusicBrainzTrackId: false);
|
||||||
includeMusicBrainzWorkId: false);
|
|
||||||
(HttpClient adminClient, _) = await CreateAdminClientAsync();
|
(HttpClient adminClient, _) = await CreateAdminClientAsync();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -817,7 +818,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
public async Task UpdateTrack_WhenWorkExceeds255Characters_ShouldReturnUnprocessableEntity()
|
public async Task UpdateTrack_WhenWorkExceeds255Characters_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
HttpResponseMessage response = await PutTrackAsync(request);
|
HttpResponseMessage response = await PutTrackAsync(request);
|
||||||
@@ -856,7 +857,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
public async Task UpdateTrack_WhenMusicBrainzWorkIdIsEmptyGuid_ShouldReturnUnprocessableEntity()
|
public async Task UpdateTrack_WhenMusicBrainzWorkIdIsEmptyGuid_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdateTrackRequest request = _requestTrackFixture.Create(musicBrainzWorkId: Guid.Empty);
|
UpdateTrackRequest request = _requestTrackFixture.Create(work: _musicWorkDtoFixture.Create(musicBrainzWorkId: Guid.Empty));
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await PutTrackAsync(request);
|
HttpResponseMessage response = await PutTrackAsync(request);
|
||||||
@@ -1160,7 +1161,7 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
|
|||||||
|
|
||||||
HttpClient client = _apiFactory.CreateClient();
|
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)}");
|
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();
|
string content = await loginResponse.Content.ReadAsStringAsync();
|
||||||
LoginResponse? loginResult = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
|
LoginResponse? loginResult = JsonSerializer.Deserialize<LoginResponse>(content, _jsonOptions);
|
||||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", loginResult!.Token);
|
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()
|
public async Task UpdateBook_WhenOriginalReleaseYearIsLessThan1_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||||
@@ -431,7 +431,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
|||||||
public async Task UpdateBook_WhenOriginalReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
public async Task UpdateBook_WhenOriginalReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||||
@@ -457,7 +457,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
|||||||
public async Task UpdateBook_WhenReReleaseYearIsLessThan1_ShouldReturnUnprocessableEntity()
|
public async Task UpdateBook_WhenReReleaseYearIsLessThan1_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
||||||
@@ -470,7 +470,7 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
|
|||||||
public async Task UpdateBook_WhenReReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
public async Task UpdateBook_WhenReReleaseYearIsGreaterThan9999_ShouldReturnUnprocessableEntity()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
HttpResponseMessage response = await PutBookAsync(bookRequest);
|
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.Themes;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
using Lumina.Application.Common.Infrastructure.Themes;
|
using Lumina.Application.Common.Infrastructure.Themes;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||||
using Lumina.Contracts.Requests.Themes;
|
using Lumina.Contracts.Requests.Themes;
|
||||||
using Lumina.Contracts.Responses.Themes;
|
using Lumina.Contracts.Responses.Themes;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
@@ -35,6 +36,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
private HttpClient _client;
|
private HttpClient _client;
|
||||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||||
private readonly TestThemeArchiveFixture _themeArchiveFixture = new();
|
private readonly TestThemeArchiveFixture _themeArchiveFixture = new();
|
||||||
|
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||||
private readonly List<string> _installedThemeIds = [];
|
private readonly List<string> _installedThemeIds = [];
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
{
|
{
|
||||||
@@ -66,7 +68,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
// Arrange
|
// Arrange
|
||||||
await ThemeTestHelpers.WaitForBundledThemeAsync(_apiFactory);
|
await ThemeTestHelpers.WaitForBundledThemeAsync(_apiFactory);
|
||||||
string themeId = await InstallThemeAsync();
|
string themeId = await InstallThemeAsync();
|
||||||
SetCurrentThemeRequest request = new(ThemeId: themeId);
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: themeId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||||
@@ -93,7 +95,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
string themeId = "nonexistent-theme";
|
string themeId = "nonexistent-theme";
|
||||||
SetCurrentThemeRequest request = new(ThemeId: themeId);
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: themeId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
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()
|
public async Task SetCurrentTheme_WhenThemeIdIsEmpty_ShouldReturnValidationProblem()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SetCurrentThemeRequest request = new(ThemeId: string.Empty);
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: string.Empty);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||||
@@ -147,7 +149,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
HttpClient nonAdminClient = await _apiFactory.CreateAuthenticatedClientAsync();
|
HttpClient nonAdminClient = await _apiFactory.CreateAuthenticatedClientAsync();
|
||||||
SetCurrentThemeRequest request = new(ThemeId: "editorial-paper");
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "editorial-paper");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await nonAdminClient.PutAsJsonAsync("/api/v1/themes/current", request);
|
HttpResponseMessage response = await nonAdminClient.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||||
@@ -172,7 +174,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
HttpClient anonymousClient = _apiFactory.CreateClient();
|
HttpClient anonymousClient = _apiFactory.CreateClient();
|
||||||
SetCurrentThemeRequest request = new(ThemeId: "editorial-paper");
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "editorial-paper");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await anonymousClient.PutAsJsonAsync("/api/v1/themes/current", request);
|
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.DataAccess.Entities.UsersManagement;
|
||||||
using Lumina.Application.Common.Infrastructure.Security;
|
using Lumina.Application.Common.Infrastructure.Security;
|
||||||
using Lumina.Application.Fixtures.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.Contracts.Requests.Authentication;
|
||||||
using Lumina.Contracts.Responses.Authentication;
|
using Lumina.Contracts.Responses.Authentication;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
@@ -37,6 +38,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
private readonly AuthenticatedLuminaApiFactory _apiFactory;
|
||||||
private readonly PasswordHashService _hashService = new();
|
private readonly PasswordHashService _hashService = new();
|
||||||
private readonly UserEntityFixture _userEntityFixture = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
|
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||||
private readonly ICryptographyService _cryptographyService;
|
private readonly ICryptographyService _cryptographyService;
|
||||||
private readonly TotpTokenGenerator _totpTokenGenerator = new();
|
private readonly TotpTokenGenerator _totpTokenGenerator = new();
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
@@ -81,9 +83,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
Totp totp = new(totpSecret);
|
Totp totp = new(totpSecret);
|
||||||
string validTotpCode = totp.ComputeTotp(DateTime.UtcNow);
|
string validTotpCode = totp.ComputeTotp(DateTime.UtcNow);
|
||||||
|
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
TotpCode: validTotpCode
|
totpCode: validTotpCode
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -118,9 +120,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
public async Task RecoverPassword_WhenUserDoesNotExist_ShouldReturnNotFound()
|
public async Task RecoverPassword_WhenUserDoesNotExist_ShouldReturnNotFound()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: "nonexistentuser",
|
username: "nonexistentuser",
|
||||||
TotpCode: "123456"
|
totpCode: "123456"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -146,9 +148,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UserEntity user = await CreateUserWithTotp();
|
UserEntity user = await CreateUserWithTotp();
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
TotpCode: "000000"
|
totpCode: "000000"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -210,9 +212,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
// Arrange
|
// Arrange
|
||||||
UserEntity user = await CreateUserWithoutTotp();
|
UserEntity user = await CreateUserWithoutTotp();
|
||||||
|
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
TotpCode: "123456"
|
totpCode: "123456"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -252,9 +254,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: "userwithoutotp2",
|
username: "userwithoutotp2",
|
||||||
TotpCode: null
|
includeTotpCode: false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -284,9 +286,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<AuthenticatedLuminaApi
|
|||||||
public async Task RecoverPassword_WhenCancellationRequested_ShouldThrowTaskCanceledException()
|
public async Task RecoverPassword_WhenCancellationRequested_ShouldThrowTaskCanceledException()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: "testuser",
|
username: "testuser",
|
||||||
TotpCode: "123456"
|
totpCode: "123456"
|
||||||
);
|
);
|
||||||
using CancellationTokenSource cts = new();
|
using CancellationTokenSource cts = new();
|
||||||
|
|
||||||
|
|||||||
+3
-2
@@ -1,8 +1,8 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Presentation.Web.Common.DTO.Themes;
|
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.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
||||||
using Lumina.Presentation.Web.Fixtures.Common.DTO.Themes;
|
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.Fixtures.Common.TestHelpers;
|
||||||
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
|
using Lumina.Presentation.Web.IntegrationTests.Common.Setup;
|
||||||
using System;
|
using System;
|
||||||
@@ -25,6 +25,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
|||||||
{
|
{
|
||||||
private readonly LuminaWebFactory _apiFactory;
|
private readonly LuminaWebFactory _apiFactory;
|
||||||
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
private readonly ThemeResponseDtoFixture _themeResponseDtoFixture = new();
|
||||||
|
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
/// 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);
|
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
|
||||||
HttpRequestMessage setCurrentThemeRequest = new(HttpMethod.Put, "/en-us/admin/themes/api-set-current-theme")
|
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.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||||
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|||||||
+5
-3
@@ -1,4 +1,5 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Themes;
|
||||||
using Lumina.Contracts.Requests.Themes;
|
using Lumina.Contracts.Requests.Themes;
|
||||||
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
using Lumina.Presentation.Api.SecurityTests.Common.Setup;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
@@ -18,6 +19,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
{
|
{
|
||||||
private readonly LuminaApiFactory _apiFactory;
|
private readonly LuminaApiFactory _apiFactory;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
|
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true
|
PropertyNameCaseInsensitive = true
|
||||||
@@ -39,7 +41,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
public async Task SetCurrentTheme_WhenUnauthorized_ShouldReturnUnauthorizedResult()
|
public async Task SetCurrentTheme_WhenUnauthorized_ShouldReturnUnauthorizedResult()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SetCurrentThemeRequest request = new("some-theme");
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "some-theme");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
HttpResponseMessage response = await _client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||||
@@ -64,7 +66,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
// Arrange
|
// Arrange
|
||||||
HttpClient client = _apiFactory.CreateClient();
|
HttpClient client = _apiFactory.CreateClient();
|
||||||
await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
await _apiFactory.CreateAndAuthenticateUserAsync(client);
|
||||||
SetCurrentThemeRequest request = new("some-theme");
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: "some-theme");
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await client.PutAsJsonAsync("/api/v1/themes/current", request);
|
HttpResponseMessage response = await client.PutAsJsonAsync("/api/v1/themes/current", request);
|
||||||
@@ -96,7 +98,7 @@ public class SetCurrentThemeEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
// Arrange
|
// Arrange
|
||||||
HttpClient client = _apiFactory.CreateClient();
|
HttpClient client = _apiFactory.CreateClient();
|
||||||
await _apiFactory.CreateAndAuthenticateAdminUserAsync(client);
|
await _apiFactory.CreateAndAuthenticateAdminUserAsync(client);
|
||||||
SetCurrentThemeRequest request = new(maliciousThemeId);
|
SetCurrentThemeRequest request = _setCurrentThemeRequestFixture.Create(themeId: maliciousThemeId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
HttpResponseMessage response = await client.PutAsJsonAsync("/api/v1/themes/current", request);
|
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 PasswordHashService _hashService = new();
|
||||||
private readonly UserEntityFixture _userEntityFixture = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||||
|
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||||
private readonly string _testUsername;
|
private readonly string _testUsername;
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
{
|
{
|
||||||
@@ -165,9 +166,10 @@ public class ChangePasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDis
|
|||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
// Authenticate user.
|
// Authenticate user.
|
||||||
LoginRequest loginRequest = new(
|
LoginRequest loginRequest = _loginRequestFixture.Create(
|
||||||
Username: user.Username,
|
username: user.Username,
|
||||||
Password: "TestPass123!"
|
password: "TestPass123!",
|
||||||
|
includeTotpCode: false
|
||||||
);
|
);
|
||||||
|
|
||||||
HttpResponseMessage loginResponse = await _client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
HttpResponseMessage loginResponse = await _client.PostAsJsonAsync("/api/v1/auth/login", loginRequest);
|
||||||
|
|||||||
+8
-6
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
|
||||||
using Lumina.Application.Fixtures.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.Contracts.Requests.Authentication;
|
||||||
using Lumina.DataAccess.Core.UoW;
|
using Lumina.DataAccess.Core.UoW;
|
||||||
using Lumina.Infrastructure.Core.Security;
|
using Lumina.Infrastructure.Core.Security;
|
||||||
@@ -32,6 +33,7 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
private readonly PasswordHashService _hashService = new();
|
private readonly PasswordHashService _hashService = new();
|
||||||
private readonly UserEntityFixture _userEntityFixture = new();
|
private readonly UserEntityFixture _userEntityFixture = new();
|
||||||
|
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||||
{
|
{
|
||||||
PropertyNameCaseInsensitive = true,
|
PropertyNameCaseInsensitive = true,
|
||||||
@@ -57,9 +59,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
public async Task RecoverPassword_WhenRateLimitExceeded_ShouldReturnTooManyRequests()
|
public async Task RecoverPassword_WhenRateLimitExceeded_ShouldReturnTooManyRequests()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: "testuser",
|
username: "testuser",
|
||||||
TotpCode: "123456"
|
totpCode: "123456"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -97,9 +99,9 @@ public class RecoverPasswordEndpointTests : IClassFixture<LuminaApiFactory>, IDi
|
|||||||
client.DefaultRequestHeaders.Clear();
|
client.DefaultRequestHeaders.Clear();
|
||||||
client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
|
client.DefaultRequestHeaders.Add("X-Forwarded-For", LuminaApiFactory.GetUniqueTestIp());
|
||||||
UserEntity legitimateUser = await CreateTestUser();
|
UserEntity legitimateUser = await CreateTestUser();
|
||||||
RecoverPasswordRequest request = new(
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
Username: maliciousUsername,
|
username: maliciousUsername,
|
||||||
TotpCode: "123456"
|
totpCode: "123456"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|||||||
+4
-3
@@ -1,6 +1,6 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Presentation.Web.Common.Requests.Themes;
|
|
||||||
using Lumina.Presentation.Web.Core.Endpoints.Admin.Themes.SetCurrentTheme;
|
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.Fixtures.Common.TestHelpers;
|
||||||
using Lumina.Presentation.Web.SecurityTests.Common.Setup;
|
using Lumina.Presentation.Web.SecurityTests.Common.Setup;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -18,6 +18,7 @@ namespace Lumina.Presentation.Web.SecurityTests.Core.Endpoints.Admin.Themes.SetC
|
|||||||
public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
public class SetCurrentThemeEndpointTests : IClassFixture<LuminaWebFactory>
|
||||||
{
|
{
|
||||||
private readonly LuminaWebFactory _apiFactory;
|
private readonly LuminaWebFactory _apiFactory;
|
||||||
|
private readonly SetCurrentThemeRequestFixture _setCurrentThemeRequestFixture = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="SetCurrentThemeEndpointTests"/> class.
|
/// 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.
|
/// Builds a PUT request for the set current theme route with the JSON content type required by the antiforgery validation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The configured PUT request.</returns>
|
/// <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")
|
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.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
|
||||||
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
setCurrentThemeRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
|||||||
+12
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ChangePasswordRequestMappingTests
|
public class ChangePasswordRequestMappingTests
|
||||||
{
|
{
|
||||||
private readonly ChangePasswordRequestFixture _fixture = new();
|
private readonly ChangePasswordRequestFixture _changePasswordRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
ChangePasswordRequest request = _fixture.Create();
|
ChangePasswordRequest request = _changePasswordRequestFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ChangePasswordCommand result = request.ToCommand();
|
ChangePasswordCommand result = request.ToCommand();
|
||||||
@@ -37,7 +37,7 @@ public class ChangePasswordRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
ChangePasswordRequest request = new(null, null, null, null);
|
ChangePasswordRequest request = _changePasswordRequestFixture.Create(includeUsername: false, includeCurrentPassword: false, includeNewPassword: false, includeNewPasswordConfirm: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ChangePasswordCommand result = request.ToCommand();
|
ChangePasswordCommand result = request.ToCommand();
|
||||||
@@ -61,7 +61,15 @@ public class ChangePasswordRequestMappingTests
|
|||||||
string? newPasswordConfirm)
|
string? newPasswordConfirm)
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
ChangePasswordCommand result = request.ToCommand();
|
ChangePasswordCommand result = request.ToCommand();
|
||||||
|
|||||||
+10
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class LoginRequestMappingTests
|
public class LoginRequestMappingTests
|
||||||
{
|
{
|
||||||
private readonly LoginRequestFixture _fixture = new();
|
private readonly LoginRequestFixture _loginRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
LoginRequest request = _fixture.Create();
|
LoginRequest request = _loginRequestFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
LoginUserQuery result = request.ToQuery();
|
LoginUserQuery result = request.ToQuery();
|
||||||
@@ -36,7 +36,7 @@ public class LoginRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
LoginRequest request = new(null, null);
|
LoginRequest request = _loginRequestFixture.Create(includeUsername: false, includePassword: false, includeTotpCode: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
LoginUserQuery result = request.ToQuery();
|
LoginUserQuery result = request.ToQuery();
|
||||||
@@ -59,7 +59,13 @@ public class LoginRequestMappingTests
|
|||||||
string? totpCode)
|
string? totpCode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
LoginUserQuery result = request.ToQuery();
|
LoginUserQuery result = request.ToQuery();
|
||||||
|
|||||||
+8
-4
@@ -14,13 +14,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class RecoverPasswordRequestMappingTests
|
public class RecoverPasswordRequestMappingTests
|
||||||
{
|
{
|
||||||
private readonly RecoverPasswordRequestFixture _fixture = new();
|
private readonly RecoverPasswordRequestFixture _recoverPasswordRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = _fixture.Create();
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
RecoverPasswordCommand result = request.ToCommand();
|
RecoverPasswordCommand result = request.ToCommand();
|
||||||
@@ -35,7 +35,7 @@ public class RecoverPasswordRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = new(null, null);
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(includeUsername: false, includeTotpCode: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
RecoverPasswordCommand result = request.ToCommand();
|
RecoverPasswordCommand result = request.ToCommand();
|
||||||
@@ -56,7 +56,11 @@ public class RecoverPasswordRequestMappingTests
|
|||||||
string? totpCode)
|
string? totpCode)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RecoverPasswordRequest request = new(username, totpCode);
|
RecoverPasswordRequest request = _recoverPasswordRequestFixture.Create(
|
||||||
|
username,
|
||||||
|
totpCode,
|
||||||
|
includeUsername: username is not null,
|
||||||
|
includeTotpCode: totpCode is not null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
RecoverPasswordCommand result = request.ToCommand();
|
RecoverPasswordCommand result = request.ToCommand();
|
||||||
|
|||||||
+21
-7
@@ -15,13 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authentication;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class RegistrationRequestMappingTests
|
public class RegistrationRequestMappingTests
|
||||||
{
|
{
|
||||||
private readonly RegistrationRequestFixture _fixture = new();
|
private readonly RegistrationRequestFixture _registrationRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToSetupCommand_WhenMappingRequest_ShouldMapCorrectly()
|
public void ToSetupCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RegistrationRequest request = _fixture.Create();
|
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
SetupApplicationCommand result = request.ToSetupCommand();
|
SetupApplicationCommand result = request.ToSetupCommand();
|
||||||
@@ -38,7 +38,7 @@ public class RegistrationRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RegistrationRequest request = _fixture.Create();
|
RegistrationRequest request = _registrationRequestFixture.Create();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
RegisterUserCommand result = request.ToCommand();
|
RegisterUserCommand result = request.ToCommand();
|
||||||
@@ -55,7 +55,7 @@ public class RegistrationRequestMappingTests
|
|||||||
public void ToSetupCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
public void ToSetupCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RegistrationRequest request = new();
|
RegistrationRequest request = _registrationRequestFixture.Create(includeUsername: false, includePassword: false, includePasswordConfirm: false, use2fa: true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
SetupApplicationCommand result = request.ToSetupCommand();
|
SetupApplicationCommand result = request.ToSetupCommand();
|
||||||
@@ -72,7 +72,7 @@ public class RegistrationRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequestWithNullValues_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
RegistrationRequest request = new();
|
RegistrationRequest request = _registrationRequestFixture.Create(includeUsername: false, includePassword: false, includePasswordConfirm: false, use2fa: true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
RegisterUserCommand result = request.ToCommand();
|
RegisterUserCommand result = request.ToCommand();
|
||||||
@@ -97,7 +97,14 @@ public class RegistrationRequestMappingTests
|
|||||||
bool use2fa)
|
bool use2fa)
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
SetupApplicationCommand result = request.ToSetupCommand();
|
SetupApplicationCommand result = request.ToSetupCommand();
|
||||||
@@ -122,7 +129,14 @@ public class RegistrationRequestMappingTests
|
|||||||
bool use2fa)
|
bool use2fa)
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
RegisterUserCommand result = request.ToCommand();
|
RegisterUserCommand result = request.ToCommand();
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class AddRoleRequestMappingTests
|
public class AddRoleRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly AddRoleRequestFixture _addRoleRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
"Admin",
|
"Admin",
|
||||||
[Guid.NewGuid(), Guid.NewGuid()]
|
[Guid.NewGuid(), Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
@@ -37,7 +40,7 @@ public class AddRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequestWithEmptyPermissions_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingRequestWithEmptyPermissions_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
"Guest",
|
"Guest",
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
@@ -58,7 +61,7 @@ public class AddRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
AddRoleRequest request = new(
|
AddRoleRequest request = _addRoleRequestFixture.Create(
|
||||||
roleName,
|
roleName,
|
||||||
[Guid.NewGuid()]
|
[Guid.NewGuid()]
|
||||||
);
|
);
|
||||||
@@ -82,7 +85,7 @@ public class AddRoleRequestMappingTests
|
|||||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||||
];
|
];
|
||||||
AddRoleRequest request = new("SuperAdmin", permissions);
|
AddRoleRequest request = _addRoleRequestFixture.Create("SuperAdmin", permissions);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
AddRoleCommand result = request.ToCommand();
|
AddRoleCommand result = request.ToCommand();
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class DeleteRoleRequestMappingTests
|
public class DeleteRoleRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly DeleteRoleRequestFixture _deleteRoleRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid roleId = Guid.NewGuid();
|
Guid roleId = Guid.NewGuid();
|
||||||
DeleteRoleRequest request = new(roleId);
|
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
DeleteRoleCommand result = request.ToCommand();
|
DeleteRoleCommand result = request.ToCommand();
|
||||||
@@ -37,7 +40,7 @@ public class DeleteRoleRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid roleId = Guid.Parse(roleIdString);
|
Guid roleId = Guid.Parse(roleIdString);
|
||||||
DeleteRoleRequest request = new(roleId);
|
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(roleId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
DeleteRoleCommand result = request.ToCommand();
|
DeleteRoleCommand result = request.ToCommand();
|
||||||
@@ -51,7 +54,7 @@ public class DeleteRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenRoleIdIsNull_ShouldThrowInvalidOperationException()
|
public void ToCommand_WhenRoleIdIsNull_ShouldThrowInvalidOperationException()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
DeleteRoleRequest request = new(null);
|
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(includeRoleId: false);
|
||||||
|
|
||||||
// Act & Assert
|
// Act & Assert
|
||||||
Assert.Throws<InvalidOperationException>(() => request.ToCommand());
|
Assert.Throws<InvalidOperationException>(() => request.ToCommand());
|
||||||
@@ -61,7 +64,7 @@ public class DeleteRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
DeleteRoleRequest request = new(Guid.Empty);
|
DeleteRoleRequest request = _deleteRoleRequestFixture.Create(Guid.Empty);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
DeleteRoleCommand result = request.ToCommand();
|
DeleteRoleCommand result = request.ToCommand();
|
||||||
|
|||||||
+6
-3
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetAuthorizationRequestMappingTests
|
public class GetAuthorizationRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetAuthorizationRequestFixture _getAuthorizationRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.NewGuid();
|
Guid userId = Guid.NewGuid();
|
||||||
GetAuthorizationRequest request = new(userId);
|
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetAuthorizationQuery result = request.ToQuery();
|
GetAuthorizationQuery result = request.ToQuery();
|
||||||
@@ -33,7 +36,7 @@ public class GetAuthorizationRequestMappingTests
|
|||||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetAuthorizationRequest request = new(null);
|
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(includeUserId: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetAuthorizationQuery result = request.ToQuery();
|
GetAuthorizationQuery result = request.ToQuery();
|
||||||
@@ -51,7 +54,7 @@ public class GetAuthorizationRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.Parse(userIdString);
|
Guid userId = Guid.Parse(userIdString);
|
||||||
GetAuthorizationRequest request = new(userId);
|
GetAuthorizationRequest request = _getAuthorizationRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetAuthorizationQuery result = request.ToQuery();
|
GetAuthorizationQuery result = request.ToQuery();
|
||||||
|
|||||||
+6
-3
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetRolePermissionsRequestMappingTests
|
public class GetRolePermissionsRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetRolePermissionsRequestFixture _getRolePermissionsRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid roleId = Guid.NewGuid();
|
Guid roleId = Guid.NewGuid();
|
||||||
GetRolePermissionsRequest request = new(roleId);
|
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetRolePermissionsQuery result = request.ToQuery();
|
GetRolePermissionsQuery result = request.ToQuery();
|
||||||
@@ -37,7 +40,7 @@ public class GetRolePermissionsRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid roleId = Guid.Parse(roleIdString);
|
Guid roleId = Guid.Parse(roleIdString);
|
||||||
GetRolePermissionsRequest request = new(roleId);
|
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(roleId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetRolePermissionsQuery result = request.ToQuery();
|
GetRolePermissionsQuery result = request.ToQuery();
|
||||||
@@ -51,7 +54,7 @@ public class GetRolePermissionsRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetRolePermissionsRequest request = new(Guid.Empty);
|
GetRolePermissionsRequest request = _getRolePermissionsRequestFixture.Create(Guid.Empty);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetRolePermissionsQuery result = request.ToQuery();
|
GetRolePermissionsQuery result = request.ToQuery();
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetUserPermissionsRequestMappingTests
|
public class GetUserPermissionsRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetUserPermissionsRequestFixture _getUserPermissionsRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.NewGuid();
|
Guid userId = Guid.NewGuid();
|
||||||
GetUserPermissionsRequest request = new(userId);
|
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserPermissionsQuery result = request.ToQuery();
|
GetUserPermissionsQuery result = request.ToQuery();
|
||||||
@@ -33,7 +36,7 @@ public class GetUserPermissionsRequestMappingTests
|
|||||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetUserPermissionsRequest request = new(null);
|
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(includeUserId: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserPermissionsQuery result = request.ToQuery();
|
GetUserPermissionsQuery result = request.ToQuery();
|
||||||
@@ -51,7 +54,7 @@ public class GetUserPermissionsRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.Parse(userIdString);
|
Guid userId = Guid.Parse(userIdString);
|
||||||
GetUserPermissionsRequest request = new(userId);
|
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserPermissionsQuery result = request.ToQuery();
|
GetUserPermissionsQuery result = request.ToQuery();
|
||||||
@@ -65,7 +68,7 @@ public class GetUserPermissionsRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetUserPermissionsRequest request = new(Guid.Empty);
|
GetUserPermissionsRequest request = _getUserPermissionsRequestFixture.Create(Guid.Empty);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserPermissionsQuery result = request.ToQuery();
|
GetUserPermissionsQuery result = request.ToQuery();
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,12 +15,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetUserRoleRequestMappingTests
|
public class GetUserRoleRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetUserRoleRequestFixture _getUserRoleRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.NewGuid();
|
Guid userId = Guid.NewGuid();
|
||||||
GetUserRoleRequest request = new(userId);
|
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserRoleQuery result = request.ToQuery();
|
GetUserRoleQuery result = request.ToQuery();
|
||||||
@@ -33,7 +36,7 @@ public class GetUserRoleRequestMappingTests
|
|||||||
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
public void ToQuery_WhenUserIdIsNull_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetUserRoleRequest request = new(null);
|
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(includeUserId: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserRoleQuery result = request.ToQuery();
|
GetUserRoleQuery result = request.ToQuery();
|
||||||
@@ -51,7 +54,7 @@ public class GetUserRoleRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
Guid userId = Guid.Parse(userIdString);
|
Guid userId = Guid.Parse(userIdString);
|
||||||
GetUserRoleRequest request = new(userId);
|
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(userId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserRoleQuery result = request.ToQuery();
|
GetUserRoleQuery result = request.ToQuery();
|
||||||
@@ -65,7 +68,7 @@ public class GetUserRoleRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingEmptyGuid_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetUserRoleRequest request = new(Guid.Empty);
|
GetUserRoleRequest request = _getUserRoleRequestFixture.Create(Guid.Empty);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetUserRoleQuery result = request.ToQuery();
|
GetUserRoleQuery result = request.ToQuery();
|
||||||
|
|||||||
+7
-4
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,12 +16,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UpdateRoleRequestMappingTests
|
public class UpdateRoleRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly UpdateRoleRequestFixture _updateRoleRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
List<Guid> permissions = [Guid.NewGuid(), Guid.NewGuid()];
|
List<Guid> permissions = [Guid.NewGuid(), Guid.NewGuid()];
|
||||||
UpdateRoleRequest request = new(
|
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
"Admin",
|
"Admin",
|
||||||
permissions
|
permissions
|
||||||
@@ -43,7 +46,7 @@ public class UpdateRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
public void ToCommand_WhenMappingDifferentRoleNames_ShouldMapCorrectly(string roleName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdateRoleRequest request = new(
|
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
roleName,
|
roleName,
|
||||||
[Guid.NewGuid()]
|
[Guid.NewGuid()]
|
||||||
@@ -64,7 +67,7 @@ public class UpdateRoleRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentRoleIds_ShouldMapCorrectly(string roleIdString)
|
public void ToCommand_WhenMappingDifferentRoleIds_ShouldMapCorrectly(string roleIdString)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdateRoleRequest request = new(
|
UpdateRoleRequest request = _updateRoleRequestFixture.Create(
|
||||||
Guid.Parse(roleIdString),
|
Guid.Parse(roleIdString),
|
||||||
"Admin",
|
"Admin",
|
||||||
[Guid.NewGuid()]
|
[Guid.NewGuid()]
|
||||||
@@ -88,7 +91,7 @@ public class UpdateRoleRequestMappingTests
|
|||||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||||
];
|
];
|
||||||
UpdateRoleRequest request = new(Guid.NewGuid(), "Admin", permissions);
|
UpdateRoleRequest request = _updateRoleRequestFixture.Create(Guid.NewGuid(), "Admin", permissions);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
UpdateRoleCommand result = request.ToCommand();
|
UpdateRoleCommand result = request.ToCommand();
|
||||||
|
|||||||
+10
-6
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Authorization;
|
using Lumina.Application.Common.Mapping.Authorization;
|
||||||
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Authorization;
|
||||||
using Lumina.Contracts.Requests.Authorization;
|
using Lumina.Contracts.Requests.Authorization;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,12 +16,14 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Authorization;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UpdateUserRoleAndPermissionsRequestMappingTests
|
public class UpdateUserRoleAndPermissionsRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly UpdateUserRoleAndPermissionsRequestFixture _updateUserRoleAndPermissionsRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
List<Guid> permissions = [Guid.NewGuid()];
|
List<Guid> permissions = [Guid.NewGuid()];
|
||||||
UpdateUserRoleAndPermissionsRequest request = new(
|
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
permissions
|
permissions
|
||||||
@@ -41,10 +44,11 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
List<Guid> permissions = [Guid.NewGuid()];
|
List<Guid> permissions = [Guid.NewGuid()];
|
||||||
UpdateUserRoleAndPermissionsRequest request = new(
|
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
null,
|
roleId: null,
|
||||||
permissions
|
permissions: permissions,
|
||||||
|
includeRoleId: false
|
||||||
);
|
);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -64,7 +68,7 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
public void ToCommand_WhenMappingDifferentUserIds_ShouldMapCorrectly(string userIdString)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdateUserRoleAndPermissionsRequest request = new(
|
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||||
Guid.Parse(userIdString),
|
Guid.Parse(userIdString),
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
[Guid.NewGuid()]
|
[Guid.NewGuid()]
|
||||||
@@ -88,7 +92,7 @@ public class UpdateUserRoleAndPermissionsRequestMappingTests
|
|||||||
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
Guid.Parse("00000000-0000-0000-0000-000000000002"),
|
||||||
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
Guid.Parse("00000000-0000-0000-0000-000000000003")
|
||||||
];
|
];
|
||||||
UpdateUserRoleAndPermissionsRequest request = new(
|
UpdateUserRoleAndPermissionsRequest request = _updateUserRoleAndPermissionsRequestFixture.Create(
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
Guid.NewGuid(),
|
Guid.NewGuid(),
|
||||||
permissions
|
permissions
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class CheckPathExistsRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingWithDifferentPathsAndHiddenElementsFlag_ShouldMapCorrectly(string path, bool shouldIncludeHiddenElements)
|
public void ToQuery_WhenMappingWithDifferentPathsAndHiddenElementsFlag_ShouldMapCorrectly(string path, bool shouldIncludeHiddenElements)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
CheckPathExistsRequest request = new(path, shouldIncludeHiddenElements);
|
CheckPathExistsRequest request = _checkPathExistsRequestFixture.Create(path, shouldIncludeHiddenElements);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
CheckPathExistsQuery result = request.ToQuery();
|
CheckPathExistsQuery result = request.ToQuery();
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class CombinePathRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string originalPath, string newPath)
|
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string originalPath, string newPath)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
CombinePathRequest request = new(originalPath, newPath);
|
CombinePathRequest request = _combinePathRequestFixture.Create(originalPath, newPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
CombinePathCommand result = request.ToCommand();
|
CombinePathCommand result = request.ToCommand();
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ public class GetPathParentRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetPathParentRequest request = new(path);
|
GetPathParentRequest request = _getPathParentRequestFixture.Create(path);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetPathParentQuery result = request.ToQuery();
|
GetPathParentQuery result = request.ToQuery();
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class GetPathRootRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetPathRootRequest request = new(path);
|
GetPathRootRequest request = _getPathRootRequestFixture.Create(path);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetPathRootQuery result = request.ToQuery();
|
GetPathRootQuery result = request.ToQuery();
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class SplitPathRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
public void ToCommand_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SplitPathRequest request = new(path);
|
SplitPathRequest request = _splitPathRequestFixture.Create(path);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
SplitPathCommand result = request.ToCommand();
|
SplitPathCommand result = request.ToCommand();
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ public class ValidatePathRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
public void ToQuery_WhenMappingWithDifferentPaths_ShouldMapCorrectly(string path)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
ValidatePathRequest request = new(path);
|
ValidatePathRequest request = _validatePathRequestFixture.Create(path);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ValidatePathQuery result = request.ToQuery();
|
ValidatePathQuery result = request.ToQuery();
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ public class GetThumbnailRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingWithDifferentPathsAndQualities_ShouldMapCorrectly(string path, int quality)
|
public void ToQuery_WhenMappingWithDifferentPathsAndQualities_ShouldMapCorrectly(string path, int quality)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThumbnailRequest request = new(path, quality);
|
GetThumbnailRequest request = _getThumbnailRequestFixture.Create(path, quality);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThumbnailQuery result = request.ToQuery();
|
GetThumbnailQuery result = request.ToQuery();
|
||||||
|
|||||||
+2
-2
@@ -53,7 +53,7 @@ public class ThumbnailMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
byte[] bytes = [.. _fixture.CreateMany<byte>(100)];
|
byte[] bytes = [.. _fixture.CreateMany<byte>(100)];
|
||||||
Thumbnail domainModel = new(imageType, bytes);
|
Thumbnail domainModel = _thumbnailFixture.Create(imageType, bytes);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ThumbnailResponse result = domainModel.ToResponse();
|
ThumbnailResponse result = domainModel.ToResponse();
|
||||||
@@ -70,7 +70,7 @@ public class ThumbnailMappingTests
|
|||||||
// Arrange
|
// Arrange
|
||||||
ImageType imageType = _fixture.Create<ImageType>();
|
ImageType imageType = _fixture.Create<ImageType>();
|
||||||
byte[] emptyBytes = [];
|
byte[] emptyBytes = [];
|
||||||
Thumbnail domainModel = new(imageType, emptyBytes);
|
Thumbnail domainModel = _thumbnailFixture.Create(imageType, emptyBytes);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ThumbnailResponse result = domainModel.ToResponse();
|
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.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||||
using Lumina.Contracts.DTO.MediaContributors;
|
using Lumina.Contracts.DTO.MediaContributors;
|
||||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
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.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Albums;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
@@ -29,6 +31,9 @@ public class AlbumEntityMappingTests
|
|||||||
private readonly GenreEntityFixture _genreEntityFixture = new();
|
private readonly GenreEntityFixture _genreEntityFixture = new();
|
||||||
private readonly TagEntityFixture _tagEntityFixture = new();
|
private readonly TagEntityFixture _tagEntityFixture = new();
|
||||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = new();
|
||||||
|
private readonly TrackIsrcEntityFixture _trackIsrcEntityFixture = new();
|
||||||
|
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||||
|
private readonly AudioRatingDtoFixture _audioRatingDtoFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToDomainEntity_WhenMappingValidAlbumEntity_ShouldMapAllPropertiesCorrectly()
|
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.OriginalLanguageCode!.ToLowerInvariant(), album.Metadata.OriginalLanguage.Value.LanguageCode);
|
||||||
Assert.Equal(entity.OriginalLanguageName, album.Metadata.OriginalLanguage.Value.LanguageName);
|
Assert.Equal(entity.OriginalLanguageName, album.Metadata.OriginalLanguage.Value.LanguageName);
|
||||||
Assert.Equal(entity.OriginalLanguageNativeName, album.Metadata.OriginalLanguage.Value.NativeName.Value);
|
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.ReleaseStatus, album.Metadata.ReleaseStatus.Value);
|
||||||
Assert.Equal(entity.TotalDiscs, album.Metadata.TotalDiscs.Value);
|
Assert.Equal(entity.TotalDiscs, album.Metadata.TotalDiscs.Value);
|
||||||
Assert.Equal(entity.TotalTracks, album.Metadata.TotalTracks);
|
Assert.Equal(entity.TotalTracks, album.Metadata.TotalTracks);
|
||||||
Assert.Equal(entity.MediaFormat, album.MediaFormat.Value);
|
Assert.Equal(entity.MediaFormat, album.MediaFormat.Value);
|
||||||
Assert.Equal(entity.Barcode, album.Barcode.Value.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.MusicBrainzReleaseId, album.MusicBrainzReleaseId.Value.Value);
|
||||||
Assert.Equal(entity.MusicBrainzReleaseGroupId, album.MusicBrainzReleaseGroupId.Value.Value);
|
Assert.Equal(entity.MusicBrainzReleaseGroupId, album.MusicBrainzReleaseGroupId.Value.Value);
|
||||||
Assert.Equal(entity.MusicBrainzReleaseArtistId, album.MusicBrainzReleaseArtistId.Value.Value);
|
Assert.Equal(entity.MusicBrainzReleaseArtistId, album.MusicBrainzReleaseArtistId.Value.Value);
|
||||||
@@ -102,7 +107,7 @@ public class AlbumEntityMappingTests
|
|||||||
includeReleaseStatus: false,
|
includeReleaseStatus: false,
|
||||||
includeTotalDiscs: false,
|
includeTotalDiscs: false,
|
||||||
includeMediaFormat: false,
|
includeMediaFormat: false,
|
||||||
includeCatalogNumber: false,
|
includeCatalogNumbers: false,
|
||||||
includeMusicBrainzReleaseId: false,
|
includeMusicBrainzReleaseId: false,
|
||||||
includeMusicBrainzReleaseGroupId: false,
|
includeMusicBrainzReleaseGroupId: false,
|
||||||
includeMusicBrainzReleaseArtistId: false);
|
includeMusicBrainzReleaseArtistId: false);
|
||||||
@@ -123,12 +128,12 @@ public class AlbumEntityMappingTests
|
|||||||
Assert.Empty(album.Metadata.Tags);
|
Assert.Empty(album.Metadata.Tags);
|
||||||
Assert.False(album.Metadata.Language.HasValue);
|
Assert.False(album.Metadata.Language.HasValue);
|
||||||
Assert.False(album.Metadata.OriginalLanguage.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.ReleaseStatus.HasValue);
|
||||||
Assert.False(album.Metadata.TotalDiscs.HasValue);
|
Assert.False(album.Metadata.TotalDiscs.HasValue);
|
||||||
Assert.False(album.MediaFormat.HasValue);
|
Assert.False(album.MediaFormat.HasValue);
|
||||||
Assert.False(album.Barcode.HasValue);
|
Assert.False(album.Barcode.HasValue);
|
||||||
Assert.False(album.CatalogNumber.HasValue);
|
Assert.Empty(album.CatalogNumbers);
|
||||||
Assert.False(album.MusicBrainzReleaseId.HasValue);
|
Assert.False(album.MusicBrainzReleaseId.HasValue);
|
||||||
Assert.False(album.MusicBrainzReleaseGroupId.HasValue);
|
Assert.False(album.MusicBrainzReleaseGroupId.HasValue);
|
||||||
Assert.False(album.MusicBrainzReleaseArtistId.HasValue);
|
Assert.False(album.MusicBrainzReleaseArtistId.HasValue);
|
||||||
@@ -231,7 +236,7 @@ public class AlbumEntityMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TrackEntity trackEntity = _trackEntityFixture.Create();
|
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]);
|
AlbumEntity entity = _albumEntityFixture.Create(tracks: [trackEntity]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
@@ -275,20 +280,20 @@ public class AlbumEntityMappingTests
|
|||||||
Assert.Equal(entity.OriginalLanguageNativeName, result.Metadata.OriginalLanguage.NativeName);
|
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.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.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.ReleaseStatus, result.Metadata.ReleaseStatus);
|
||||||
Assert.Equal(entity.TotalDiscs, result.Metadata.TotalDiscs);
|
Assert.Equal(entity.TotalDiscs, result.Metadata.TotalDiscs);
|
||||||
Assert.Equal(entity.TotalTracks, result.Metadata.TotalTracks);
|
Assert.Equal(entity.TotalTracks, result.Metadata.TotalTracks);
|
||||||
Assert.Equal(entity.MediaFormat, result.MediaFormat);
|
Assert.Equal(entity.MediaFormat, result.MediaFormat);
|
||||||
Assert.Equal(entity.Barcode, result.Barcode);
|
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.MusicBrainzReleaseId, result.MusicBrainzReleaseId);
|
||||||
Assert.Equal(entity.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
Assert.Equal(entity.MusicBrainzReleaseGroupId, result.MusicBrainzReleaseGroupId);
|
||||||
Assert.Equal(entity.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
Assert.Equal(entity.MusicBrainzReleaseArtistId, result.MusicBrainzReleaseArtistId);
|
||||||
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
|
Assert.Equal(entity.CreatedOnUtc, result.CreatedOnUtc);
|
||||||
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||||
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.Ratings.Select(rating => new AudioRatingDto(rating.Value, rating.MaxValue, rating.Source, rating.VoteCount)), result.Ratings);
|
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));
|
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.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||||
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
using Lumina.Application.Fixtures.Common.DTO.Pagination;
|
||||||
using Lumina.Contracts.DTO.MediaContributors;
|
using Lumina.Contracts.DTO.MediaContributors;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.DTO.MediaContributors;
|
||||||
using Lumina.Contracts.Responses.Common;
|
using Lumina.Contracts.Responses.Common;
|
||||||
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
using Lumina.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Artists;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
@@ -27,6 +28,7 @@ public class ArtistEntityMappingTests
|
|||||||
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
private readonly ArtistEntityFixture _artistEntityFixture = new();
|
||||||
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
private readonly AlbumEntityFixture _albumEntityFixture = new();
|
||||||
private readonly PaginatedResultDtoFixture<ArtistEntity> _paginatedResultDtoFixture = new();
|
private readonly PaginatedResultDtoFixture<ArtistEntity> _paginatedResultDtoFixture = new();
|
||||||
|
private readonly MediaContributorReferenceDtoFixture _mediaContributorReferenceDtoFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToDomainEntity_WhenMappingValidArtistEntity_ShouldMapAllPropertiesCorrectly()
|
public void ToDomainEntity_WhenMappingValidArtistEntity_ShouldMapAllPropertiesCorrectly()
|
||||||
@@ -111,10 +113,10 @@ public class ArtistEntityMappingTests
|
|||||||
Assert.NotNull(result);
|
Assert.NotNull(result);
|
||||||
Assert.Equal(entity.Id, result.Id);
|
Assert.Equal(entity.Id, result.Id);
|
||||||
Assert.Equal(entity.LibraryId, result.LibraryId);
|
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.Website, result.Website);
|
||||||
Assert.Equal(entity.MusicBrainzArtistId, result.MusicBrainzArtistId);
|
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.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.Id), result.Albums.Select(album => album.Id));
|
||||||
Assert.Equal(entity.Albums.Select(album => album.Title), result.Albums.Select(album => album.Metadata.Title));
|
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++)
|
for (int i = 0; i < entities.Count; i++)
|
||||||
{
|
{
|
||||||
Assert.Equal(entities[i].Id, results[i].Id);
|
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.Common;
|
||||||
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||||
using Lumina.Application.Common.Mapping.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
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.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.AudioLibrary.MusicLibrary;
|
||||||
using Lumina.Contracts.DTO.MediaContributors;
|
using Lumina.Contracts.DTO.MediaContributors;
|
||||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary;
|
||||||
using Lumina.Contracts.DTO.MediaLibrary.AudioLibrary.MusicLibrary;
|
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.Contracts.Responses.MediaLibrary.AudioLibrary.MusicLibrary.Tracks;
|
||||||
using Lumina.Domain.Common.Errors;
|
using Lumina.Domain.Common.Errors;
|
||||||
using Lumina.Domain.Common.Primitives;
|
using Lumina.Domain.Common.Primitives;
|
||||||
@@ -26,6 +29,12 @@ public class TrackEntityMappingTests
|
|||||||
{
|
{
|
||||||
private readonly TrackEntityFixture _trackEntityFixture = new();
|
private readonly TrackEntityFixture _trackEntityFixture = new();
|
||||||
private readonly AudioRatingEntityFixture _audioRatingEntityFixture = 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]
|
[Fact]
|
||||||
public void ToDomainEntity_WhenMappingValidTrackEntity_ShouldMapAllPropertiesCorrectly()
|
public void ToDomainEntity_WhenMappingValidTrackEntity_ShouldMapAllPropertiesCorrectly()
|
||||||
@@ -73,10 +82,10 @@ public class TrackEntityMappingTests
|
|||||||
Assert.Equal(entity.Script, track.Script.Value);
|
Assert.Equal(entity.Script, track.Script.Value);
|
||||||
Assert.Equal(entity.Key, track.Key.Value);
|
Assert.Equal(entity.Key, track.Key.Value);
|
||||||
Assert.Equal(entity.Bpm, track.Bpm.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.MusicBrainzRecordingId, track.MusicBrainzRecordingId.Value.Value);
|
||||||
Assert.Equal(entity.MusicBrainzTrackId, track.MusicBrainzTrackId.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.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.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));
|
Assert.Equal(entity.Ratings.Select(rating => rating.Value), track.Ratings.Select(rating => (decimal?)rating.Value));
|
||||||
@@ -107,7 +116,7 @@ public class TrackEntityMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TrackEntity entity = _trackEntityFixture.Create();
|
TrackEntity entity = _trackEntityFixture.Create();
|
||||||
entity.Genres = [new GenreEntity(string.Empty)];
|
entity.Genres = [_genreEntityFixture.Create(name: string.Empty)];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Track> result = entity.ToDomainEntity();
|
Result<Track> result = entity.ToDomainEntity();
|
||||||
@@ -122,7 +131,7 @@ public class TrackEntityMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TrackEntity entity = _trackEntityFixture.Create();
|
TrackEntity entity = _trackEntityFixture.Create();
|
||||||
entity.Tags = [new TagEntity(" ")];
|
entity.Tags = [_tagEntityFixture.Create(name: " ")];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Track> result = entity.ToDomainEntity();
|
Result<Track> result = entity.ToDomainEntity();
|
||||||
@@ -137,7 +146,7 @@ public class TrackEntityMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TrackEntity entity = _trackEntityFixture.Create();
|
TrackEntity entity = _trackEntityFixture.Create();
|
||||||
entity.Moods = [new TrackMoodEntity(string.Empty)];
|
entity.Moods = [_trackMoodEntityFixture.Create(name: string.Empty)];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Track> result = entity.ToDomainEntity();
|
Result<Track> result = entity.ToDomainEntity();
|
||||||
@@ -152,7 +161,7 @@ public class TrackEntityMappingTests
|
|||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
TrackEntity entity = _trackEntityFixture.Create();
|
TrackEntity entity = _trackEntityFixture.Create();
|
||||||
entity.Isrcs = [new TrackIsrcEntity("not-an-isrc")];
|
entity.Isrcs = [_trackIsrcEntityFixture.Create(value: "not-an-isrc")];
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Track> result = entity.ToDomainEntity();
|
Result<Track> result = entity.ToDomainEntity();
|
||||||
@@ -222,16 +231,16 @@ public class TrackEntityMappingTests
|
|||||||
Assert.Equal(entity.Script, result.Script);
|
Assert.Equal(entity.Script, result.Script);
|
||||||
Assert.Equal(entity.Key, result.Key);
|
Assert.Equal(entity.Key, result.Key);
|
||||||
Assert.Equal(entity.Bpm, result.Bpm);
|
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.MusicBrainzRecordingId, result.MusicBrainzRecordingId);
|
||||||
Assert.Equal(entity.MusicBrainzTrackId, result.MusicBrainzTrackId);
|
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.CreatedOnUtc, result.CreatedOnUtc);
|
||||||
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
Assert.Equal(entity.UpdatedOnUtc, result.UpdatedOnUtc);
|
||||||
Assert.Equal(entity.Moods.Select(mood => mood.Name), result.Moods!.Select(mood => mood.Name));
|
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.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.Contributors.Select(contributor => _mediaContributorReferenceDtoFixture.Create(contributorId: contributor.MediaContributorId, role: 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.Ratings.Select(rating => _audioRatingDtoFixture.Create(value: rating.Value, maxValue: rating.MaxValue, source: rating.Source, voteCount: rating.VoteCount)), result.Ratings);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
+8
-5
@@ -25,6 +25,9 @@ public class BookMetadataDtoMappingTests
|
|||||||
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
|
private readonly BookMetadataDtoFixture _bookMetadataDtoFixture = new();
|
||||||
private readonly GenreDtoFixture _genreDtoFixture = new();
|
private readonly GenreDtoFixture _genreDtoFixture = new();
|
||||||
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
private readonly ReleaseInfoDtoFixture _releaseInfoDtoFixture = new();
|
||||||
|
private readonly TagDtoFixture _tagDtoFixture = new();
|
||||||
|
private readonly IsbnDtoFixture _isbnDtoFixture = new();
|
||||||
|
private readonly BookRatingDtoFixture _bookRatingDtoFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItToTheBook()
|
public void ApplyMetadata_WhenCalledWithValidMetadata_ShouldApplyItToTheBook()
|
||||||
@@ -126,7 +129,7 @@ public class BookMetadataDtoMappingTests
|
|||||||
Book book = _bookFixture.Create();
|
Book book = _bookFixture.Create();
|
||||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||||
title: "A valid title",
|
title: "A valid title",
|
||||||
tags: [new TagDto(" ")]);
|
tags: [_tagDtoFixture.Create(name: " ")]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Success> result = book.ApplyMetadata(metadata);
|
Result<Success> result = book.ApplyMetadata(metadata);
|
||||||
@@ -142,7 +145,7 @@ public class BookMetadataDtoMappingTests
|
|||||||
Book book = _bookFixture.Create();
|
Book book = _bookFixture.Create();
|
||||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||||
title: "A valid title",
|
title: "A valid title",
|
||||||
isbns: [new IsbnDto("not-an-isbn", IsbnFormat.Isbn13)]);
|
isbns: [_isbnDtoFixture.Create(value: "not-an-isbn", format: IsbnFormat.Isbn13)]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Success> result = book.ApplyMetadata(metadata);
|
Result<Success> result = book.ApplyMetadata(metadata);
|
||||||
@@ -158,7 +161,7 @@ public class BookMetadataDtoMappingTests
|
|||||||
Book book = _bookFixture.Create();
|
Book book = _bookFixture.Create();
|
||||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||||
title: "A valid title",
|
title: "A valid title",
|
||||||
ratings: [new BookRatingDto(-1m, 5m, null, null)]);
|
ratings: [_bookRatingDtoFixture.Create(value: -1m, maxValue: 5m, includeSource: false, includeVoteCount: false)]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Success> result = book.ApplyMetadata(metadata);
|
Result<Success> result = book.ApplyMetadata(metadata);
|
||||||
@@ -196,8 +199,8 @@ public class BookMetadataDtoMappingTests
|
|||||||
Book book = _bookFixture.Create();
|
Book book = _bookFixture.Create();
|
||||||
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
BookMetadataDto metadata = _bookMetadataDtoFixture.Create(
|
||||||
title: "A valid title",
|
title: "A valid title",
|
||||||
isbns: [new IsbnDto("9780306406157", IsbnFormat.Isbn13)],
|
isbns: [_isbnDtoFixture.Create(value: "9780306406157", format: IsbnFormat.Isbn13)],
|
||||||
ratings: [new BookRatingDto(4m, 5m, null, 10)]);
|
ratings: [_bookRatingDtoFixture.Create(value: 4m, maxValue: 5m, voteCount: 10, includeSource: false)]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
Result<Success> result = book.ApplyMetadata(metadata);
|
Result<Success> result = book.ApplyMetadata(metadata);
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
using Lumina.Application.Core.Plugins.Queries.GetLibraryMetadataProviders;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetLibraryMetadataProvidersRequestMappingTests
|
public class GetLibraryMetadataProvidersRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetLibraryMetadataProvidersRequestFixture _getLibraryMetadataProvidersRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetLibraryMetadataProvidersRequest request = new(LibraryId: Guid.NewGuid());
|
GetLibraryMetadataProvidersRequest request = _getLibraryMetadataProvidersRequestFixture.Create(Guid.NewGuid());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetLibraryMetadataProvidersQuery result = request.ToQuery();
|
GetLibraryMetadataProvidersQuery result = request.ToQuery();
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
using Lumina.Application.Core.Plugins.Queries.GetPluginSettings;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class GetPluginSettingsRequestMappingTests
|
public class GetPluginSettingsRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly GetPluginSettingsRequestFixture _getPluginSettingsRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToQuery_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetPluginSettingsRequest request = new(PluginId: Guid.NewGuid());
|
GetPluginSettingsRequest request = _getPluginSettingsRequestFixture.Create(Guid.NewGuid());
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetPluginSettingsQuery result = request.ToQuery();
|
GetPluginSettingsQuery result = request.ToQuery();
|
||||||
|
|||||||
+6
-3
@@ -3,6 +3,7 @@ using Lumina.Application.Common.Mapping.Plugins;
|
|||||||
using Lumina.Contracts.Responses.Plugins;
|
using Lumina.Contracts.Responses.Plugins;
|
||||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||||
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
using Lumina.Plugins.Contracts.Common.Models.DTO.Settings;
|
||||||
|
using Lumina.Plugins.Contracts.Fixtures.Common.Models.DTO.Settings;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
#endregion
|
#endregion
|
||||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class PluginSettingDescriptorMappingTests
|
public class PluginSettingDescriptorMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly PluginSettingDescriptorDtoFixture _pluginSettingDescriptorDtoFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToResponse_WhenMappingValidDescriptor_ShouldMapCorrectly()
|
public void ToResponse_WhenMappingValidDescriptor_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
PluginSettingDescriptorDto descriptor = new("apiKey", "API Key", PluginSettingType.Text, "default", null);
|
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("apiKey", "API Key", PluginSettingType.Text, "default", null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||||
@@ -41,7 +44,7 @@ public class PluginSettingDescriptorMappingTests
|
|||||||
public void ToResponse_WhenMappingDifferentSettingTypes_ShouldMapTypeCorrectly(PluginSettingType type)
|
public void ToResponse_WhenMappingDifferentSettingTypes_ShouldMapTypeCorrectly(PluginSettingType type)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
PluginSettingDescriptorDto descriptor = new("key", "Label", type, null, null);
|
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("key", "Label", type, null, null);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||||
@@ -54,7 +57,7 @@ public class PluginSettingDescriptorMappingTests
|
|||||||
public void ToResponse_WhenMappingDescriptorWithAllowedValues_ShouldMapAllowedValues()
|
public void ToResponse_WhenMappingDescriptorWithAllowedValues_ShouldMapAllowedValues()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
PluginSettingDescriptorDto descriptor = new("mode", "Mode", PluginSettingType.Select, null, ["fast", "slow"]);
|
PluginSettingDescriptorDto descriptor = _pluginSettingDescriptorDtoFixture.Create("mode", "Mode", PluginSettingType.Select, null, ["fast", "slow"]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
PluginSettingDescriptorResponse result = descriptor.ToResponse();
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
using Lumina.Application.Core.Plugins.Commands.ReorderLibraryMetadataProviders;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class ReorderLibraryMetadataProvidersRequestMappingTests
|
public class ReorderLibraryMetadataProvidersRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly ReorderLibraryMetadataProvidersRequestFixture _reorderLibraryMetadataProvidersRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
ReorderLibraryMetadataProvidersRequest request = new(LibraryId: Guid.NewGuid(), PluginIds: [Guid.NewGuid(), Guid.NewGuid()]);
|
ReorderLibraryMetadataProvidersRequest request = _reorderLibraryMetadataProvidersRequestFixture.Create(Guid.NewGuid(), [Guid.NewGuid(), Guid.NewGuid()]);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
ReorderLibraryMetadataProvidersCommand result = request.ToCommand();
|
ReorderLibraryMetadataProvidersCommand result = request.ToCommand();
|
||||||
|
|||||||
+4
-1
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
using Lumina.Application.Core.Plugins.Commands.SetLibraryMetadataProviderEnabled;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
@@ -14,11 +15,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class SetLibraryMetadataProviderEnabledRequestMappingTests
|
public class SetLibraryMetadataProviderEnabledRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly SetLibraryMetadataProviderEnabledRequestFixture _setLibraryMetadataProviderEnabledRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
SetLibraryMetadataProviderEnabledRequest request = new(LibraryId: Guid.NewGuid(), PluginId: Guid.NewGuid(), IsEnabled: true);
|
SetLibraryMetadataProviderEnabledRequest request = _setLibraryMetadataProviderEnabledRequestFixture.Create(Guid.NewGuid(), Guid.NewGuid(), true);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
SetLibraryMetadataProviderEnabledCommand result = request.ToCommand();
|
SetLibraryMetadataProviderEnabledCommand result = request.ToCommand();
|
||||||
|
|||||||
+5
-2
@@ -1,6 +1,7 @@
|
|||||||
#region ========================================================================= USING =====================================================================================
|
#region ========================================================================= USING =====================================================================================
|
||||||
using Lumina.Application.Common.Mapping.Plugins;
|
using Lumina.Application.Common.Mapping.Plugins;
|
||||||
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
using Lumina.Application.Core.Plugins.Commands.UpdatePluginSettings;
|
||||||
|
using Lumina.Contracts.Fixtures.Core.Requests.Plugins;
|
||||||
using Lumina.Contracts.Requests.Plugins;
|
using Lumina.Contracts.Requests.Plugins;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -15,11 +16,13 @@ namespace Lumina.Application.UnitTests.Common.Mapping.Plugins;
|
|||||||
[ExcludeFromCodeCoverage]
|
[ExcludeFromCodeCoverage]
|
||||||
public class UpdatePluginSettingsRequestMappingTests
|
public class UpdatePluginSettingsRequestMappingTests
|
||||||
{
|
{
|
||||||
|
private readonly UpdatePluginSettingsRequestFixture _updatePluginSettingsRequestFixture = new();
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||||
{
|
{
|
||||||
// Arrange
|
// 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
|
// Act
|
||||||
UpdatePluginSettingsCommand result = request.ToCommand();
|
UpdatePluginSettingsCommand result = request.ToCommand();
|
||||||
@@ -34,7 +37,7 @@ public class UpdatePluginSettingsRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingRequestWithNullSettings_ShouldMapNullSettings()
|
public void ToCommand_WhenMappingRequestWithNullSettings_ShouldMapNullSettings()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
UpdatePluginSettingsRequest request = new(PluginId: Guid.NewGuid(), Settings: null);
|
UpdatePluginSettingsRequest request = _updatePluginSettingsRequestFixture.Create(Guid.NewGuid(), includeSettings: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
UpdatePluginSettingsCommand result = request.ToCommand();
|
UpdatePluginSettingsCommand result = request.ToCommand();
|
||||||
|
|||||||
+2
-2
@@ -39,7 +39,7 @@ public class DeleteThemeRequestMappingTests
|
|||||||
public void ToCommand_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
public void ToCommand_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
DeleteThemeRequest request = new(themeId);
|
DeleteThemeRequest request = _deleteThemeRequestFixture.Create(themeId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
DeleteThemeCommand result = request.ToCommand();
|
DeleteThemeCommand result = request.ToCommand();
|
||||||
@@ -53,7 +53,7 @@ public class DeleteThemeRequestMappingTests
|
|||||||
public void ToCommand_WhenThemeIdIsNull_ShouldMapNull()
|
public void ToCommand_WhenThemeIdIsNull_ShouldMapNull()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
DeleteThemeRequest request = new(null);
|
DeleteThemeRequest request = _deleteThemeRequestFixture.Create(includeThemeId: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
DeleteThemeCommand result = request.ToCommand();
|
DeleteThemeCommand result = request.ToCommand();
|
||||||
|
|||||||
+2
-2
@@ -39,7 +39,7 @@ public class GetThemeArchiveRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
public void ToQuery_WhenMappingDifferentThemeIds_ShouldMapCorrectly(string themeId)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeArchiveRequest request = new(themeId);
|
GetThemeArchiveRequest request = _getThemeArchiveRequestFixture.Create(themeId);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeArchiveQuery result = request.ToQuery();
|
GetThemeArchiveQuery result = request.ToQuery();
|
||||||
@@ -53,7 +53,7 @@ public class GetThemeArchiveRequestMappingTests
|
|||||||
public void ToQuery_WhenThemeIdIsNull_ShouldMapNull()
|
public void ToQuery_WhenThemeIdIsNull_ShouldMapNull()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeArchiveRequest request = new(null);
|
GetThemeArchiveRequest request = _getThemeArchiveRequestFixture.Create(includeThemeId: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeArchiveQuery result = request.ToQuery();
|
GetThemeArchiveQuery result = request.ToQuery();
|
||||||
|
|||||||
+2
-2
@@ -40,7 +40,7 @@ public class GetThemeAssetRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingDifferentThemeIdsAndAssetPaths_ShouldMapCorrectly(string themeId, string assetPath)
|
public void ToQuery_WhenMappingDifferentThemeIdsAndAssetPaths_ShouldMapCorrectly(string themeId, string assetPath)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeAssetRequest request = new(themeId, assetPath);
|
GetThemeAssetRequest request = _getThemeAssetRequestFixture.Create(themeId, assetPath);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeAssetQuery result = request.ToQuery();
|
GetThemeAssetQuery result = request.ToQuery();
|
||||||
@@ -55,7 +55,7 @@ public class GetThemeAssetRequestMappingTests
|
|||||||
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeAssetRequest request = new(null, null);
|
GetThemeAssetRequest request = _getThemeAssetRequestFixture.Create(includeThemeId: false, includeAssetPath: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeAssetQuery result = request.ToQuery();
|
GetThemeAssetQuery result = request.ToQuery();
|
||||||
|
|||||||
+2
-2
@@ -40,7 +40,7 @@ public class GetThemeTemplateRequestMappingTests
|
|||||||
public void ToQuery_WhenMappingDifferentThemeIdsAndPageKeys_ShouldMapCorrectly(string themeId, string pageKey)
|
public void ToQuery_WhenMappingDifferentThemeIdsAndPageKeys_ShouldMapCorrectly(string themeId, string pageKey)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeTemplateRequest request = new(themeId, pageKey);
|
GetThemeTemplateRequest request = _getThemeTemplateRequestFixture.Create(themeId, pageKey);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeTemplateQuery result = request.ToQuery();
|
GetThemeTemplateQuery result = request.ToQuery();
|
||||||
@@ -55,7 +55,7 @@ public class GetThemeTemplateRequestMappingTests
|
|||||||
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
public void ToQuery_WhenFieldsAreNull_ShouldMapNull()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
GetThemeTemplateRequest request = new(null, null);
|
GetThemeTemplateRequest request = _getThemeTemplateRequestFixture.Create(includeThemeId: false, includePageKey: false);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
GetThemeTemplateQuery result = request.ToQuery();
|
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