Merge pull request #147 from BinaryAlley/refactor/centralize-test-fixtures

Refactor/centralize test fixtures
This commit is contained in:
BinaryAlley authored and GitHub committed 2026-08-15 04:30:12 -07:00
commit 7f335b70f1
356 files changed
+4170 -5426

No files matched your search

+94 -1
View File
@@ -1,4 +1,4 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
@@ -210,6 +210,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Plugins.OpenLibrary"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lumina.Domain.SharedKernel", "Lumina.Domain.SharedKernel\Lumina.Domain.SharedKernel.csproj", "{9450EAC6-1F33-4BE1-89E3-0275885FE3EE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common", "Common", "{7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Domain.Fixtures", "..\tests\Common\Lumina.Domain.Fixtures\Lumina.Domain.Fixtures.csproj", "{E6449D94-C33A-41CE-9047-7298CF20C311}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Contracts.Fixtures", "..\tests\Common\Lumina.Contracts.Fixtures\Lumina.Contracts.Fixtures.csproj", "{45774AE5-23DB-424B-8E2A-B355ADEFB777}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Application.Fixtures", "..\tests\Common\Lumina.Application.Fixtures\Lumina.Application.Fixtures.csproj", "{BEF177F3-99E7-4649-86AB-B4235B9A95ED}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Infrastructure.Fixtures", "..\tests\Common\Lumina.Infrastructure.Fixtures\Lumina.Infrastructure.Fixtures.csproj", "{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Presentation.Api.Fixtures", "..\tests\Common\Lumina.Presentation.Api.Fixtures\Lumina.Presentation.Api.Fixtures.csproj", "{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lumina.Domain.SharedKernel.Fixtures", "..\tests\Common\Lumina.Domain.SharedKernel.Fixtures\Lumina.Domain.SharedKernel.Fixtures.csproj", "{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -432,6 +446,78 @@ Global
{9450EAC6-1F33-4BE1-89E3-0275885FE3EE}.Release|x64.Build.0 = Release|Any CPU
{9450EAC6-1F33-4BE1-89E3-0275885FE3EE}.Release|x86.ActiveCfg = Release|Any CPU
{9450EAC6-1F33-4BE1-89E3-0275885FE3EE}.Release|x86.Build.0 = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|x64.ActiveCfg = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|x64.Build.0 = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|x86.ActiveCfg = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Debug|x86.Build.0 = Debug|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|Any CPU.Build.0 = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|x64.ActiveCfg = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|x64.Build.0 = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|x86.ActiveCfg = Release|Any CPU
{E6449D94-C33A-41CE-9047-7298CF20C311}.Release|x86.Build.0 = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|x64.ActiveCfg = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|x64.Build.0 = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|x86.ActiveCfg = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Debug|x86.Build.0 = Debug|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|Any CPU.Build.0 = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|x64.ActiveCfg = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|x64.Build.0 = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|x86.ActiveCfg = Release|Any CPU
{45774AE5-23DB-424B-8E2A-B355ADEFB777}.Release|x86.Build.0 = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|x64.ActiveCfg = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|x64.Build.0 = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|x86.ActiveCfg = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Debug|x86.Build.0 = Debug|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|Any CPU.Build.0 = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|x64.ActiveCfg = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|x64.Build.0 = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|x86.ActiveCfg = Release|Any CPU
{BEF177F3-99E7-4649-86AB-B4235B9A95ED}.Release|x86.Build.0 = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|x64.ActiveCfg = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|x64.Build.0 = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|x86.ActiveCfg = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Debug|x86.Build.0 = Debug|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|Any CPU.Build.0 = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|x64.ActiveCfg = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|x64.Build.0 = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|x86.ActiveCfg = Release|Any CPU
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B}.Release|x86.Build.0 = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|x64.Build.0 = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|x86.ActiveCfg = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Debug|x86.Build.0 = Debug|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|Any CPU.Build.0 = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|x64.ActiveCfg = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|x64.Build.0 = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|x86.ActiveCfg = Release|Any CPU
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91}.Release|x86.Build.0 = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|x64.ActiveCfg = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|x64.Build.0 = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|x86.ActiveCfg = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Debug|x86.Build.0 = Debug|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|Any CPU.Build.0 = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|x64.ActiveCfg = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|x64.Build.0 = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|x86.ActiveCfg = Release|Any CPU
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -478,6 +564,13 @@ Global
{8CF6FEA4-624C-4EC9-93D6-EB7626059D7C} = {3C316ABB-08D5-4450-9A4E-91059DB54254}
{EADCD78B-04D5-4FE3-855C-E3015531EC8E} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
{9450EAC6-1F33-4BE1-89E3-0275885FE3EE} = {3C316ABB-08D5-4450-9A4E-91059DB54254}
{7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B} = {16E590D3-DD9F-4B45-BF19-C6E317A57D11}
{E6449D94-C33A-41CE-9047-7298CF20C311} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{45774AE5-23DB-424B-8E2A-B355ADEFB777} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{BEF177F3-99E7-4649-86AB-B4235B9A95ED} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{7C2AB7E7-F58B-4F96-BDFB-05E403BD999B} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{4E7353D5-5F1C-43A1-B792-6CD1D5DBDB91} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
{A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61} = {7E8A2D6B-3F4C-4E5F-9A6B-1C2D3E4F5A6B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4A55A28E-C657-4A0B-95EA-2931AE66004E}
@@ -1,13 +1,14 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="PermissionEntity"/> class.
@@ -15,26 +16,17 @@ namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
[ExcludeFromCodeCoverage]
public class PermissionEntityFixture
{
private readonly Fixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="PermissionEntityFixture"/> class.
/// </summary>
public PermissionEntityFixture()
{
_fixture = new Fixture();
ConfigureCustomTypes();
}
/// <summary>
/// Creates a random valid <see cref="PermissionEntity"/>.
/// </summary>
/// <param name="id">Optional. The permission Id.</param>
/// <param name="permissionName">Optional. The permission name.</param>
/// <returns>The created <see cref="PermissionEntity"/>.</returns>
public PermissionEntity CreatePermissionModel()
public PermissionEntity Create(Guid? id = null, AuthorizationPermission? permissionName = null)
{
return new Faker<PermissionEntity>()
.RuleFor(x => x.Id, f => f.Random.Guid())
.RuleFor(x => x.PermissionName, f => f.PickRandom<AuthorizationPermission>())
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
.RuleFor(x => x.PermissionName, f => permissionName ?? f.PickRandom<AuthorizationPermission>())
.RuleFor(x => x.RolePermissions, [])
.RuleFor(x => x.UserPermissions, [])
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
@@ -45,18 +37,12 @@ public class PermissionEntityFixture
}
/// <summary>
/// Configures custom type generation rules for the AutoFixture instance.
/// Creates a list of <see cref="PermissionEntity"/> instances with randomized test data.
/// </summary>
private void ConfigureCustomTypes()
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PermissionEntity"/> instances.</returns>
public List<PermissionEntity> CreateMany(int count = 3)
{
_fixture.Register(() => new PermissionEntity
{
Id = _fixture.Create<Guid>(),
PermissionName = _fixture.Create<AuthorizationPermission>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>(),
UpdatedOnUtc = _fixture.Create<DateTime>(),
UpdatedBy = _fixture.Create<Guid>()
});
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="RolePermissionEntity"/> class.
@@ -15,24 +15,13 @@ namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
[ExcludeFromCodeCoverage]
public class RolePermissionEntityFixture
{
private readonly Fixture _fixture;
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="RolePermissionEntityFixture"/> class.
/// </summary>
public RolePermissionEntityFixture()
{
_fixture = new Fixture();
_faker = new Faker();
ConfigureCustomTypes();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="RolePermissionEntity"/>.
/// </summary>
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
public RolePermissionEntity CreateRolePermissionModel()
public RolePermissionEntity Create()
{
PermissionEntity permission = new()
{
@@ -71,41 +60,13 @@ public class RolePermissionEntityFixture
}
/// <summary>
/// Configures custom type generation rules for the AutoFixture instance.
/// Creates a list of <see cref="RolePermissionEntity"/> instances with randomized test data.
/// </summary>
private void ConfigureCustomTypes()
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="RolePermissionEntity"/> instances.</returns>
public List<RolePermissionEntity> CreateMany(int count = 3)
{
_fixture.Register(() => new PermissionEntity
{
Id = _fixture.Create<Guid>(),
PermissionName = _fixture.Create<AuthorizationPermission>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>(),
UpdatedOnUtc = _fixture.Create<DateTime>(),
UpdatedBy = _fixture.Create<Guid>()
});
_fixture.Register(() => new RoleEntity
{
Id = _fixture.Create<Guid>(),
RoleName = _fixture.Create<string>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>(),
UpdatedOnUtc = _fixture.Create<DateTime>(),
UpdatedBy = _fixture.Create<Guid>()
});
_fixture.Register(() => new RolePermissionEntity
{
Id = _fixture.Create<Guid>(),
RoleId = _fixture.Create<Guid>(),
Role = _fixture.Create<RoleEntity>(),
PermissionId = _fixture.Create<Guid>(),
Permission = _fixture.Create<PermissionEntity>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>(),
UpdatedOnUtc = _fixture.Create<DateTime>(),
UpdatedBy = _fixture.Create<Guid>()
});
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,42 +1,27 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetAuthorization.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="GetAuthorizationQuery"/> class.
/// Fixture class for the <see cref="UserAuthorizationEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAuthorizationQueryFixture
public class UserAuthorizationEntityFixture
{
/// <summary>
/// Creates a random valid query to get authorization details.
/// </summary>
/// <param name="userId">Optional user Id to use. If null, a random GUID will be generated.</param>
/// <returns>The created query.</returns>
public static GetAuthorizationQuery CreateGetAuthorizationQuery(Guid? userId = null)
{
return new Faker<GetAuthorizationQuery>()
.CustomInstantiator(f => new GetAuthorizationQuery(
userId ?? f.Random.Guid()
))
.Generate();
}
/// <summary>
/// Creates a random valid authorization entity.
/// </summary>
/// <param name="userId">Optional user Id to use. If null, a random GUID will be generated.</param>
/// <param name="userId">Optional. The user Id to use. If null, a random GUID will be generated.</param>
/// <param name="isAdmin">Whether the user should have admin role.</param>
/// <returns>The created entity.</returns>
public static UserAuthorizationEntity CreateUserAuthorizationEntity(Guid? userId = null, bool isAdmin = false)
public UserAuthorizationEntity Create(Guid? userId = null, bool isAdmin = false)
{
string role = isAdmin ? "Admin" : string.Empty;
@@ -51,4 +36,15 @@ public class GetAuthorizationQueryFixture
}
};
}
/// <summary>
/// Creates a list of <see cref="UserAuthorizationEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <param name="isAdmin">Whether the users should have admin role.</param>
/// <returns>List of configured <see cref="UserAuthorizationEntity"/> instances.</returns>
public List<UserAuthorizationEntity> CreateMany(int count = 3, bool isAdmin = false)
{
return [.. Enumerable.Range(0, count).Select(_ => Create(isAdmin: isAdmin))];
}
}
@@ -1,13 +1,11 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="UserPermissionEntity"/> class.
@@ -15,24 +13,13 @@ namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
[ExcludeFromCodeCoverage]
public class UserPermissionEntityFixture
{
private readonly Fixture _fixture;
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="UserPermissionEntityFixture"/> class.
/// </summary>
public UserPermissionEntityFixture()
{
_fixture = new Fixture();
_faker = new Faker();
ConfigureCustomTypes();
}
/// <summary>
/// Creates a random valid <see cref="UserPermissionEntity"/>.
/// </summary>
/// <param name="user">The user the permission is granted to.</param>
/// <param name="permission">The permission granted to the user.</param>
/// <returns>The created <see cref="UserPermissionEntity"/>.</returns>
public UserPermissionEntity CreateUserPermissionModel(UserEntity user, PermissionEntity permission)
public UserPermissionEntity Create(UserEntity user, PermissionEntity permission)
{
return new Faker<UserPermissionEntity>()
.CustomInstantiator(f => new UserPermissionEntity
@@ -50,22 +37,4 @@ public class UserPermissionEntityFixture
.Generate();
}
/// <summary>
/// Configures custom type generation rules for the AutoFixture instance.
/// </summary>
private void ConfigureCustomTypes()
{
_fixture.Register(() => new UserPermissionEntity
{
Id = _fixture.Create<Guid>(),
UserId = _fixture.Create<Guid>(),
User = _fixture.Create<UserEntity>(),
PermissionId = _fixture.Create<Guid>(),
Permission = _fixture.Create<PermissionEntity>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>(),
UpdatedOnUtc = _fixture.Create<DateTime>(),
UpdatedBy = _fixture.Create<Guid>()
});
}
}
@@ -1,14 +1,12 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="UserRoleEntity"/> class.
@@ -16,22 +14,11 @@ namespace Lumina.DataAccess.UnitTests.Core.Repositories.Authorization.Fixtures;
[ExcludeFromCodeCoverage]
public class UserRoleEntityFixture
{
private readonly Fixture _fixture;
/// <summary>
/// Initializes a new instance of the <see cref="UserRoleEntityFixture"/> class.
/// </summary>
public UserRoleEntityFixture()
{
_fixture = new Fixture();
ConfigureCustomTypes();
}
/// <summary>
/// Creates a random valid <see cref="UserRoleEntity"/>.
/// </summary>
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
public UserRoleEntity CreateUserRoleModel()
public UserRoleEntity Create()
{
return new Faker<UserRoleEntity>()
.CustomInstantiator(f => new UserRoleEntity
@@ -64,28 +51,13 @@ public class UserRoleEntityFixture
}
/// <summary>
/// Configures custom type generation rules for the AutoFixture instance.
/// Creates a list of <see cref="UserRoleEntity"/> instances with randomized test data.
/// </summary>
private void ConfigureCustomTypes()
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UserRoleEntity"/> instances.</returns>
public List<UserRoleEntity> CreateMany(int count = 3)
{
_fixture.Register(() => new UserEntity
{
Id = _fixture.Create<Guid>(),
Username = _fixture.Create<string>(),
Password = _fixture.Create<string>(),
Libraries = [],
UserRole = null,
UserPermissions = [],
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>()
});
_fixture.Register(() => new RoleEntity
{
Id = _fixture.Create<Guid>(),
RoleName = _fixture.Create<string>(),
CreatedOnUtc = _fixture.Create<DateTime>(),
CreatedBy = _fixture.Create<Guid>()
});
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,19 +1,15 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.DataAccess.UnitTests.Common.Setup;
using Lumina.Application.Fixtures.Common.Setup;using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookEntity"/> class.
@@ -21,27 +17,14 @@ namespace Lumina.DataAccess.UnitTests.Core.Repositories.Books.Fixtures;
[ExcludeFromCodeCoverage]
public class BookEntityFixture
{
private readonly Fixture _fixture;
private readonly Random _random = new();
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="BookEntityFixture"/> class.
/// </summary>
public BookEntityFixture()
{
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_faker = new Faker();
ConfigureCustomTypes();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="BookEntity"/>.
/// </summary>
/// <returns>The created <see cref="BookEntity"/>.</returns>
public BookEntity CreateBookModel()
public BookEntity Create()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -65,8 +48,8 @@ public class BookEntityFixture
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.Tags, f => new HashSet<TagEntity>(CreateTags(f.Random.Number(1, 5))))
.RuleFor(x => x.Genres, f => new HashSet<GenreEntity>(CreateGenres(f.Random.Number(1, 5))))
.RuleFor(x => x.Tags, f => [.. CreateTags(f.Random.Number(1, 5))])
.RuleFor(x => x.Genres, f => [.. CreateGenres(f.Random.Number(1, 5))])
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
.RuleFor(x => x.PageCount, _random.Next(100, 300))
.RuleFor(x => x.Format, f => f.PickRandom<BookFormat>())
@@ -88,6 +71,16 @@ public class BookEntityFixture
.Generate();
}
/// <summary>
/// Creates a list of <see cref="BookEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookEntity"/> instances.</returns>
public List<BookEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
/// Creates a list of tag entities with random data.
/// </summary>
@@ -119,9 +112,7 @@ public class BookEntityFixture
/// <returns>A properly formatted LCCN string.</returns>
private string CreateLCCN(Faker f)
{
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
.Select(_ => f.Random.Char('a', 'z'))
.ToArray());
string letters = new([.. Enumerable.Range(0, f.Random.Number(0, 3)).Select(_ => f.Random.Char('a', 'z'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
}
@@ -155,7 +146,7 @@ public class BookEntityFixture
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
}
@@ -167,9 +158,7 @@ public class BookEntityFixture
private string CreateGoogleBooksId(Faker f)
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string(Enumerable.Repeat(VALID_CHARS, 12)
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
.ToArray());
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
}
/// <summary>
@@ -180,7 +169,11 @@ public class BookEntityFixture
private static List<IsbnEntity> CreateIsbns(int count)
{
return new Faker<IsbnEntity>()
.CustomInstantiator(f => new IsbnEntity(CreateIsbn(f), f.PickRandom<IsbnFormat>()))
.CustomInstantiator(f =>
{
string isbnValue = CreateIsbn(f);
return new IsbnEntity(isbnValue, isbnValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
})
.Generate(count);
}
@@ -219,7 +212,7 @@ public class BookEntityFixture
}
}
// <summary>
/// <summary>
/// Creates a list of book rating entities with random data.
/// </summary>
/// <param name="count">The number of ratings to create.</param>
@@ -236,19 +229,4 @@ public class BookEntityFixture
.Generate(count);
}
/// <summary>
/// Configures custom type generation rules for the AutoFixture instance.
/// </summary>
private void ConfigureCustomTypes()
{
_fixture.Register(() => new TagEntity(_fixture.Create<string>()));
_fixture.Register(() => new GenreEntity(_fixture.Create<string>()));
_fixture.Register(() => new IsbnEntity(_fixture.Create<string>(), _fixture.Create<IsbnFormat>()));
_fixture.Register(() => new BookRatingEntity(
_fixture.Create<decimal>(),
_fixture.Create<decimal>(),
_fixture.Create<BookRatingSource>(),
_fixture.Create<int>()
));
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookRatingEntity"/>.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingEntityFixture
{
private readonly Random _random = new();
private readonly Faker _faker = new();
/// <summary>
/// Creates a <see cref="BookRatingEntity"/>.
/// </summary>
/// <param name="value">Optional. The rating value.</param>
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
/// <param name="source">Optional. The rating source.</param>
/// <param name="voteCount">Optional. The number of votes.</param>
/// <param name="includeValues">Whether the rating properties should be populated. Set to <see langword="false"/> to create an invalid entity.</param>
/// <returns>The created book rating entity.</returns>
public BookRatingEntity Create(
decimal? value = null,
decimal? maxValue = null,
BookRatingSource? source = null,
int? voteCount = null,
bool includeValues = true)
{
return new BookRatingEntity(
includeValues ? (value ?? _random.Next(1, 5)) : null,
includeValues ? (maxValue ?? 5) : null,
includeValues ? (source ?? _faker.PickRandom<BookRatingSource>()) : null,
includeValues ? (voteCount ?? _random.Next(1, 1000)) : null
);
}
/// <summary>
/// Creates a list of <see cref="BookRatingEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookRatingEntity"/> instances.</returns>
public List<BookRatingEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
/// <summary>
/// Fixture class for the <see cref="LibraryMetadataProviderConfigurationEntity"/> class.
@@ -20,7 +22,7 @@ public class LibraryMetadataProviderConfigurationEntityFixture
/// <param name="pluginId">The Id of the plugin providing the metadata.</param>
/// <param name="rank">The rank of the metadata provider, determining the order in which providers are tried.</param>
/// <returns>The created <see cref="LibraryMetadataProviderConfigurationEntity"/>.</returns>
public LibraryMetadataProviderConfigurationEntity CreateConfiguration(Guid libraryId, Guid pluginId, int rank)
public LibraryMetadataProviderConfigurationEntity Create(Guid libraryId, Guid pluginId, int rank)
{
return new Faker<LibraryMetadataProviderConfigurationEntity>()
.RuleFor(configuration => configuration.Id, faker => faker.Random.Guid())
@@ -34,4 +36,17 @@ public class LibraryMetadataProviderConfigurationEntityFixture
.RuleFor(configuration => configuration.UpdatedBy, faker => faker.Random.Guid())
.Generate();
}
/// <summary>
/// Creates a list of <see cref="LibraryMetadataProviderConfigurationEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <param name="libraryId">The Id of the media library the configurations belong to.</param>
/// <param name="pluginId">The Id of the plugin providing the metadata.</param>
/// <param name="rank">The rank of the metadata providers.</param>
/// <returns>List of configured <see cref="LibraryMetadataProviderConfigurationEntity"/> instances.</returns>
public List<LibraryMetadataProviderConfigurationEntity> CreateMany(int count, Guid libraryId, Guid pluginId, int rank)
{
return [.. Enumerable.Range(0, count).Select(_ => Create(libraryId, pluginId, rank))];
}
}
@@ -5,10 +5,11 @@ using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.Json;
#endregion
namespace Lumina.DataAccess.UnitTests.Core.Repositories.Plugins.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
/// <summary>
/// Fixture class for the <see cref="PluginEntity"/> class.
@@ -21,7 +22,7 @@ public class PluginEntityFixture
/// </summary>
/// <param name="id">The Id of the plugin, or <see langword="null"/> to generate a random one.</param>
/// <returns>The created <see cref="PluginEntity"/>.</returns>
public PluginEntity CreatePluginEntity(Guid? id = null)
public PluginEntity Create(Guid? id = null)
{
return new Faker<PluginEntity>()
.RuleFor(plugin => plugin.Id, faker => id ?? faker.Random.Guid())
@@ -37,4 +38,14 @@ public class PluginEntityFixture
.RuleFor(plugin => plugin.UpdatedBy, faker => faker.Random.Guid())
.Generate();
}
/// <summary>
/// Creates a list of <see cref="PluginEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="PluginEntity"/> instances.</returns>
public List<PluginEntity> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -9,7 +9,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures;
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
/// <summary>
/// Fixture class for the <see cref="UserEntity"/> class.
@@ -18,27 +18,16 @@ namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtu
public class UserEntityFixture
{
/// <summary>
/// Creates a random valid user entity.
/// Creates a random valid <see cref="UserEntity"/>.
/// </summary>
/// <param name="libraryCount">Number of libraries to generate. Default is 0.</param>
/// <returns>The created user entity.</returns>
public static UserEntity CreateUserEntity(int libraryCount = 0)
public UserEntity Create(int libraryCount = 0)
{
Guid userId = Guid.NewGuid();
List<LibraryEntity> libraries = [.. new Faker<LibraryEntity>()
.CustomInstantiator(f => new LibraryEntity
{
Id = Guid.NewGuid(),
UserId = userId,
Title = f.Commerce.ProductName(),
LibraryType = f.PickRandom<LibraryType>(),
ContentLocations = [],
CreatedOnUtc = f.Date.Past(),
CreatedBy = userId,
UpdatedOnUtc = null,
UpdatedBy = null
})
.Generate(libraryCount)];
List<LibraryEntity> libraries = libraryCount > 0
? CreateLibraries(libraryCount, userId)
: [];
return new Faker<UserEntity>()
.CustomInstantiator(f => new UserEntity
@@ -61,14 +50,37 @@ public class UserEntityFixture
}
/// <summary>
/// Creates a list of user entities.
/// Creates a list of <see cref="UserEntity"/> instances with randomized test data.
/// </summary>
/// <param name="count">The number of entities to create.</param>
/// <returns>The created list.</returns>
public static List<UserEntity> CreateMany(int count = 3)
/// <param name="count">Number of instances to create.</param>
/// <param name="libraryCount">Number of libraries to generate for each user.</param>
/// <returns>List of configured <see cref="UserEntity"/> instances.</returns>
public List<UserEntity> CreateMany(int count = 3, int libraryCount = 0)
{
return Enumerable.Range(0, count)
.Select(_ => CreateUserEntity())
.ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create(libraryCount))];
}
/// <summary>
/// Creates a valid collection of user libraries.
/// </summary>
/// <param name="count">The number of user libraries to create.</param>
/// <param name="userId">The unique identifier of the user for whom to create the libraries.</param>
/// <returns>A collection of <see cref="LibraryEntity"/>.</returns>
private static List<LibraryEntity> CreateLibraries(int count, Guid userId)
{
return new Faker<LibraryEntity>()
.CustomInstantiator(f => new LibraryEntity
{
Id = Guid.NewGuid(),
UserId = userId,
Title = f.Commerce.ProductName(),
LibraryType = f.PickRandom<LibraryType>(),
ContentLocations = [],
CreatedOnUtc = f.Date.Past(),
CreatedBy = userId,
UpdatedOnUtc = null,
UpdatedBy = null
})
.Generate(count);
}
}
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Bogus;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.DataAccess.UnitTests.Common.Setup;
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Contains extension methods for the <see cref="Faker"/> class.
@@ -16,7 +16,7 @@ public static class BogusExtensions
/// Adds <see cref="DateOnly"/> random data generation support to the <see cref="Faker"/> class.
/// </summary>
/// <param name="faker">The faker instance to extend.</param>
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
/// <returns>A random <see cref="DateOnly"/> instance.</returns>
public static DateOnly DateOnly(this Faker faker)
{
return System.DateOnly.FromDateTime(faker.Date.Past());
@@ -28,11 +28,11 @@ public static class BogusExtensions
/// <param name="faker">The faker instance to extend.</param>
/// <param name="start">The start of the interval.</param>
/// <param name="end">The end of the interval.</param>
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
/// <returns>A random <see cref="DateOnly"/> instance.</returns>
public static DateOnly DateOnlyBetween(this Faker faker, DateOnly start, DateOnly end)
{
DateTime startDateTime = start.ToDateTime(TimeOnly.MinValue);
DateTime endDateTime = end.ToDateTime(TimeOnly.MinValue);
return System.DateOnly.FromDateTime(faker.Date.Between(startDateTime, endDateTime));
}
}
}
@@ -4,7 +4,7 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.DataAccess.UnitTests.Common.Setup;
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
@@ -4,10 +4,10 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Setup;
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
/// Represents a specimen builder for the <see cref="DateOnly?"/> type.
/// </summary>
[ExcludeFromCodeCoverage]
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.AddRole;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.AddRole;
/// <summary>
/// Fixture class for the <see cref="AddRoleCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddRoleCommandFixture
{
/// <summary>
/// Creates a random valid command to add a role.
/// </summary>
/// <param name="roleName">Optional. The role name.</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>
/// <returns>The created command to add a role.</returns>
public AddRoleCommand Create(
string? roleName = null,
IEnumerable<Guid>? permissions = null,
int permissionCount = 3)
{
Faker<AddRoleCommand> faker = new Faker<AddRoleCommand>()
.CustomInstantiator(f => new AddRoleCommand(
default!,
default!))
.RuleFor(x => x.RoleName, f => roleName ?? f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.Permissions, f => [.. permissions ?? Enumerable.Range(0, permissionCount).Select(_ => Guid.NewGuid())]);
return faker.Generate();
}
/// <summary>
/// Creates a list of <see cref="AddRoleCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<AddRoleCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Bogus;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.DeleteRole;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Commands.DeleteRole.Fixtures;
namespace Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.DeleteRole;
/// <summary>
/// Fixture class for the <see cref="DeleteRoleCommand"/> class.
@@ -16,12 +18,23 @@ public class DeleteRoleCommandFixture
/// <summary>
/// Creates a random valid command to delete a role.
/// </summary>
/// <param name="roleId">Optional. The role Id.</param>
/// <returns>The created command.</returns>
public DeleteRoleCommand CreateCommand()
public DeleteRoleCommand Create(Guid? roleId = null)
{
return new Faker<DeleteRoleCommand>()
.CustomInstantiator(f => new DeleteRoleCommand(
Guid.NewGuid()))
roleId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="DeleteRoleCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<DeleteRoleCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Admin.Authorization.Roles.Commands.UpdateRole;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Commands.UpdateRole;
/// <summary>
/// Fixture class for the <see cref="UpdateRoleCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateRoleCommandFixture
{
/// <summary>
/// Creates a random valid command to update a role.
/// </summary>
/// <param name="roleId">Optional. The role Id.</param>
/// <param name="roleName">Optional. The role name.</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>
/// <returns>The created command to update a role.</returns>
public UpdateRoleCommand Create(
Guid? roleId = null,
string? roleName = null,
IEnumerable<Guid>? permissions = null,
int permissionCount = 3)
{
return new Faker<UpdateRoleCommand>()
.CustomInstantiator(f => new UpdateRoleCommand(
default,
default!,
default!))
.RuleFor(x => x.RoleId, f => roleId ?? Guid.NewGuid())
.RuleFor(x => x.RoleName, f => roleName ?? f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.Permissions, f => [.. permissions ?? Enumerable.Range(0, permissionCount).Select(_ => Guid.NewGuid())])
.Generate();
}
/// <summary>
/// Creates a list of <see cref="UpdateRoleCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UpdateRoleCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Bogus;
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Queries.GetRolePermissions.Fixtures;
namespace Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
/// <summary>
/// Fixture class for the <see cref="GetRolePermissionsQuery"/> class.
@@ -16,12 +18,23 @@ public class GetRolePermissionsQueryFixture
/// <summary>
/// Creates a random valid query to get role permissions.
/// </summary>
/// <param name="roleId">Optional. The role Id.</param>
/// <returns>The created query.</returns>
public GetRolePermissionsQuery CreateQuery()
public GetRolePermissionsQuery Create(Guid? roleId = null)
{
return new Faker<GetRolePermissionsQuery>()
.CustomInstantiator(f => new GetRolePermissionsQuery(
Guid.NewGuid()))
roleId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetRolePermissionsQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetRolePermissionsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.Admin.Authorization.Roles.Queries.GetRoles;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.Admin.Authorization.Roles.Queries.GetRoles.Fixtures;
namespace Lumina.Application.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRoles;
/// <summary>
/// Fixture class for the <see cref="GetRolesQuery"/> class.
@@ -15,8 +17,18 @@ public class GetRolesQueryFixture
/// Creates a random valid query to get roles.
/// </summary>
/// <returns>The created query.</returns>
public GetRolesQuery CreateQuery()
public GetRolesQuery Create()
{
return new GetRolesQuery();
}
/// <summary>
/// Creates a list of <see cref="GetRolesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetRolesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Directories.Queries.GetDirectories;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Queries.GetDirectories.Fixtures;
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Directories.Queries.GetDirectories;
/// <summary>
/// Fixture class for the <see cref="GetDirectoriesQuery"/> class.
@@ -15,16 +17,27 @@ public class GetDirectoriesQueryFixture
/// <summary>
/// Creates a random valid query to get directories.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get directories.</returns>
public static GetDirectoriesQuery CreateGetDirectoriesQuery(bool includeHiddenElements = false)
public GetDirectoriesQuery Create(string? path = null, bool includeHiddenElements = false)
{
return new Faker<GetDirectoriesQuery>()
.CustomInstantiator(f => new GetDirectoriesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.DirectoryPath())
.RuleFor(x => x.Path, f => path ?? f.System.DirectoryPath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
/// <summary>
/// Creates a list of <see cref="GetDirectoriesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetDirectoriesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.Drives.Queries.GetDrives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Drives.Queries.GetDrives;
/// <summary>
/// Fixture class for the <see cref="GetDrivesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetDrivesQueryFixture
{
/// <summary>
/// Creates a random valid query to get drives.
/// </summary>
/// <returns>The created query.</returns>
public GetDrivesQuery Create()
{
return new GetDrivesQuery();
}
/// <summary>
/// Creates a list of <see cref="GetDrivesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetDrivesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,34 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.FileSystem.Queries.GetFileSystem;
/// <summary>
/// Fixture class for the <see cref="GetFileSystemQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetFileSystemQueryFixture
{
/// <summary>
/// Creates a random valid query to get the file system.
/// </summary>
/// <returns>The created query.</returns>
public GetFileSystemQuery Create()
{
return new GetFileSystemQuery();
}
/// <summary>
/// Creates a list of <see cref="GetFileSystemQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetFileSystemQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetFiles;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetFiles.Fixtures;
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetFiles;
/// <summary>
/// Fixture class for the <see cref="GetFilesQuery"/> class.
@@ -15,16 +17,27 @@ public class GetFilesQueryFixture
/// <summary>
/// Creates a random valid query to get files.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get files.</returns>
public static GetFilesQuery CreateGetFilesQuery(bool includeHiddenElements = false)
public GetFilesQuery Create(string? path = null, bool includeHiddenElements = false)
{
return new Faker<GetFilesQuery>()
.CustomInstantiator(f => new GetFilesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
/// <summary>
/// Creates a list of <see cref="GetFilesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetFilesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.GetTreeFiles.Fixtures;
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
/// <summary>
/// Fixture class for the <see cref="GetTreeFilesQuery"/> class.
@@ -13,18 +15,29 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.G
public class GetTreeFilesQueryFixture
{
/// <summary>
/// Creates a random valid query to get files.
/// Creates a random valid query to get tree files.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query to get files.</returns>
public static GetTreeFilesQuery CreateGetFilesQuery(bool includeHiddenElements = false)
/// <returns>The created query to get tree files.</returns>
public GetTreeFilesQuery Create(string? path = null, bool includeHiddenElements = false)
{
return new Faker<GetTreeFilesQuery>()
.CustomInstantiator(f => new GetTreeFilesQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, f => includeHiddenElements);
}
/// <summary>
/// Creates a list of <see cref="GetTreeFilesQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetTreeFilesQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.CombinePath;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.CombinePath;
/// <summary>
/// Fixture class for the <see cref="CombinePathCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class CombinePathCommandFixture
{
/// <summary>
/// Creates a random valid command to combine paths.
/// </summary>
/// <param name="originalPath">Optional. The original path.</param>
/// <param name="newPath">Optional. The new path to combine.</param>
/// <returns>The created command.</returns>
public CombinePathCommand Create(string? originalPath = null, string? newPath = null)
{
return new Faker<CombinePathCommand>()
.CustomInstantiator(f => new CombinePathCommand(
default!,
default!))
.RuleFor(x => x.OriginalPath, f => originalPath ?? f.System.FilePath())
.RuleFor(x => x.NewPath, f => newPath ?? f.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="CombinePathCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<CombinePathCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Commands.SplitPath;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Commands.SplitPath.Fixtures;
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Commands.SplitPath;
/// <summary>
/// Fixture class for the <see cref="SplitPathCommand"/> class.
@@ -15,13 +17,23 @@ public class SplitPathCommandFixture
/// <summary>
/// Creates a random valid command for splitting paths.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <returns>The created command.</returns>
public static SplitPathCommand CreateSplitPathCommand()
public SplitPathCommand Create(string? path = null)
{
return new Faker<SplitPathCommand>()
.CustomInstantiator(f => new SplitPathCommand(
default!
))
.RuleFor(x => x.Path, f => f.System.FilePath());
default!))
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="SplitPathCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<SplitPathCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Queries.CheckPathExists.Fixtures;
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
/// <summary>
/// Fixture class for the <see cref="CheckPathExistsQuery"/> class.
@@ -15,16 +17,27 @@ public class CheckPathExistsQueryFixture
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query.</returns>
public static CheckPathExistsQuery CreateCheckPathExistsQuery(bool includeHiddenElements = true)
public CheckPathExistsQuery Create(string? path = null, bool includeHiddenElements = true)
{
return new Faker<CheckPathExistsQuery>()
.CustomInstantiator(f => new CheckPathExistsQuery(
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, includeHiddenElements);
}
/// <summary>
/// Creates a list of <see cref="CheckPathExistsQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<CheckPathExistsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathParent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathParent;
/// <summary>
/// Fixture class for the <see cref="GetPathParentQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathParentQueryFixture
{
/// <summary>
/// Creates a random valid query to get the parent of a path.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <returns>The created query.</returns>
public GetPathParentQuery Create(string? path = null)
{
return new Faker<GetPathParentQuery>()
.CustomInstantiator(f => new GetPathParentQuery(
default!))
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="GetPathParentQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPathParentQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.GetPathRoot;
/// <summary>
/// Fixture class for the <see cref="GetPathRootQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetPathRootQueryFixture
{
/// <summary>
/// Creates a random valid query to get the root of a path.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <returns>The created query.</returns>
public GetPathRootQuery Create(string? path = null)
{
return new Faker<GetPathRootQuery>()
.CustomInstantiator(f => new GetPathRootQuery(
default!))
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="GetPathRootQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPathRootQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,39 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Paths.Queries.ValidatePath;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Paths.Queries.ValidatePath;
/// <summary>
/// Fixture class for the <see cref="ValidatePathQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidatePathQueryFixture
{
/// <summary>
/// Creates a random valid query to validate a path.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <returns>The created query.</returns>
public ValidatePathQuery Create(string? path = null)
{
return new Faker<ValidatePathQuery>()
.CustomInstantiator(f => new ValidatePathQuery(
default!))
.RuleFor(x => x.Path, f => path ?? f.System.FilePath());
}
/// <summary>
/// Creates a list of <see cref="ValidatePathQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ValidatePathQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.FileSystemManagement.Thumbnails.Queries.GetThumbnail;
/// <summary>
/// Fixture class for the <see cref="GetThumbnailQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetThumbnailQueryFixture
{
/// <summary>
/// Creates a random valid query to get a thumbnail.
/// </summary>
/// <param name="path">Optional. The file system path.</param>
/// <param name="quality">Optional. The thumbnail quality.</param>
/// <returns>The created query.</returns>
public GetThumbnailQuery Create(string? path = null, int? quality = null)
{
return new Faker<GetThumbnailQuery>()
.CustomInstantiator(f => new GetThumbnailQuery(
default!,
default
))
.RuleFor(x => x.Path, f => path ?? f.System.FilePath())
.RuleFor(x => x.Quality, f => quality ?? f.Random.Int());
}
/// <summary>
/// Creates a list of <see cref="GetThumbnailQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThumbnailQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.Maintenance.ApplicationSetup.Commands.SetupApplication;
/// <summary>
/// Fixture class for the <see cref="SetupApplicationCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class SetupApplicationCommandFixture
{
/// <summary>
/// Creates a random valid command for the application setup.
/// </summary>
/// <param name="username">Optional. The admin username.</param>
/// <param name="password">Optional. The admin password.</param>
/// <param name="passwordConfirm">Optional. The admin password confirmation.</param>
/// <param name="use2fa">Whether to use two-factor authentication.</param>
/// <returns>The created command.</returns>
public SetupApplicationCommand Create(
string? username = null,
string? password = null,
string? passwordConfirm = null,
bool use2fa = true)
{
string resolvedPassword = password ?? "Abcd123$";
return new Faker<SetupApplicationCommand>()
.CustomInstantiator(f => new SetupApplicationCommand(
default!,
default!,
default!,
true
))
.RuleFor(x => x.Username, f => username ?? f.Internet.UserName())
.RuleFor(x => x.Password, resolvedPassword)
.RuleFor(x => x.PasswordConfirm, passwordConfirm ?? resolvedPassword)
.RuleFor(x => x.Use2fa, use2fa)
.Generate();
}
/// <summary>
/// Creates a list of <see cref="SetupApplicationCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<SetupApplicationCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,19 +2,18 @@
using AutoFixture;
using Bogus;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.Fixtures.Common.Setup;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
namespace Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
/// <summary>
/// Fixture class for the <see cref="AddBookCommand"/> class.
@@ -22,26 +21,24 @@ namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.B
[ExcludeFromCodeCoverage]
public class AddBookCommandFixture
{
private readonly Fixture _fixture;
private readonly Fixture _fixture = new();
private readonly Random _random = new();
private readonly Faker _faker;
private readonly Faker _faker = new();
/// <summary>
/// Initializes a new instance of the <see cref="AddBookCommandFixture"/> class.
/// </summary>
public AddBookCommandFixture()
{
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_faker = new Faker();
}
/// <summary>
/// Creates a random valid command to add a book.
/// </summary>
/// <returns>The created command to add a book.</returns>
public AddBookCommand CreateCommandBook()
public AddBookCommand Create()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -82,6 +79,7 @@ public class AddBookCommandFixture
))
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
.CustomInstantiator(f => new MediaContributorNameDto(
default!,
@@ -89,6 +87,7 @@ public class AddBookCommandFixture
))
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
.CustomInstantiator(f => new MediaContributorDto(
default!,
@@ -98,16 +97,16 @@ public class AddBookCommandFixture
.RuleFor(e => e.Role, mediaContributorRole);
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
.CustomInstantiator(f => new BookRatingDto(
.CustomInstantiator(f => new BookRatingDto(
default,
default,
default,
default
))
.RuleFor(e => e.Value, _random.Next(1, 5))
.RuleFor(e => e.MaxValue, 5)
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
.RuleFor(e => e.MaxValue, 5)
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
.CustomInstantiator(f => new LanguageInfoDto(
@@ -221,9 +220,7 @@ public class AddBookCommandFixture
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
.RuleFor(x => x.LCCN, f =>
{
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
.Select(_ => f.Random.Char('a', 'z'))
.ToArray());
string letters = new([.. Enumerable.Range(0, f.Random.Number(0, 3)).Select(_ => f.Random.Char('a', 'z'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
})
@@ -256,90 +253,19 @@ public class AddBookCommandFixture
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
})
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.GoogleBooksId, f =>
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string(Enumerable.Repeat(VALID_CHARS, 12)
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
.ToArray());
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
})
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
}
private void ConfigureCustomRequestTypes()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
_fixture.Register(() => new ReleaseInfoDto(
_faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)),
releaseYear,
_faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)),
reReleaseYear,
_fixture.Create<string>()[2..],
_fixture.Create<string?>()));
_fixture.Register(() => new GenreDto(
_fixture.Create<string>()
));
_fixture.Register(() => new TagDto(
_fixture.Create<string>()
));
_fixture.Register(() => new LanguageInfoDto(
_fixture.Create<string>(),
_fixture.Create<string>(),
_fixture.Create<string?>()
));
_fixture.Register(() => new IsbnDto(
_fixture.Create<string>(),
_fixture.Create<IsbnFormat>()
));
_fixture.Register(() => new BookRatingDto(
_fixture.Create<decimal>(),
_fixture.Create<decimal>(),
_fixture.Create<BookRatingSource?>(),
_fixture.Create<int?>()
));
_fixture.Register(() => new WrittenContentMetadataDto(
_fixture.Create<string>()[255..],
LimitStringLength(_fixture.Create<string?>(), 255),
LimitStringLength(_fixture.Create<string?>(), 2000),
_fixture.Create<ReleaseInfoDto>(),
_fixture.Create<List<GenreDto>>(),
_fixture.Create<List<TagDto>>(),
_fixture.Create<LanguageInfoDto?>(),
_fixture.Create<LanguageInfoDto?>(),
_fixture.Create<string?>(),
_fixture.Create<int?>()
));
_fixture.Register(() => new BookSeriesDto(
_fixture.Create<string>()
));
_fixture.Register(() => new MediaContributorRoleDto(
_fixture.Create<string>(),
_fixture.Create<string>()
));
_fixture.Register(() => new MediaContributorNameDto(
_fixture.Create<string>(),
_fixture.Create<string?>()
));
_fixture.Register(() => new MediaContributorDto(
_fixture.Create<MediaContributorNameDto>(),
_fixture.Create<MediaContributorRoleDto>()
));
}
private static string? LimitStringLength(string? input, int maxLength)
{
return input?.Length > maxLength ? input[..maxLength] : input;
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.ChangePassword;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authentication.Commands.ChangePassword;
/// <summary>
/// Fixture class for the <see cref="ChangePasswordCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ChangePasswordCommandFixture
{
/// <summary>
/// Creates a random valid command to change a password.
/// </summary>
/// <param name="username">Optional. The username.</param>
/// <param name="currentPassword">Optional. The current password.</param>
/// <param name="newPassword">Optional. The new password.</param>
/// <param name="newPasswordConfirm">Optional. The new password confirmation.</param>
/// <returns>The created command.</returns>
public ChangePasswordCommand Create(
string? username = null,
string? currentPassword = null,
string? newPassword = null,
string? newPasswordConfirm = null)
{
string resolvedCurrentPassword = currentPassword ?? "CurrentP@ss123";
string resolvedNewPassword = newPassword ?? "Abcd123$";
return new Faker<ChangePasswordCommand>()
.CustomInstantiator(f => new ChangePasswordCommand(
default!,
default!,
default!,
default!
))
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
.RuleFor(x => x.CurrentPassword, resolvedCurrentPassword)
.RuleFor(x => x.NewPassword, resolvedNewPassword)
.RuleFor(x => x.NewPasswordConfirm, newPasswordConfirm ?? resolvedNewPassword);
}
/// <summary>
/// Creates a list of <see cref="ChangePasswordCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ChangePasswordCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RecoverPassword;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authentication.Commands.RecoverPassword;
/// <summary>
/// Fixture class for the <see cref="RecoverPasswordCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class RecoverPasswordCommandFixture
{
/// <summary>
/// Creates a random valid command to recover a password.
/// </summary>
/// <param name="username">Optional. The username.</param>
/// <param name="totpCode">Optional. The TOTP code.</param>
/// <returns>The created command.</returns>
public RecoverPasswordCommand Create(string? username = null, string? totpCode = null)
{
return new Faker<RecoverPasswordCommand>()
.CustomInstantiator(f => new RecoverPasswordCommand(
default!,
default!
))
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
.RuleFor(x => x.TotpCode, f => totpCode ?? f.Random.Replace("######"));
}
/// <summary>
/// Creates a list of <see cref="RecoverPasswordCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<RecoverPasswordCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,54 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authentication.Commands.RegisterUser;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authentication.Commands.RegisterUser;
/// <summary>
/// Fixture class for the <see cref="RegisterUserCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class RegisterUserCommandFixture
{
/// <summary>
/// Creates a random valid command for a new account registration.
/// </summary>
/// <param name="username">Optional. The username.</param>
/// <param name="password">Optional. The password.</param>
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
/// <param name="use2fa">Whether to use two-factor authentication.</param>
/// <returns>The created command.</returns>
public RegisterUserCommand Create(
string? username = null,
string? password = null,
string? passwordConfirm = null,
bool use2fa = true)
{
string resolvedPassword = password ?? "Abcd123$";
return new Faker<RegisterUserCommand>()
.CustomInstantiator(f => new RegisterUserCommand(
default!,
default!,
default!,
true
))
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
.RuleFor(x => x.Password, resolvedPassword)
.RuleFor(x => x.PasswordConfirm, passwordConfirm ?? resolvedPassword)
.RuleFor(x => x.Use2fa, use2fa);
}
/// <summary>
/// Creates a list of <see cref="RegisterUserCommand"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<RegisterUserCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,9 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Core.UsersManagement.Authentication.Queries.GetUsers;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.GetUsers.Fixtures;
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authentication.Queries.GetUsers;
/// <summary>
/// Fixture class for the <see cref="GetUsersQuery"/> class.
@@ -15,8 +17,18 @@ public class GetUsersQueryFixture
/// Creates a random valid query to get users.
/// </summary>
/// <returns>The created query.</returns>
public GetUsersQuery CreateQuery()
public GetUsersQuery Create()
{
return new GetUsersQuery();
}
/// <summary>
/// Creates a list of <see cref="GetUsersQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetUsersQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authentication.Queries.LoginUser;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authentication.Queries.LoginUser;
/// <summary>
/// Fixture class for the <see cref="LoginUserQuery"/> class.
@@ -15,22 +17,37 @@ public class LoginUserQueryFixture
/// <summary>
/// Creates a random valid query for user login.
/// </summary>
/// <param name="username">Optional. The username.</param>
/// <param name="password">Optional. The password.</param>
/// <param name="includeTotpCode">Whether to include a TOTP code in the query.</param>
/// <returns>The created query.</returns>
public static LoginUserQuery CreateLoginQuery(bool includeTotpCode = false)
public LoginUserQuery Create(
string? username = null,
string? password = null,
bool includeTotpCode = false)
{
string password = "Abcd123$";
string resolvedPassword = password ?? "Abcd123$";
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
.CustomInstantiator(f => new LoginUserQuery(
default!,
default!,
default
))
.RuleFor(x => x.Username, f => f.Person.UserName)
.RuleFor(x => x.Password, password);
.RuleFor(x => x.Username, f => username ?? f.Person.UserName)
.RuleFor(x => x.Password, resolvedPassword);
if (includeTotpCode)
faker.RuleFor(x => x.TotpCode, f => f.Random.Replace("######")); // generates 6 random digits
return faker;
return faker.Generate();
}
/// <summary>
/// Creates a list of <see cref="LoginUserQuery"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<LoginUserQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Commands.UpdateUserRoleAndPermissions;
/// <summary>
/// Fixture class for the <see cref="UpdateUserRoleAndPermissionsCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UpdateUserRoleAndPermissionsCommandFixture
{
/// <summary>
/// Creates a random valid command to update user role and permissions.
/// </summary>
/// <param name="userId">Optional. The user Id.</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="permissionCount">The number of permissions to generate when none are provided.</param>
/// <returns>The created command.</returns>
public UpdateUserRoleAndPermissionsCommand Create(
Guid? userId = null,
Guid? roleId = null,
IEnumerable<Guid>? permissions = null,
int permissionCount = 3)
{
return new Faker<UpdateUserRoleAndPermissionsCommand>()
.CustomInstantiator(f => new UpdateUserRoleAndPermissionsCommand(
userId ?? Guid.NewGuid(),
roleId,
default!))
.RuleFor(x => x.Permissions, f => [.. permissions ?? Enumerable.Range(0, permissionCount).Select(_ => Guid.NewGuid())])
.Generate();
}
/// <summary>
/// Creates a list of <see cref="UpdateUserRoleAndPermissionsCommand"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="UpdateUserRoleAndPermissionsCommand"/> instances.</returns>
public List<UpdateUserRoleAndPermissionsCommand> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,41 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetAuthorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Queries.GetAuthorization;
/// <summary>
/// Fixture class for the <see cref="GetAuthorizationQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetAuthorizationQueryFixture
{
/// <summary>
/// Creates a random valid query to get authorization details.
/// </summary>
/// <param name="userId">Optional. The user Id to use. If null, a random GUID will be generated.</param>
/// <returns>The created query.</returns>
public GetAuthorizationQuery Create(Guid? userId = null)
{
return new Faker<GetAuthorizationQuery>()
.CustomInstantiator(f => new GetAuthorizationQuery(
userId ?? f.Random.Guid()
))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetAuthorizationQuery"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="GetAuthorizationQuery"/> instances.</returns>
public List<GetAuthorizationQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Bogus;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserPermissions.Fixtures;
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
/// <summary>
/// Fixture class for the <see cref="GetUserPermissionsQuery"/> class.
@@ -16,12 +18,23 @@ public class GetUserPermissionsQueryFixture
/// <summary>
/// Creates a random valid query to get user permissions.
/// </summary>
/// <param name="userId">Optional. The user Id.</param>
/// <returns>The created query.</returns>
public GetUserPermissionsQuery CreateQuery()
public GetUserPermissionsQuery Create(Guid? userId = null)
{
return new Faker<GetUserPermissionsQuery>()
.CustomInstantiator(f => new GetUserPermissionsQuery(
Guid.NewGuid()))
userId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetUserPermissionsQuery"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="GetUserPermissionsQuery"/> instances.</returns>
public List<GetUserPermissionsQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Bogus;
using Lumina.Application.Core.UsersManagement.Authorization.Queries.GetUserRole;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authorization.Queries.GetUserRole.Fixtures;
namespace Lumina.Application.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserRole;
/// <summary>
/// Fixture class for the <see cref="GetUserRoleQuery"/> class.
@@ -16,12 +18,23 @@ public class GetUserRoleQueryFixture
/// <summary>
/// Creates a random valid query to get a user's role.
/// </summary>
/// <param name="userId">Optional. The user Id.</param>
/// <returns>The created query.</returns>
public GetUserRoleQuery CreateQuery()
public GetUserRoleQuery Create(Guid? userId = null)
{
return new Faker<GetUserRoleQuery>()
.CustomInstantiator(f => new GetUserRoleQuery(
Guid.NewGuid()))
userId ?? Guid.NewGuid()))
.Generate();
}
/// <summary>
/// Creates a list of <see cref="GetUserRoleQuery"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="GetUserRoleQuery"/> instances.</returns>
public List<GetUserRoleQuery> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Bogus" Version="35.6.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Application\Lumina.Application.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Lumina.Application.Fixtures")]
[assembly: AssemblyProduct("Lumina.Application.Fixtures")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("A1B2C3D4-0003-4A5B-9C0D-333333333333")]
[assembly: InternalsVisibleTo("Lumina.Application.UnitTests")]
[assembly: InternalsVisibleTo("Lumina.DataAccess.UnitTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -1,10 +1,10 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Bogus;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Setup;
namespace Lumina.Contracts.Fixtures.Common.Setup;
/// <summary>
/// Contains extension methods for the <see cref="Faker"/> class.
@@ -16,7 +16,7 @@ public static class BogusExtensions
/// Adds <see cref="DateOnly"/> random data generation support to the <see cref="Faker"/> class.
/// </summary>
/// <param name="faker">The faker instance to extend.</param>
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
/// <returns>A random <see cref="DateOnly"/> instance.</returns>
public static DateOnly DateOnly(this Faker faker)
{
return System.DateOnly.FromDateTime(faker.Date.Past());
@@ -28,11 +28,11 @@ public static class BogusExtensions
/// <param name="faker">The faker instance to extend.</param>
/// <param name="start">The start of the interval.</param>
/// <param name="end">The end of the interval.</param>
/// <returns>A random<see cref="DateOnly"/> instance.</returns>
/// <returns>A random <see cref="DateOnly"/> instance.</returns>
public static DateOnly DateOnlyBetween(this Faker faker, DateOnly start, DateOnly end)
{
DateTime startDateTime = start.ToDateTime(TimeOnly.MinValue);
DateTime endDateTime = end.ToDateTime(TimeOnly.MinValue);
return System.DateOnly.FromDateTime(faker.Date.Between(startDateTime, endDateTime));
}
}
}
@@ -4,7 +4,7 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Common.Setup;
namespace Lumina.Contracts.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
@@ -4,10 +4,10 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.DataAccess.UnitTests.Common.Setup;
namespace Lumina.Contracts.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
/// Represents a specimen builder for the <see cref="DateOnly?"/> type.
/// </summary>
[ExcludeFromCodeCoverage]
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
@@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.DTO.FileSystemManagement;
/// <summary>
/// Fixture class for the <see cref="FileSystemItemDto"/> class.
@@ -37,6 +37,6 @@ public class FileSystemItemDtoFixture
/// <returns>The created list.</returns>
public List<FileSystemItemDto> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,55 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookRatingDto"/>.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingDtoFixture
{
private readonly Fixture _fixture = new();
private readonly Random _random = new();
/// <summary>
/// Creates a <see cref="BookRatingDto"/>.
/// </summary>
/// <param name="value">Optional. The rating value.</param>
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
/// <param name="source">Optional. The rating source.</param>
/// <param name="voteCount">Optional. The number of votes.</param>
/// <param name="includeOptionalProperties">Whether the optional source and vote count should be included.</param>
/// <returns>The created <see cref="BookRatingDto"/>.</returns>
public BookRatingDto Create(
decimal? value = null,
decimal? maxValue = null,
BookRatingSource? source = null,
int? voteCount = null,
bool includeOptionalProperties = true)
{
return new BookRatingDto(
value ?? _random.Next(1, 5),
maxValue ?? 5,
includeOptionalProperties ? (source ?? _fixture.Create<BookRatingSource>()) : null,
includeOptionalProperties ? (voteCount ?? _random.Next(1, 1000)) : null
);
}
/// <summary>
/// Creates a list of <see cref="BookRatingDto"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<BookRatingDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,12 @@
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="IsbnDto"/>.
@@ -16,51 +18,28 @@ public class IsbnDtoFixture
private readonly Random _random = new();
/// <summary>
/// Creates a valid ISBN-10 DTO.
/// Creates an <see cref="IsbnDto"/> with a random or explicitly requested format.
/// </summary>
/// <returns>The created ISBN DTO.</returns>
public IsbnDto CreateIsbn10()
/// <param name="value">Optional. The ISBN value. If not provided, a valid ISBN is generated.</param>
/// <param name="format">Optional. The ISBN format. If not provided, the format is left unspecified.</param>
/// <returns>The created <see cref="IsbnDto"/>.</returns>
public IsbnDto Create(string? value = null, IsbnFormat? format = null)
{
string resolvedValue = value ?? (format == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13());
return new IsbnDto(
GenerateValidIsbn10(),
IsbnFormat.Isbn10
resolvedValue,
format
);
}
/// <summary>
/// Creates a valid ISBN-13 DTO.
/// Creates a list of <see cref="IsbnDto"/>.
/// </summary>
/// <returns>The created ISBN DTO.</returns>
public IsbnDto CreateIsbn13()
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<IsbnDto> CreateMany(int count = 3)
{
return new IsbnDto(
GenerateValidIsbn13(),
IsbnFormat.Isbn13
);
}
/// <summary>
/// Creates an invalid ISBN DTO.
/// </summary>
/// <returns>The created invalid ISBN DTO.</returns>
public IsbnDto CreateInvalid()
{
return new IsbnDto(
"invalid-isbn",
IsbnFormat.Isbn13
);
}
/// <summary>
/// Creates an ISBN entity without format.
/// </summary>
/// <returns>The created ISBN entity.</returns>
public IsbnDto CreateWithoutFormat()
{
return new IsbnDto(
GenerateValidIsbn13(),
null
);
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
private string GenerateValidIsbn10()
@@ -6,39 +6,36 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.ChangePassword.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.Authentication;
/// <summary>
/// Fixture class for the <see cref="ChangePasswordRequest"/> class.
/// Fixture class for the <see cref="ChangePasswordRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ChangePasswordRequestFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="ChangePasswordRequestFixture"/> class.
/// </summary>
public ChangePasswordRequestFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="ChangePasswordRequest"/>.
/// </summary>
/// <param name="username">Optional. The username for the password change.</param>
/// <param name="currentPassword">Optional. The current password.</param>
/// <param name="newPassword">Optional. The new password.</param>
/// <param name="newPasswordConfirm">Optional. The new password confirmation.</param>
/// <returns>The created <see cref="ChangePasswordRequest"/>.</returns>
public ChangePasswordRequest CreateChangePasswordRequest(
public ChangePasswordRequest Create(
string? username = null,
string? currentPassword = null,
string? newPassword = null,
string? newPasswordConfirm = null)
{
string generatedNewPassword = newPassword ?? _faker.Internet.Password();
return new ChangePasswordRequest(
username ?? _faker.Internet.UserName(),
currentPassword ?? _faker.Internet.Password(),
newPassword ?? _faker.Internet.Password(),
newPasswordConfirm ?? _faker.Internet.Password()
generatedNewPassword,
newPasswordConfirm ?? generatedNewPassword
);
}
@@ -49,8 +46,6 @@ public class ChangePasswordRequestFixture
/// <returns>The created list.</returns>
public List<ChangePasswordRequest> CreateMany(int count = 3)
{
return Enumerable.Range(0, count)
.Select(_ => CreateChangePasswordRequest())
.ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,29 +6,24 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Queries.LoginUser.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.Authentication;
/// <summary>
/// Fixture class for the <see cref="LoginRequest"/> class.
/// Fixture class for the <see cref="LoginRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LoginRequestFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="LoginRequestFixture"/> class.
/// </summary>
public LoginRequestFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="LoginRequest"/>.
/// </summary>
/// <param name="username">Optional. The username for login.</param>
/// <param name="password">Optional. The password for login.</param>
/// <param name="totpCode">Optional. The TOTP code for two-factor authentication.</param>
/// <returns>The created <see cref="LoginRequest"/>.</returns>
public LoginRequest CreateLoginRequest(
public LoginRequest Create(
string? username = null,
string? password = null,
string? totpCode = null)
@@ -47,8 +42,6 @@ public class LoginRequestFixture
/// <returns>The created list.</returns>
public List<LoginRequest> CreateMany(int count = 3)
{
return Enumerable.Range(0, count)
.Select(_ => CreateLoginRequest())
.ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,29 +6,23 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RecoverPassword.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.Authentication;
/// <summary>
/// Fixture class for the <see cref="RecoverPasswordRequest"/> class.
/// Fixture class for the <see cref="RecoverPasswordRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RecoverPasswordRequestFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="RecoverPasswordRequestFixture"/> class.
/// </summary>
public RecoverPasswordRequestFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="RecoverPasswordRequest"/>.
/// </summary>
/// <param name="username">Optional. The username for password recovery.</param>
/// <param name="totpCode">Optional. The TOTP code for verification.</param>
/// <returns>The created <see cref="RecoverPasswordRequest"/>.</returns>
public RecoverPasswordRequest CreateRecoverPasswordRequest(
public RecoverPasswordRequest Create(
string? username = null,
string? totpCode = null)
{
@@ -45,8 +39,6 @@ public class RecoverPasswordRequestFixture
/// <returns>The created list.</returns>
public List<RecoverPasswordRequest> CreateMany(int count = 3)
{
return Enumerable.Range(0, count)
.Select(_ => CreateRecoverPasswordRequest())
.ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,40 +6,35 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.UsersManagement.Authentication.Commands.RegisterUser.Fixture;
namespace Lumina.Contracts.Fixtures.Core.Requests.Authentication;
/// <summary>
/// Fixture class for the <see cref="RegistrationRequest"/> class.
/// Fixture class for the <see cref="RegistrationRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RegistrationRequestFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="RegistrationRequestFixture"/> class.
/// </summary>
public RegistrationRequestFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="RegistrationRequest"/>.
/// </summary>
/// <param name="username">Optional. The username for registration.</param>
/// <param name="password">Optional. The password for registration.</param>
/// <param name="passwordConfirm">Optional. The password confirmation.</param>
/// <param name="use2fa">Optional. Whether to use two-factor authentication.</param>
/// <returns>The created <see cref="RegistrationRequest"/>.</returns>
public RegistrationRequest CreateRegistrationRequest(
public RegistrationRequest Create(
string? username = null,
string? password = null,
string? passwordConfirm = null,
bool? use2fa = null)
{
password ??= _faker.Internet.Password();
string generatedPassword = password ?? _faker.Internet.Password();
return new RegistrationRequest(
username ?? _faker.Internet.UserName(),
password,
passwordConfirm ?? password,
generatedPassword,
passwordConfirm ?? generatedPassword,
use2fa ?? _faker.Random.Bool()
);
}
@@ -51,8 +46,6 @@ public class RegistrationRequestFixture
/// <returns>The created list.</returns>
public List<RegistrationRequest> CreateMany(int count = 3)
{
return Enumerable.Range(0, count)
.Select(_ => CreateRegistrationRequest())
.ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Requests.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.UsersManagement.Authorization.GetAuthorization.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.Authorization;
/// <summary>
/// Fixture class for the <see cref="GetAuthorizationRequest"/> record.
@@ -15,12 +17,22 @@ public class GetAuthorizationRequestFixture
/// <summary>
/// Creates a <see cref="GetAuthorizationRequest"/> with default or specified values.
/// </summary>
/// <param name="userId">Optional user Id to use.</param>
/// <param name="userId">Optional. The user Id to use.</param>
/// <returns>The created <see cref="GetAuthorizationRequest"/>.</returns>
public static GetAuthorizationRequest Create(Guid? userId = null)
public GetAuthorizationRequest Create(Guid? userId = null)
{
return new GetAuthorizationRequest(
UserId: userId ?? Guid.NewGuid()
);
}
/// <summary>
/// Creates a list of <see cref="GetAuthorizationRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetAuthorizationRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Directories;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Directories;
/// <summary>
/// Fixture class for the <see cref="GetDirectoriesRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetDirectoriesRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a <see cref="GetDirectoriesRequest"/> with default or random values.
/// </summary>
/// <param name="path">Optional. The file system path for which to get the directories.</param>
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
/// <returns>The created <see cref="GetDirectoriesRequest"/>.</returns>
public GetDirectoriesRequest Create(string? path = null, bool? includeHiddenElements = null)
{
return new GetDirectoriesRequest(
Path: path ?? _faker.System.FilePath(),
IncludeHiddenElements: includeHiddenElements ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="GetDirectoriesRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetDirectoriesRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Files;
/// <summary>
/// Fixture class for the <see cref="GetFilesRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetFilesRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a <see cref="GetFilesRequest"/> with default or random values.
/// </summary>
/// <param name="path">Optional. The file system path for which to get the files.</param>
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
/// <returns>The created <see cref="GetFilesRequest"/>.</returns>
public GetFilesRequest Create(string? path = null, bool? includeHiddenElements = null)
{
return new GetFilesRequest(
Path: path ?? _faker.System.FilePath(),
IncludeHiddenElements: includeHiddenElements ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="GetFilesRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetFilesRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Files;
/// <summary>
/// Fixture class for the <see cref="GetTreeFilesRequest"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetTreeFilesRequestFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a <see cref="GetTreeFilesRequest"/> with default or random values.
/// </summary>
/// <param name="path">Optional. The file system path for which to get the tree files.</param>
/// <param name="includeHiddenElements">Optional. Whether to include hidden file system elements.</param>
/// <returns>The created <see cref="GetTreeFilesRequest"/>.</returns>
public GetTreeFilesRequest Create(string? path = null, bool? includeHiddenElements = null)
{
return new GetTreeFilesRequest(
Path: path ?? _faker.System.FilePath(),
IncludeHiddenElements: includeHiddenElements ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="GetTreeFilesRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetTreeFilesRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="CheckPathExistsRequest"/> record.
@@ -17,8 +19,8 @@ public class CheckPathExistsRequestFixture
/// <summary>
/// Creates a <see cref="CheckPathExistsRequest"/> with default or random values.
/// </summary>
/// <param name="path">The path to check.</param>
/// <param name="includeHiddenElements">Whether to include hidden elements.</param>
/// <param name="path">Optional. The path to check.</param>
/// <param name="includeHiddenElements">Optional. Whether to include hidden elements.</param>
/// <returns>The created <see cref="CheckPathExistsRequest"/>.</returns>
public CheckPathExistsRequest Create(string? path = null, bool? includeHiddenElements = null)
{
@@ -27,4 +29,14 @@ public class CheckPathExistsRequestFixture
IncludeHiddenElements: includeHiddenElements ?? _faker.Random.Bool()
);
}
/// <summary>
/// Creates a list of <see cref="CheckPathExistsRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<CheckPathExistsRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="CombinePathRequest"/> record.
@@ -17,8 +19,8 @@ public class CombinePathRequestFixture
/// <summary>
/// Creates a <see cref="CombinePathRequest"/> with default or random values.
/// </summary>
/// <param name="originalPath">The original path.</param>
/// <param name="newPath">The new path to combine.</param>
/// <param name="originalPath">Optional. The original path.</param>
/// <param name="newPath">Optional. The new path to combine.</param>
/// <returns>The created <see cref="CombinePathRequest"/>.</returns>
public CombinePathRequest Create(string? originalPath = null, string? newPath = null)
{
@@ -27,4 +29,14 @@ public class CombinePathRequestFixture
NewPath: newPath ?? _faker.System.FileName()
);
}
/// <summary>
/// Creates a list of <see cref="CombinePathRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<CombinePathRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="GetPathParentRequest"/> record.
@@ -17,7 +19,7 @@ public class GetPathParentRequestFixture
/// <summary>
/// Creates a <see cref="GetPathParentRequest"/> with a default or random value.
/// </summary>
/// <param name="path">The path to get the parent of.</param>
/// <param name="path">Optional. The path to get the parent of.</param>
/// <returns>The created <see cref="GetPathParentRequest"/>.</returns>
public GetPathParentRequest Create(string? path = null)
{
@@ -25,4 +27,14 @@ public class GetPathParentRequestFixture
Path: path ?? _faker.System.FilePath()
);
}
/// <summary>
/// Creates a list of <see cref="GetPathParentRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPathParentRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="GetPathRootRequest"/> record.
@@ -17,7 +19,7 @@ public class GetPathRootRequestFixture
/// <summary>
/// Creates a <see cref="GetPathRootRequest"/> with a default or random value.
/// </summary>
/// <param name="path">The path to get the root of.</param>
/// <param name="path">Optional. The path to get the root of.</param>
/// <returns>The created <see cref="GetPathRootRequest"/>.</returns>
public GetPathRootRequest Create(string? path = null)
{
@@ -25,4 +27,14 @@ public class GetPathRootRequestFixture
Path: path ?? _faker.System.FilePath()
);
}
/// <summary>
/// Creates a list of <see cref="GetPathRootRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetPathRootRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="SplitPathRequest"/> record.
@@ -17,7 +19,7 @@ public class SplitPathRequestFixture
/// <summary>
/// Creates a <see cref="SplitPathRequest"/> with a default or random value.
/// </summary>
/// <param name="path">The path to split.</param>
/// <param name="path">Optional. The path to split.</param>
/// <returns>The created <see cref="SplitPathRequest"/>.</returns>
public SplitPathRequest Create(string? path = null)
{
@@ -25,4 +27,14 @@ public class SplitPathRequestFixture
Path: path ?? _faker.System.FilePath()
);
}
/// <summary>
/// Creates a list of <see cref="SplitPathRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<SplitPathRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Path;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="ValidatePathRequest"/> record.
@@ -17,7 +19,7 @@ public class ValidatePathRequestFixture
/// <summary>
/// Creates a <see cref="ValidatePathRequest"/> with a default or random value.
/// </summary>
/// <param name="path">The path to validate.</param>
/// <param name="path">Optional. The path to validate.</param>
/// <returns>The created <see cref="ValidatePathRequest"/>.</returns>
public ValidatePathRequest Create(string? path = null)
{
@@ -25,4 +27,14 @@ public class ValidatePathRequestFixture
Path: path ?? _faker.System.FilePath()
);
}
/// <summary>
/// Creates a list of <see cref="ValidatePathRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ValidatePathRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,10 +1,12 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Requests.FileSystemManagement.Thumbnails;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Presentation.Api.UnitTests.Core.Endpoints.FileSystemManagement.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.FileSystemManagement.Thumbnails;
/// <summary>
/// Fixture class for the <see cref="GetThumbnailRequest"/> record.
@@ -17,8 +19,8 @@ public class GetThumbnailRequestFixture
/// <summary>
/// Creates a <see cref="GetThumbnailRequest"/> with default or random values.
/// </summary>
/// <param name="path">The path of the file to get the thumbnail for.</param>
/// <param name="quality">The quality of the thumbnail.</param>
/// <param name="path">Optional. The path of the file to get the thumbnail for.</param>
/// <param name="quality">Optional. The quality of the thumbnail.</param>
/// <returns>The created <see cref="GetThumbnailRequest"/>.</returns>
public GetThumbnailRequest Create(string? path = null, int? quality = null)
{
@@ -27,4 +29,14 @@ public class GetThumbnailRequestFixture
Quality: quality ?? _faker.Random.Int(1, 100)
);
}
/// <summary>
/// Creates a list of <see cref="GetThumbnailRequest"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<GetThumbnailRequest> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,19 +1,19 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Lumina.Contracts.DTO.Common;
using Lumina.Contracts.DTO.MediaContributors;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary;
using Lumina.Contracts.DTO.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Contracts.Fixtures.Common.Setup;
using Lumina.Contracts.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Requests.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
/// <summary>
/// Fixture class for the <see cref="AddBookRequest"/> class.
@@ -21,26 +21,24 @@ namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.B
[ExcludeFromCodeCoverage]
public class AddBookRequestFixture
{
private readonly Fixture _fixture;
private readonly Fixture _fixture = new();
private readonly Random _random = new();
private readonly Faker _faker;
private readonly Faker _faker = new();
/// <summary>
/// Initializes a new instance of the <see cref="AddBookRequestFixture"/> class.
/// </summary>
public AddBookRequestFixture()
{
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_faker = new Faker();
}
/// <summary>
/// Creates a random valid request to add a book.
/// </summary>
/// <returns>The created request to add a book.</returns>
public AddBookRequest CreateRequestBook()
public AddBookRequest Create()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
@@ -83,12 +81,12 @@ public class AddBookRequestFixture
.RuleFor(e => e.Category, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<MediaContributorNameDto> mediaContributorName = new Faker<MediaContributorNameDto>()
.CustomInstantiator(f => new MediaContributorNameDto(
default!,
default!
))
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
.CustomInstantiator(f => new MediaContributorNameDto(
default!,
default!
))
.RuleFor(e => e.DisplayName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.LegalName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<MediaContributorDto> mediaContributor = new Faker<MediaContributorDto>()
.CustomInstantiator(f => new MediaContributorDto(
@@ -99,16 +97,16 @@ public class AddBookRequestFixture
.RuleFor(e => e.Role, mediaContributorRole);
Faker<BookRatingDto> rating = new Faker<BookRatingDto>()
.CustomInstantiator(f => new BookRatingDto(
.CustomInstantiator(f => new BookRatingDto(
default,
default,
default,
default
))
.RuleFor(e => e.Value, _random.Next(1, 5))
.RuleFor(e => e.MaxValue, 5)
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
.RuleFor(e => e.MaxValue, 5)
.RuleFor(e => e.Source, _fixture.Create<BookRatingSource>())
.RuleFor(e => e.VoteCount, _random.Next(1, 1000));
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
.CustomInstantiator(f => new LanguageInfoDto(
@@ -222,9 +220,7 @@ public class AddBookRequestFixture
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
.RuleFor(x => x.LCCN, f =>
{
string letters = new(Enumerable.Range(0, f.Random.Number(0, 3))
.Select(_ => f.Random.Char('a', 'z'))
.ToArray());
string letters = new([.. Enumerable.Range(0, f.Random.Number(0, 3)).Select(_ => f.Random.Char('a', 'z'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
})
@@ -257,20 +253,17 @@ public class AddBookRequestFixture
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(new[] { 'A', 'M', 'W' });
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
})
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.GoogleBooksId, f =>
{
const string VALID_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
return new string(Enumerable.Repeat(VALID_CHARS, 12)
.Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])
.ToArray());
return new string([.. Enumerable.Repeat(VALID_CHARS, 12).Select(s => s[f.Random.Number(VALID_CHARS.Length - 1)])]);
})
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(p => p.ISBNs, f => isbn.Generate(f.Random.Number(1, 5)))
.RuleFor(p => p.Ratings, f => rating.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Contributors, f => mediaContributor.Generate(f.Random.Number(1, 5)));
@@ -1,13 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Common;
/// <summary>
/// Fixture class for the <see cref="FileSystemTreeNodeResponse"/> class.
@@ -53,6 +53,6 @@ public class FileSystemTreeNodeResponseFixture
/// <returns>A list of <see cref="FileSystemTreeNodeResponse"/> objects with nested structures.</returns>
public List<FileSystemTreeNodeResponse> CreateMany(int count = 2, int maxDepth = 2, int maxChildren = 3)
{
return Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren)).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create(0, maxDepth, maxChildren))];
}
}
@@ -1,12 +1,13 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Fixtures.Core.DTO.FileSystemManagement;
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Directories.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Directories;
/// <summary>
/// Fixture class for the <see cref="DirectoryResponse"/> class.
@@ -20,7 +21,7 @@ public class DirectoryResponseFixture
/// <summary>
/// Creates a random valid <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="itemCount">The number of children elements to create.</param>
/// <param name="itemCount">Optional. The number of children elements to create.</param>
/// <returns>The created <see cref="DirectoryResponse"/>.</returns>
public DirectoryResponse Create(int itemCount = 3)
{
@@ -37,10 +38,10 @@ public class DirectoryResponseFixture
/// Creates a list of <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <param name="itemCount">The number of children elemens to create for each element.</param>
/// <param name="itemCount">The number of children elements to create for each element.</param>
/// <returns>The created list.</returns>
public List<DirectoryResponse> CreateMany(int count = 3, int itemCount = 3)
{
return Enumerable.Range(0, count).Select(_ => Create(itemCount)).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create(itemCount))];
}
}
@@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Files;
/// <summary>
/// Fixture class for the <see cref="FileResponse"/> class.
@@ -38,6 +38,6 @@ public class FileResponseFixture
/// <returns>The created list.</returns>
public List<FileResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="PathSegmentResponse"/> class.
@@ -19,10 +19,11 @@ public class PathSegmentResponseFixture
/// <summary>
/// Creates a random valid <see cref="PathSegmentResponse"/>.
/// </summary>
/// <param name="path">Optional. The path of the segment.</param>
/// <returns>The created <see cref="PathSegmentResponse"/>.</returns>
public PathSegmentResponse Create()
public PathSegmentResponse Create(string? path = null)
{
return new PathSegmentResponse(_faker.System.DirectoryPath());
return new PathSegmentResponse(path ?? _faker.System.DirectoryPath());
}
/// <summary>
@@ -32,6 +33,6 @@ public class PathSegmentResponseFixture
/// <returns>The created list.</returns>
public List<PathSegmentResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -6,7 +6,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Pahs.Fixtures;
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
/// <summary>
/// Fixture class for the <see cref="PathSeparatorResponse"/> class.
@@ -19,10 +19,11 @@ public class PathSeparatorResponseFixture
/// <summary>
/// Creates a random valid <see cref="PathSeparatorResponse"/>.
/// </summary>
/// <param name="separator">Optional. The path separator.</param>
/// <returns>The created <see cref="PathSeparatorResponse"/>.</returns>
public PathSeparatorResponse Create()
public PathSeparatorResponse Create(string? separator = null)
{
return new PathSeparatorResponse(_faker.System.DirectoryPath());
return new PathSeparatorResponse(separator ?? _faker.System.DirectoryPath());
}
/// <summary>
@@ -32,6 +33,6 @@ public class PathSeparatorResponseFixture
/// <returns>The created list.</returns>
public List<PathSeparatorResponse> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => Create()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,42 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Thumbnails;
/// <summary>
/// Fixture class for the <see cref="ThumbnailResponse"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThumbnailResponseFixture
{
/// <summary>
/// Creates a random valid <see cref="ThumbnailResponse"/>.
/// </summary>
/// <param name="type">Optional. The thumbnail image type.</param>
/// <param name="bytes">Optional. The thumbnail image bytes.</param>
/// <returns>The created <see cref="ThumbnailResponse"/>.</returns>
public ThumbnailResponse Create(ImageType? type = null, byte[]? bytes = null)
{
Faker faker = new();
return new ThumbnailResponse(
type ?? faker.PickRandom<ImageType>(),
bytes ?? faker.Random.Bytes(20)
);
}
/// <summary>
/// Creates a list of <see cref="ThumbnailResponse"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<ThumbnailResponse> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Bogus" Version="35.6.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Contracts\Lumina.Contracts.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,22 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Lumina.Contracts.Fixtures")]
[assembly: AssemblyProduct("Lumina.Contracts.Fixtures")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("A1B2C3D4-0002-4A5B-9C0D-222222222222")]
[assembly: InternalsVisibleTo("Lumina.Application.UnitTests")]
[assembly: InternalsVisibleTo("Lumina.Presentation.Api.UnitTests")]
[assembly: InternalsVisibleTo("Lumina.Presentation.Api.IntegrationTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -4,7 +4,7 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
namespace Lumina.Domain.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
@@ -4,10 +4,10 @@ using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Presentation.Api.IntegrationTests.Common.Setup;
namespace Lumina.Domain.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
/// Represents a specimen builder for the <see cref="DateOnly?"/> type.
/// </summary>
[ExcludeFromCodeCoverage]
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
@@ -10,23 +10,15 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Entities.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
/// <summary>
/// Fixture class for the <see cref="Directory"/> class.
/// Fixture class for the <see cref="Directory"/> entity.
/// </summary>
[ExcludeFromCodeCoverage]
public class DirectoryFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="DirectoryFixture"/> class.
/// </summary>
public DirectoryFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="Directory"/>.
@@ -39,7 +31,7 @@ public class DirectoryFixture
/// <param name="childItems">Optional. A list of child items to be added to the directory.</param>
/// <returns>A newly created <see cref="Directory"/> instance.</returns>
/// <exception cref="InvalidOperationException">Thrown if the <see cref="Directory"/> creation fails.</exception>
public Directory CreateDirectory(
public Directory Create(
string? path = null,
string? name = null,
Optional<DateTime>? dateCreated = null,
@@ -72,7 +64,7 @@ public class DirectoryFixture
/// <returns>The created list.</returns>
public List<Directory> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => CreateDirectory())];
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
/// <summary>
@@ -104,6 +96,6 @@ public class DirectoryFixture
for (int i = 0; i < childCount; i++)
childItems.Add(CreateNestedDirectory(currentDepth + 1, maxDepth, maxChildrenPerDirectory));
}
return CreateDirectory(childItems: childItems);
return Create(childItems: childItems);
}
}
@@ -9,40 +9,40 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
/// <summary>
/// Fixture class for the <see cref="File"/> class.
/// Fixture class for the <see cref="File"/> entity.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="FileFixture"/> class.
/// </summary>
public FileFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="File"/>.
/// </summary>
/// <param name="path">Optional. The file path. If not provided, a random path is generated.</param>
/// <param name="name">Optional. The file name. If not provided, a random name is generated.</param>
/// <param name="dateCreated">Optional. The file's creation date. If not provided, a random past date is generated.</param>
/// <param name="dateModified">Optional. The file's modification date. If not provided, a recent date is generated.</param>
/// <param name="size">Optional. The file size. If not provided, a random size is generated.</param>
/// <param name="status">Optional. The file's status. If not provided, a random status is assigned.</param>
/// <param name="includeDates">Whether the file should include creation and modification dates.</param>
/// <returns>The created <see cref="File"/>.</returns>
public File CreateFile(
string? path = null,
string? name = null,
Optional<DateTime>? dateCreated = null,
Optional<DateTime>? dateModified = null,
long? size = null,
FileSystemItemStatus? status = null)
public File Create(
string? path = null,
string? name = null,
Optional<DateTime>? dateCreated = null,
Optional<DateTime>? dateModified = null,
long? size = null,
FileSystemItemStatus? status = null,
bool includeDates = true)
{
path ??= _faker.System.FilePath();
name ??= _faker.System.FileName();
dateCreated ??= Optional<DateTime>.Some(_faker.Date.Past());
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
dateCreated ??= includeDates ? Optional<DateTime>.Some(_faker.Date.Past()) : Optional<DateTime>.None();
dateModified ??= includeDates ? Optional<DateTime>.Some(_faker.Date.Recent()) : Optional<DateTime>.None();
size ??= _faker.Random.Long();
status ??= _faker.PickRandom<FileSystemItemStatus>();
@@ -60,22 +60,6 @@ public class FileFixture
/// <returns>The created list.</returns>
public List<File> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => CreateFile())];
}
/// <summary>
/// Creates a random valid <see cref="File"/>, without creationg and modification dates.
/// </summary>
/// <returns></returns>
public static File CreateFileWithoutDates()
{
return File.Create(
"/path/to/file_without_dates.txt",
"file_without_dates.txt",
Optional<DateTime>.None(),
Optional<DateTime>.None(),
2048,
FileSystemItemStatus.Accessible
).Value;
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -4,13 +4,15 @@ using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.FileSystem.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
/// <summary>
/// Fixture class for the <see cref="UnixRootItem"/> class.
/// Fixture class for the <see cref="UnixRootItem"/> entity.
/// </summary>
[ExcludeFromCodeCoverage]
public class UnixRootItemFixture
@@ -20,14 +22,25 @@ public class UnixRootItemFixture
/// <summary>
/// Creates a random valid <see cref="UnixRootItem"/>.
/// </summary>
/// <param name="status">Optional. The root item status.</param>
/// <returns>The created <see cref="UnixRootItem"/>.</returns>
public UnixRootItem Create()
public UnixRootItem Create(FileSystemItemStatus? status = null)
{
Result<UnixRootItem> unixRootItemResult = UnixRootItem.Create(
_faker.PickRandom<FileSystemItemStatus>()
status ?? _faker.PickRandom<FileSystemItemStatus>()
);
if (unixRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", unixRootItemResult.Errors));
throw new InvalidOperationException("Failed to create UnixRootItem: " + string.Join(", ", unixRootItemResult.Errors));
return unixRootItemResult.Value;
}
/// <summary>
/// Creates a list of <see cref="UnixRootItem"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<UnixRootItem> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
/// <summary>
/// Fixture class for the <see cref="WindowsRootItem"/> entity.
/// </summary>
[ExcludeFromCodeCoverage]
public class WindowsRootItemFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="WindowsRootItem"/>.
/// </summary>
/// <param name="path">Optional. The root item path.</param>
/// <param name="name">Optional. The root item name.</param>
/// <param name="status">Optional. The root item status.</param>
/// <returns>The created <see cref="WindowsRootItem"/>.</returns>
public WindowsRootItem Create(
string? path = null,
string? name = null,
FileSystemItemStatus? status = null)
{
Result<WindowsRootItem> windowsRootItemResult = WindowsRootItem.Create(
path ?? _faker.System.FilePath(),
name ?? _faker.System.FileName(),
status ?? _faker.PickRandom<FileSystemItemStatus>()
);
if (windowsRootItemResult.IsFailure)
throw new InvalidOperationException("Failed to create WindowsRootItem: " + string.Join(", ", windowsRootItemResult.Errors));
return windowsRootItemResult.Value;
}
/// <summary>
/// Creates a list of <see cref="WindowsRootItem"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<WindowsRootItem> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,14 +1,14 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
/// <summary>
/// Fixture class for the <see cref="FileSystemItem"/> class.
/// Test-support class that allows the abstract <see cref="FileSystemItem"/> type to be instantiated in tests.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileSystemItemFixture : FileSystemItem
@@ -2,7 +2,7 @@
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Strategies.Platform.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
/// <summary>
/// Fixture interface for non existing platform context.
@@ -3,33 +3,27 @@ using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="FileSystemPathId"/> class.
/// Fixture class for the <see cref="FileSystemPathId"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class FileSystemPathIdFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemPathIdFixture"/> class.
/// </summary>
public FileSystemPathIdFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="FileSystemPathId"/>.
/// </summary>
/// <param name="path">The path of the file system path element.</param>
/// <param name="path">Optional. The path of the file system path element.</param>
/// <returns>The created <see cref="FileSystemPathId"/>.</returns>
public FileSystemPathId CreateFileSystemPathId(string? path = null)
public FileSystemPathId Create(string? path = null)
{
path ??= _faker.System.FilePath();
@@ -39,4 +33,14 @@ public class FileSystemPathIdFixture
throw new InvalidOperationException("Failed to create FileSystemPathId: " + string.Join(", ", fileSystemPathIdResult.Errors));
return fileSystemPathIdResult.Value;
}
/// <summary>
/// Creates a list of <see cref="FileSystemPathId"/>.
/// </summary>
/// <param name="count">The number of elements to create.</param>
/// <returns>The created list.</returns>
public List<FileSystemPathId> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -8,32 +8,27 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.ValueObjects.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="PathSegment"/> class.
/// Fixture class for the <see cref="PathSegment"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class PathSegmentFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="PathSegmentFixture"/> class.
/// </summary>
public PathSegmentFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="PathSegment"/>.
/// </summary>
/// <param name="name">Optional. The segment name.</param>
/// <param name="isDirectory">Whether the segment is a directory.</param>
/// <param name="isDrive">Whether the segment is a drive.</param>
/// <returns>The created <see cref="PathSegment"/>.</returns>
public PathSegment CreatePathSegment(
string? name = null,
bool? isDirectory = null,
bool? isDrive = null)
public PathSegment Create(
string? name = null,
bool? isDirectory = null,
bool? isDrive = null)
{
name ??= _faker.System.FileName();
isDirectory ??= true;
@@ -53,6 +48,6 @@ public class PathSegmentFixture
/// <returns>The created list.</returns>
public List<PathSegment> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => CreatePathSegment())];
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -8,37 +8,29 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.ValueObjects.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="StreamInfo"/> class.
/// Fixture class for the <see cref="StreamInfo"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class StreamInfoFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="StreamInfoFixture"/> class.
/// </summary>
public StreamInfoFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="StreamInfo"/>.
/// </summary>
/// <param name="streamId">Optional. The unique identifier for the stream. If not provided, a default value may be used.</param>
/// <param name="mimeType">Optional. The MIME type of the stream (e.g., video/mp4, audio/mpeg). If not provided, a default MIME type may be used.</param>
/// <param name="bitrate">Optional. The bitrate of the stream in kbps. If not provided, a default value may be used.</param>
/// <param name="codec">Optional. The codec used for the stream (e.g., H.264, AAC). If not provided, a default codec may be used.</param>
/// <param name="resolution">Optional. The video resolution (e.g., 1920x1080). If not provided, a default resolution may be used.</param>
/// <param name="frameRate">Optional. The frame rate of the video stream in frames per second (fps). If not provided, a default frame rate may be used.</param>
/// <param name="sampleRate">Optional. The sample rate of the audio stream in Hz. If not provided, a default sample rate may be used.</param>
/// <param name="channels">Optional. The number of audio channels (e.g., 2 for stereo, 6 for 5.1 surround). If not provided, a default channel count may be used.</param>
/// <param name="streamId">Optional. The unique identifier for the stream.</param>
/// <param name="mimeType">Optional. The MIME type of the stream.</param>
/// <param name="bitrate">Optional. The bitrate of the stream in kbps.</param>
/// <param name="codec">Optional. The codec used for the stream.</param>
/// <param name="resolution">Optional. The video resolution.</param>
/// <param name="frameRate">Optional. The frame rate of the video stream.</param>
/// <param name="sampleRate">Optional. The sample rate of the audio stream.</param>
/// <param name="channels">Optional. The number of audio channels.</param>
/// <returns>The created <see cref="StreamInfo"/>.</returns>
public StreamInfo CreateStreamInfo(
public StreamInfo Create(
string? streamId = null,
string? mimeType = null,
int? bitrate = null,
@@ -72,6 +64,6 @@ public class StreamInfoFixture
/// <returns>The created list.</returns>
public List<StreamInfo> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => CreateStreamInfo())];
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,29 +1,21 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.ValueObjects.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="Thumbnail"/> class.
/// Fixture class for the <see cref="Thumbnail"/> value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class ThumbnailFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="ThumbnailFixture"/> class.
/// </summary>
public ThumbnailFixture()
{
_faker = new Faker();
}
private readonly Faker _faker = new();
/// <summary>
/// Creates a random valid <see cref="Thumbnail"/>.
@@ -31,7 +23,7 @@ public class ThumbnailFixture
/// <param name="type">Optional. The <see cref="ImageType"/> of the thumbnail. If not provided, a random image type is selected.</param>
/// <param name="bytes">Optional. The byte array representing the image data. If not provided, a random 1KB byte array is generated.</param>
/// <returns>A newly created <see cref="Thumbnail"/> instance.</returns>
public Thumbnail CreateThumbnail(ImageType? type = null, byte[]? bytes = null)
public Thumbnail Create(ImageType? type = null, byte[]? bytes = null)
{
type ??= _faker.PickRandom<ImageType>();
bytes ??= _faker.Random.Bytes(1024); // Generate 1KB of random bytes
@@ -46,6 +38,6 @@ public class ThumbnailFixture
/// <returns>The created list.</returns>
public List<Thumbnail> CreateMany(int count = 3)
{
return Enumerable.Range(0, count).Select(_ => CreateThumbnail()).ToList();
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,107 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
/// <summary>
/// Fixture class for the <see cref="Library"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryFixture
{
private readonly Faker _faker = new();
private readonly Random _random = new();
/// <summary>
/// Creates a random valid <see cref="Library"/> domain aggregate.
/// </summary>
/// <param name="id">Optional. The library Id.</param>
/// <param name="userId">Optional. The Id of the user that owns the library.</param>
/// <param name="title">Optional. The library title.</param>
/// <param name="libraryType">Optional. The library type.</param>
/// <param name="contentLocations">Optional. The content locations of the library.</param>
/// <param name="coverImage">Optional. The cover image of the library.</param>
/// <param name="isEnabled">Whether the library is enabled.</param>
/// <param name="isLocked">Whether the library is locked.</param>
/// <param name="downloadMetadataFromWeb">Whether metadata download from the web is enabled.</param>
/// <param name="shouldSaveMetadataInMediaDirectories">Whether metadata should be saved in the media directories.</param>
/// <param name="shouldSkipUnchangedDirectoriesDuringScan">Whether unchanged directories should be skipped during scan.</param>
/// <param name="scanIds">Optional. The scan Ids associated with the library.</param>
/// <returns>The created <see cref="Library"/>.</returns>
public Library Create(
Guid? id = null,
Guid? userId = null,
string? title = null,
LibraryType? libraryType = null,
IEnumerable<string>? contentLocations = null,
string? coverImage = null,
bool isEnabled = true,
bool isLocked = false,
bool downloadMetadataFromWeb = true,
bool shouldSaveMetadataInMediaDirectories = false,
bool shouldSkipUnchangedDirectoriesDuringScan = false,
IEnumerable<Guid>? scanIds = null)
{
List<string> validPaths =
[
"C:/Media",
"D:/Books",
"E:/Digital Library",
"F:/Content"
];
List<ScanId> resolvedScanIds = scanIds is null ? [ScanId.CreateUnique(), ScanId.CreateUnique()] : [.. scanIds.Select(scanId => ScanId.Create(scanId))];
Result<Library> library = id is null ?
Library.Create(
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
libraryType ?? _faker.PickRandom<LibraryType>(),
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
coverImage ?? _faker.System.FilePath(),
isEnabled,
isLocked,
downloadMetadataFromWeb,
shouldSaveMetadataInMediaDirectories,
shouldSkipUnchangedDirectoriesDuringScan,
resolvedScanIds
) :
Library.Create(
LibraryId.Create(id.Value),
userId is not null ? UserId.Create(userId.Value) : UserId.CreateUnique(),
title ?? _faker.Random.String2(_faker.Random.Number(1, 50)),
libraryType ?? _faker.PickRandom<LibraryType>(),
contentLocations ?? validPaths.Take(_random.Next(1, validPaths.Count)),
coverImage ?? _faker.System.FilePath(),
isEnabled,
isLocked,
downloadMetadataFromWeb,
shouldSaveMetadataInMediaDirectories,
shouldSkipUnchangedDirectoriesDuringScan,
resolvedScanIds
);
return library.Value;
}
/// <summary>
/// Creates multiple <see cref="Library"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Library"/> instances.</returns>
public List<Library> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -1,7 +1,5 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Lumina.Application.UnitTests.Common.Setup;
using Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Common.ValueObjects.Metadata;
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
@@ -9,6 +7,8 @@ using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Boo
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.ExternalIdentifiers.LibraryManagementBoundedContext.LibraryAggregate;
using Lumina.Domain.Fixtures.Common.Setup;
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
@@ -16,36 +16,33 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
/// <summary>
/// Fixture class for the <see cref="Book"/> domain entity.
/// Fixture class for the <see cref="Book"/> domain aggregate.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookFixture
{
private readonly Fixture _fixture;
private readonly IsbnFixture _isbnFixture;
private readonly BookRatingFixture _bookRatingFixture;
private readonly Fixture _fixture = new();
private readonly IsbnFixture _isbnFixture = new();
private readonly BookRatingFixture _bookRatingFixture = new();
/// <summary>
/// Initializes a new instance of the <see cref="BookFixture"/> class.
/// </summary>
public BookFixture()
{
_fixture = new Fixture();
_fixture.Customizations.Add(new DateOnlySpecimenBuilder());
_fixture.Customizations.Add(new NullableDateOnlySpecimenBuilder());
_isbnFixture = new IsbnFixture();
_bookRatingFixture = new BookRatingFixture();
ConfigureCustomDomainTypes();
}
/// <summary>
/// Creates a random valid book domain entity.
/// Creates a random valid <see cref="Book"/> domain aggregate.
/// </summary>
/// <returns>The created book domain entity.</returns>
public Book CreateDomainBook()
/// <returns>The created <see cref="Book"/> domain aggregate.</returns>
public Book Create()
{
return Book.Create(
LibraryId.Create(_fixture.Create<Guid>()),
@@ -70,6 +67,16 @@ public class BookFixture
).Value;
}
/// <summary>
/// Creates multiple <see cref="Book"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Book"/> instances.</returns>
public List<Book> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
private void ConfigureCustomDomainTypes()
{
_fixture.Register(() => Optional<string>.Some(_fixture.Create<string>()));
@@ -77,8 +84,8 @@ public class BookFixture
_fixture.Register(() =>
{
int originalYear = _fixture.Create<Generator<int>>().First(y => y >= 1900 && y <= 2025);
int reReleaseYear = _fixture.Create<Generator<int>>().First(y => y >= originalYear && y <= 2025);
int originalYear = _fixture.Create<Generator<int>>().First(year => year >= 1900 && year <= 2025);
int reReleaseYear = _fixture.Create<Generator<int>>().First(year => year >= originalYear && year <= 2025);
return ReleaseInfo.Create(
Optional<DateOnly>.Some(DateOnly.FromDateTime(new DateTime(originalYear, 1, 1))),
@@ -111,8 +118,8 @@ public class BookFixture
_fixture.Create<Optional<int>>()
).Value);
_fixture.Register(() => _isbnFixture.CreateIsbn13());
_fixture.Register(() => _isbnFixture.Create());
_fixture.Register(() => _bookRatingFixture.CreateBookRating());
_fixture.Register(() => _bookRatingFixture.Create());
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="BookRating"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookRatingFixture
{
private readonly Fixture _fixture = new();
private readonly Random _random = new();
/// <summary>
/// Creates a random valid <see cref="BookRating"/>.
/// </summary>
/// <param name="value">Optional. The rating value.</param>
/// <param name="maxValue">Optional. The maximum possible rating value.</param>
/// <param name="source">Optional. The rating source. If not provided, a random source is selected.</param>
/// <param name="voteCount">Optional. The number of votes. If not provided, a random vote count is selected.</param>
/// <returns>The created <see cref="BookRating"/>.</returns>
public BookRating Create(
decimal? value = null,
decimal? maxValue = null,
Optional<BookRatingSource>? source = null,
Optional<int>? voteCount = null)
{
maxValue ??= _random.Next(5, 10);
value ??= _random.Next(1, (int)maxValue.Value);
source ??= Optional<BookRatingSource>.Some(_fixture.Create<BookRatingSource>());
voteCount ??= Optional<int>.Some(_random.Next(1, 1000));
return BookRating.Create(value.Value, maxValue.Value, source.Value, voteCount.Value).Value;
}
/// <summary>
/// Creates multiple <see cref="BookRating"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="BookRating"/> instances.</returns>
public List<BookRating> CreateMany(int count = 3)
{
List<BookRating> result = [];
for (int i = 0; i < count; i++)
result.Add(Create());
return result;
}
}
@@ -1,14 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.UnitTests.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Common.Fixtures;
namespace Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
/// <summary>
/// Fixture class for the <see cref="Isbn"/> domain entity.
/// Fixture class for the <see cref="Isbn"/> domain value object.
/// </summary>
[ExcludeFromCodeCoverage]
public class IsbnFixture
@@ -16,23 +17,28 @@ public class IsbnFixture
private readonly Random _random = new();
/// <summary>
/// Creates a valid ISBN-10.
/// Creates a valid <see cref="Isbn"/> with a random or explicitly requested format.
/// </summary>
/// <returns>The created ISBN.</returns>
public Isbn CreateIsbn10()
/// <param name="format">Optional. The requested <see cref="IsbnFormat"/>. If not provided, a random format is selected.</param>
/// <returns>The created <see cref="Isbn"/>.</returns>
public Isbn Create(IsbnFormat? format = null)
{
string isbn = GenerateValidIsbn10();
return Isbn.Create(isbn, IsbnFormat.Isbn10).Value;
IsbnFormat targetFormat = format ?? (_random.Next(2) == 0 ? IsbnFormat.Isbn10 : IsbnFormat.Isbn13);
string isbn = targetFormat == IsbnFormat.Isbn10 ? GenerateValidIsbn10() : GenerateValidIsbn13();
return Isbn.Create(isbn, targetFormat).Value;
}
/// <summary>
/// Creates a valid ISBN-13.
/// Creates multiple <see cref="Isbn"/> instances with randomized test data.
/// </summary>
/// <returns>The created ISBN.</returns>
public Isbn CreateIsbn13()
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="Isbn"/> instances.</returns>
public List<Isbn> CreateMany(int count = 3)
{
string isbn = GenerateValidIsbn13();
return Isbn.Create(isbn, IsbnFormat.Isbn13).Value;
List<Isbn> result = [];
for (int i = 0; i < count; i++)
result.Add(Create());
return result;
}
private string GenerateValidIsbn10()
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoFixture" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.AutoNSubstitute" Version="5.0.0-preview0011" />
<PackageReference Include="AutoFixture.Xunit2" Version="5.0.0-preview0011" />
<PackageReference Include="Bogus" Version="35.6.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Domain\Lumina.Domain.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Lumina.Domain.Fixtures")]
[assembly: AssemblyProduct("Lumina.Domain.Fixtures")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("A1B2C3D4-0001-4A5B-9C0D-111111111111")]
[assembly: InternalsVisibleTo("Lumina.Domain.UnitTests")]
[assembly: InternalsVisibleTo("Lumina.Application.UnitTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -9,17 +9,17 @@ using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Xunit;
#endregion
namespace Lumina.Domain.UnitTests.Core.Aggregates.FileSystemManagementAggregate.Services.Fixtures;
namespace Lumina.Domain.SharedKernel.Fixtures.Common.Enums.PhotoLibrary;
/// <summary>
/// Fixture class for the <see cref="ImageType"/> enum.
/// Test-support class providing image byte data for each supported <see cref="ImageType"/>.
/// </summary>
[ExcludeFromCodeCoverage]
public class ImageTypeFixture : TheoryData<ImageType, byte[]>
{
/// <summary>
/// Initializes a new instance of the <see cref="ImageTypeFixture"/> class.
/// </summary>
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
<BaseOutputPath>$(SolutionDir)..\bin\api\</BaseOutputPath>
<IsPackable>false</IsPackable>
<IsTestProject>false</IsTestProject>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.5" />
<PackageReference Include="xunit" Version="2.9.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Lumina.Domain.SharedKernel\Lumina.Domain.SharedKernel.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Lumina.Domain.SharedKernel.Fixtures")]
[assembly: AssemblyProduct("Lumina.Domain.SharedKernel.Fixtures")]
[assembly: ComVisible(false)]
[assembly: Guid("A6BC3F8B-CAB8-4F3B-BD89-B7428697DE61")]
[assembly: InternalsVisibleTo("Lumina.Domain.UnitTests")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
@@ -0,0 +1,43 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography;
#endregion
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
/// <summary>
/// Fixture class for the <see cref="EncryptionSettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class EncryptionSettingsDtoFixture
{
/// <summary>
/// Creates a valid <see cref="EncryptionSettingsDto"/> with a random 256-bit key.
/// </summary>
/// <param name="secretKey">Optional. The secret key. If not provided, a valid 256-bit (32 byte) key for AES-256 is generated.</param>
/// <returns>The created <see cref="EncryptionSettingsDto"/>.</returns>
public EncryptionSettingsDto Create(string? secretKey = null)
{
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
return new EncryptionSettingsDto
{
SecretKey = secretKey ?? Convert.ToBase64String(key)
};
}
/// <summary>
/// Creates a list of <see cref="EncryptionSettingsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="EncryptionSettingsDto"/> instances.</returns>
public List<EncryptionSettingsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,56 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Cryptography;
#endregion
namespace Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
/// <summary>
/// Fixture class for the <see cref="JwtSettingsDto"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class JwtSettingsDtoFixture
{
private readonly Faker _faker = new();
/// <summary>
/// Creates a valid <see cref="JwtSettingsDto"/>.
/// </summary>
/// <param name="secretKey">Optional. The secret key used to sign the JWT.</param>
/// <param name="expiryMinutes">Optional. The duration (in minutes) for which the JWT is valid.</param>
/// <param name="issuer">Optional. The issuer of the JWT.</param>
/// <param name="audience">Optional. The intended audience for the JWT.</param>
/// <returns>The created <see cref="JwtSettingsDto"/>.</returns>
public JwtSettingsDto Create(
string? secretKey = null,
int? expiryMinutes = null,
string? issuer = null,
string? audience = null)
{
byte[] key = new byte[32];
RandomNumberGenerator.Fill(key);
return new JwtSettingsDto
{
SecretKey = secretKey ?? Convert.ToBase64String(key),
ExpiryMinutes = expiryMinutes ?? _faker.Random.Int(1, 120),
Issuer = issuer ?? _faker.Company.CompanyName(),
Audience = audience ?? _faker.Company.CompanyName()
};
}
/// <summary>
/// Creates a list of <see cref="JwtSettingsDto"/> instances with randomized test data.
/// </summary>
/// <param name="count">Number of instances to create.</param>
/// <returns>List of configured <see cref="JwtSettingsDto"/> instances.</returns>
public List<JwtSettingsDto> CreateMany(int count = 3)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -2,10 +2,10 @@
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Infrastructure.UnitTests.Common.Utilities.Fixtures;
namespace Lumina.Infrastructure.Fixtures.Common.Utilities;
/// <summary>
/// Contains unit tests for the <see cref="OptionsBuilderValidationUtilitiesTests"/> class.
/// Test-support placeholder class for options builder validation utilities tests.
/// </summary>
[ExcludeFromCodeCoverage]
public class OptionsBuilderValidationUtilitiesFixture
@@ -2,10 +2,10 @@
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Infrastructure.UnitTests.Common.Validation.Fixtures;
namespace Lumina.Infrastructure.Fixtures.Common.Validation;
/// <summary>
/// Contains unit tests for the <see cref="ValidationOptionsTests"/> class.
/// Test-support placeholder class for validation options tests.
/// </summary>
[ExcludeFromCodeCoverage]
public class ValidationOptionsFixture
@@ -1,14 +1,15 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Infrastructure.Common.Models.DTO.Configuration;
using Lumina.Infrastructure.Fixtures.Common.Models.DTO.Configuration;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Infrastructure.UnitTests.Core.Authentication.Fixtures;
namespace Lumina.Infrastructure.Fixtures.Core.Authentication;
/// <summary>
/// Fixture class for JWT token generation tests.
/// Test-support class for JWT token generation tests.
/// </summary>
[ExcludeFromCodeCoverage]
public class JwtTokenGeneratorFixture
@@ -19,15 +20,7 @@ public class JwtTokenGeneratorFixture
/// <returns>The created settings model.</returns>
public static JwtSettingsDto CreateJwtSettings()
{
return new Faker<JwtSettingsDto>()
.CustomInstantiator(f => new JwtSettingsDto
{
SecretKey = "this-is-a-very-long-secret-key-for-testing-jwt-tokens",
ExpiryMinutes = 30,
Issuer = "test-issuer",
Audience = "test-audience"
})
.Generate();
return new JwtSettingsDtoFixture().Create();
}
/// <summary>
Loaded 100 of 356 files, more files were not shown because too many files have changed in this diff. Show more