Centralizes and standardizes test fixtures.

This commit is contained in:
BinaryAlley committed 2026-08-15 02:58:17 -07:00
1 parent dfc513da4f
commit b648e2f054
294 files changed
+3807 -4437

No files matched your search

@@ -0,0 +1,48 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="PermissionEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PermissionEntityFixture
{
/// <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 Create(Guid? id = null, AuthorizationPermission? permissionName = null)
{
return new Faker<PermissionEntity>()
.RuleFor(x => x.Id, f => id ?? f.Random.Guid())
.RuleFor(x => x.PermissionName, f => permissionName ?? f.PickRandom<AuthorizationPermission>())
.RuleFor(x => x.RolePermissions, [])
.RuleFor(x => x.UserPermissions, [])
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.CreatedBy, f => f.Random.Guid())
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
.RuleFor(x => x.UpdatedBy, f => f.Random.Guid())
.Generate();
}
/// <summary>
/// Creates a list of <see cref="PermissionEntity"/> instances with randomized test data.
/// </summary>
/// <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)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,80 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="RolePermissionEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class RolePermissionEntityFixture
{
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="RolePermissionEntityFixture"/> class.
/// </summary>
public RolePermissionEntityFixture()
{
_faker = new Faker();
}
/// <summary>
/// Creates a random valid <see cref="RolePermissionEntity"/>.
/// </summary>
/// <returns>The created <see cref="RolePermissionEntity"/>.</returns>
public RolePermissionEntity Create()
{
PermissionEntity permission = new()
{
Id = _faker.Random.Guid(),
PermissionName = _faker.PickRandom<AuthorizationPermission>(),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid(),
UpdatedOnUtc = _faker.Date.Recent(),
UpdatedBy = _faker.Random.Guid()
};
RoleEntity role = new()
{
Id = _faker.Random.Guid(),
RoleName = _faker.Random.String2(10),
CreatedOnUtc = _faker.Date.Past(),
CreatedBy = _faker.Random.Guid(),
UpdatedOnUtc = _faker.Date.Recent(),
UpdatedBy = _faker.Random.Guid()
};
return new Faker<RolePermissionEntity>()
.CustomInstantiator(f => new RolePermissionEntity
{
Id = f.Random.Guid(),
RoleId = role.Id,
Role = role,
PermissionId = permission.Id,
Permission = permission,
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid(),
UpdatedOnUtc = f.Date.Recent(),
UpdatedBy = f.Random.Guid()
})
.Generate();
}
/// <summary>
/// Creates a list of <see cref="RolePermissionEntity"/> instances with randomized test data.
/// </summary>
/// <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)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,50 @@
#region ========================================================================= USING =====================================================================================
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.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="UserAuthorizationEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserAuthorizationEntityFixture
{
/// <summary>
/// Creates a random valid authorization entity.
/// </summary>
/// <param name="userId">Optional. The user Id to use. If null, a random GUID will be generated.</param>
/// <param name="isAdmin">Whether the user should have admin role.</param>
/// <returns>The created entity.</returns>
public UserAuthorizationEntity Create(Guid? userId = null, bool isAdmin = false)
{
string role = isAdmin ? "Admin" : string.Empty;
return new UserAuthorizationEntity
{
UserId = userId ?? Guid.NewGuid(),
Role = role,
Permissions = new HashSet<AuthorizationPermission>
{
AuthorizationPermission.CanViewUsers,
AuthorizationPermission.CanRegisterUsers
}
};
}
/// <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))];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="UserPermissionEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserPermissionEntityFixture
{
/// <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 Create(UserEntity user, PermissionEntity permission)
{
return new Faker<UserPermissionEntity>()
.CustomInstantiator(f => new UserPermissionEntity
{
Id = f.Random.Guid(),
UserId = user.Id,
User = user,
PermissionId = permission.Id,
Permission = permission,
CreatedOnUtc = f.Date.Past(),
CreatedBy = user.Id,
UpdatedOnUtc = f.Random.Bool() ? f.Date.Recent() : null,
UpdatedBy = f.Random.Bool() ? user.Id : null
})
.Generate();
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Authorization;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.Authorization;
/// <summary>
/// Fixture class for the <see cref="UserRoleEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserRoleEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="UserRoleEntity"/>.
/// </summary>
/// <returns>The created <see cref="UserRoleEntity"/>.</returns>
public UserRoleEntity Create()
{
return new Faker<UserRoleEntity>()
.CustomInstantiator(f => new UserRoleEntity
{
Id = f.Random.Guid(),
UserId = f.Random.Guid(),
User = new()
{
Id = f.Random.Guid(),
Username = f.Internet.UserName(),
Password = f.Internet.Password(),
Libraries = [],
UserRole = null,
UserPermissions = [],
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
},
RoleId = f.Random.Guid(),
Role = new()
{
Id = f.Random.Guid(),
RoleName = f.Random.String2(f.Random.Number(1, 50)),
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
},
CreatedOnUtc = f.Date.Past(),
CreatedBy = f.Random.Guid()
})
.Generate();
}
/// <summary>
/// Creates a list of <see cref="UserRoleEntity"/> instances with randomized test data.
/// </summary>
/// <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)
{
return [.. Enumerable.Range(0, count).Select(_ => Create())];
}
}
@@ -0,0 +1,240 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Common;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
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;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
/// <summary>
/// Fixture class for the <see cref="BookEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class BookEntityFixture
{
private readonly Random _random = new();
private readonly Faker _faker;
/// <summary>
/// Initializes a new instance of the <see cref="BookEntityFixture"/> class.
/// </summary>
public BookEntityFixture()
{
_faker = new Faker();
}
/// <summary>
/// Creates a random valid <see cref="BookEntity"/>.
/// </summary>
/// <returns>The created <see cref="BookEntity"/>.</returns>
public BookEntity Create()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
return new Faker<BookEntity>()
.RuleFor(x => x.Id, f => f.Random.Guid())
.RuleFor(x => x.LibraryId, f => f.Random.Guid())
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.LanguageCode, f => f.Random.String2(2))
.RuleFor(x => x.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.LanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.OriginalLanguageCode, f => f.Random.String2(2))
.RuleFor(x => x.OriginalLanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.OriginalLanguageNativeName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.Tags, f => [.. CreateTags(f.Random.Number(1, 5))])
.RuleFor(x => x.Genres, f => [.. CreateGenres(f.Random.Number(1, 5))])
.RuleFor(x => x.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>())
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
.RuleFor(x => x.GoodreadsId, _random.Next(100000, 500000).ToString())
.RuleFor(x => x.LCCN, CreateLCCN)
.RuleFor(x => x.OCLCNumber, CreateOCLCNumber)
.RuleFor(x => x.OpenLibraryId, CreateOpenLibraryId)
.RuleFor(x => x.LibraryThingId, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.GoogleBooksId, CreateGoogleBooksId)
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.RuleFor(x => x.AppleBooksId, f => $"id{f.Random.Number(1, 999999)}")
.RuleFor(x => x.ISBNs, f => CreateIsbns(f.Random.Number(1, 5)))
.RuleFor(x => x.Ratings, f => CreateBookRatings(f.Random.Number(1, 5)))
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.UpdatedOnUtc, f => f.Date.Recent())
.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>
/// <param name="count">The number of tags to create.</param>
/// <returns>A list of randomly generated tag entities.</returns>
private static List<TagEntity> CreateTags(int count)
{
return new Faker<TagEntity>()
.CustomInstantiator(f => new TagEntity(f.Random.String2(f.Random.Number(1, 50))))
.Generate(count);
}
/// <summary>
/// Creates a list of genre entities with random data.
/// </summary>
/// <param name="count">The number of genres to create.</param>
/// <returns>A list of randomly generated genre entities.</returns>
private static List<GenreEntity> CreateGenres(int count)
{
return new Faker<GenreEntity>()
.CustomInstantiator(f => new GenreEntity(f.Random.String2(f.Random.Number(1, 50))))
.Generate(count);
}
/// <summary>
/// Creates a valid Library of Congress Control Number (LCCN).
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <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'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
}
/// <summary>
/// Creates a valid OCLC (Online Computer Library Center) number.
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <returns>A properly formatted OCLC number string with valid prefix.</returns>
private string CreateOCLCNumber(Faker f)
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = f.Random.ArrayElement(prefixes);
string number = prefix switch
{
"ocm" => f.Random.String2(8, "0123456789"),
"ocn" => f.Random.String2(f.Random.Number(9, 11), "0123456789"),
"on" => f.Random.String2(10, "0123456789"),
"(OCoLC)" => f.Random.String2(f.Random.Number(8, 10), "0123456789"),
_ => f.Random.String2(f.Random.Number(8, 10), "0123456789")
};
return prefix + number;
}
/// <summary>
/// Creates a valid Open Library ID.
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <returns>A properly formatted Open Library ID string.</returns>
private string CreateOpenLibraryId(Faker f)
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
char suffix = f.Random.ArrayElement(['A', 'M', 'W']);
return $"OL{firstDigit}{remainingDigits}{suffix}";
}
/// <summary>
/// Creates a valid Google Books ID.
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <returns>A properly formatted Google Books ID string.</returns>
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)])]);
}
/// <summary>
/// Creates a list of ISBN entities with random data.
/// </summary>
/// <param name="count">The number of ISBNs to create.</param>
/// <returns>A list of randomly generated ISBN entities.</returns>
private static List<IsbnEntity> CreateIsbns(int count)
{
return new Faker<IsbnEntity>()
.CustomInstantiator(f =>
{
string isbnValue = CreateIsbn(f);
return new IsbnEntity(isbnValue, isbnValue.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
})
.Generate(count);
}
/// <summary>
/// Creates a valid ISBN (International Standard Book Number).
/// </summary>
/// <param name="f">The Faker instance used for generating random data.</param>
/// <returns>A properly formatted ISBN-10 or ISBN-13 string with valid checksum.</returns>
private static string CreateIsbn(Faker f)
{
bool isIsbn13 = f.Random.Bool();
if (isIsbn13)
{
string prefix = f.Random.Bool() ? "978" : "979";
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
int sum = 0;
for (int i = 0; i < 12; i++)
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
int checkDigit = (10 - (sum % 10)) % 10;
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
}
else
{
int[] digits = new int[9];
for (int i = 0; i < 9; i++)
digits[i] = f.Random.Number(0, 9);
int sum = 0;
for (int i = 0; i < 9; i++)
sum += (10 - i) * digits[i];
int checkDigit = (11 - (sum % 11)) % 11;
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
}
}
/// <summary>
/// Creates a list of book rating entities with random data.
/// </summary>
/// <param name="count">The number of ratings to create.</param>
/// <returns>A list of randomly generated book rating entities.</returns>
private static List<BookRatingEntity> CreateBookRatings(int count)
{
return new Faker<BookRatingEntity>()
.CustomInstantiator(f => new BookRatingEntity(
f.Random.Decimal(1, 5),
5,
f.PickRandom<BookRatingSource>(),
f.Random.Number(1, 1000)
))
.Generate(count);
}
}
@@ -0,0 +1,63 @@
#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;
/// <summary>
/// Initializes a new instance of the <see cref="BookRatingEntityFixture"/> class.
/// </summary>
public BookRatingEntityFixture()
{
_faker = new Faker();
}
/// <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())];
}
}
@@ -0,0 +1,52 @@
#region ========================================================================= USING =====================================================================================
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.Application.Fixtures.Common.DataAccess.Entities.Plugins;
/// <summary>
/// Fixture class for the <see cref="LibraryMetadataProviderConfigurationEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class LibraryMetadataProviderConfigurationEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="LibraryMetadataProviderConfigurationEntity"/> for the provided media library, plugin and rank.
/// </summary>
/// <param name="libraryId">The Id of the media library the configuration belongs to.</param>
/// <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 Create(Guid libraryId, Guid pluginId, int rank)
{
return new Faker<LibraryMetadataProviderConfigurationEntity>()
.RuleFor(configuration => configuration.Id, faker => faker.Random.Guid())
.RuleFor(configuration => configuration.LibraryId, libraryId)
.RuleFor(configuration => configuration.PluginId, pluginId)
.RuleFor(configuration => configuration.IsEnabled, faker => faker.Random.Bool())
.RuleFor(configuration => configuration.Rank, rank)
.RuleFor(configuration => configuration.CreatedOnUtc, faker => faker.Date.Past())
.RuleFor(configuration => configuration.CreatedBy, faker => faker.Random.Guid())
.RuleFor(configuration => configuration.UpdatedOnUtc, faker => faker.Date.Recent())
.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))];
}
}
@@ -0,0 +1,51 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
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.Application.Fixtures.Common.DataAccess.Entities.Plugins;
/// <summary>
/// Fixture class for the <see cref="PluginEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class PluginEntityFixture
{
/// <summary>
/// Creates a random valid <see cref="PluginEntity"/>.
/// </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 Create(Guid? id = null)
{
return new Faker<PluginEntity>()
.RuleFor(plugin => plugin.Id, faker => id ?? faker.Random.Guid())
.RuleFor(plugin => plugin.Name, faker => faker.Company.CompanyName())
.RuleFor(plugin => plugin.Author, faker => faker.Name.FullName())
.RuleFor(plugin => plugin.Version, faker => faker.System.Semver())
.RuleFor(plugin => plugin.Description, faker => faker.Lorem.Sentence())
.RuleFor(plugin => plugin.LoadStatus, faker => faker.PickRandom<PluginLoadStatus>())
.RuleFor(plugin => plugin.SettingsJson, faker => JsonSerializer.Serialize(new Dictionary<string, string> { [faker.Random.String2(1, 10)] = faker.Random.String2(1, 20) }))
.RuleFor(plugin => plugin.CreatedOnUtc, faker => faker.Date.Past())
.RuleFor(plugin => plugin.CreatedBy, faker => faker.Random.Guid())
.RuleFor(plugin => plugin.UpdatedOnUtc, faker => faker.Date.Recent())
.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())];
}
}
@@ -0,0 +1,86 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Common.DataAccess.Entities.UsersManagement;
/// <summary>
/// Fixture class for the <see cref="UserEntity"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserEntityFixture
{
/// <summary>
/// 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 UserEntity Create(int libraryCount = 0)
{
Guid userId = Guid.NewGuid();
List<LibraryEntity> libraries = libraryCount > 0
? CreateLibraries(libraryCount, userId)
: [];
return new Faker<UserEntity>()
.CustomInstantiator(f => new UserEntity
{
Id = userId,
Username = default!,
Password = default!,
CreatedOnUtc = default,
TotpSecret = default,
Libraries = libraries,
UserPermissions = [],
UserRole = null,
CreatedBy = userId
})
.RuleFor(x => x.Username, f => f.Internet.UserName())
.RuleFor(x => x.Password, f => Uri.EscapeDataString(f.Internet.Password()))
.RuleFor(x => x.CreatedOnUtc, f => f.Date.Past())
.RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null)
.Generate();
}
/// <summary>
/// Creates a list of <see cref="UserEntity"/> instances with randomized test data.
/// </summary>
/// <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(_ => 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);
}
}
@@ -0,0 +1,38 @@
#region ========================================================================= USING =====================================================================================
using Bogus;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Contains extension methods for the <see cref="Faker"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public static class BogusExtensions
{
/// <summary>
/// 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>
public static DateOnly DateOnly(this Faker faker)
{
return System.DateOnly.FromDateTime(faker.Date.Past());
}
/// <summary>
/// Adds <see cref="DateOnly"/> random data generation within a specified interval support to the <see cref="Faker"/> class.
/// </summary>
/// <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>
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));
}
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture.Kernel;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly"/> type.
/// </summary>
[ExcludeFromCodeCoverage]
public class DateOnlySpecimenBuilder : ISpecimenBuilder
{
/// <summary>
/// Adds <see cref="DateOnly"/> support to the AutoFixture library.
/// </summary>
/// <param name="request">The request to process.</param>
/// <param name="context">The context within which the specimen is created.</param>
/// <returns>A specimen based on the request.</returns>
public object Create(object request, ISpecimenContext context)
{
if (request is Type type && type == typeof(DateOnly))
return DateOnly.FromDateTime(DateTime.Now);
return new NoSpecimen();
}
}
@@ -0,0 +1,27 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture.Kernel;
using System;
using System.Diagnostics.CodeAnalysis;
#endregion
namespace Lumina.Application.Fixtures.Common.Setup;
/// <summary>
/// Represents a specimen builder for the <see cref="DateOnly?"/> type.
/// </summary>
[ExcludeFromCodeCoverage]
public class NullableDateOnlySpecimenBuilder : ISpecimenBuilder
{
/// <summary>
/// Adds <see cref="DateOnly?"/> support to the AutoFixture library.
/// </summary>
/// <param name="request">The request to process.</param>
/// <param name="context">The context within which the specimen is created.</param>
/// <returns>A specimen based on the request.</returns>
public object Create(object request, ISpecimenContext context)
{
if (request is Type type && type == typeof(DateOnly?))
return (DateOnly?)DateOnly.FromDateTime(DateTime.Now);
return new NoSpecimen();
}
}
@@ -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())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
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.Fixtures.Core.Admin.Authorization.Roles.Commands.DeleteRole;
/// <summary>
/// Fixture class for the <see cref="DeleteRoleCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 Create(Guid? roleId = null)
{
return new Faker<DeleteRoleCommand>()
.CustomInstantiator(f => new DeleteRoleCommand(
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())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
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.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRolePermissions;
/// <summary>
/// Fixture class for the <see cref="GetRolePermissionsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 Create(Guid? roleId = null)
{
return new Faker<GetRolePermissionsQuery>()
.CustomInstantiator(f => new GetRolePermissionsQuery(
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())];
}
}
@@ -0,0 +1,34 @@
#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.Fixtures.Core.Admin.Authorization.Roles.Queries.GetRoles;
/// <summary>
/// Fixture class for the <see cref="GetRolesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetRolesQueryFixture
{
/// <summary>
/// Creates a random valid query to get roles.
/// </summary>
/// <returns>The created query.</returns>
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())];
}
}
@@ -0,0 +1,43 @@
#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.Fixtures.Core.FileSystemManagement.Directories.Queries.GetDirectories;
/// <summary>
/// Fixture class for the <see cref="GetDirectoriesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 GetDirectoriesQuery Create(string? path = null, bool includeHiddenElements = false)
{
return new Faker<GetDirectoriesQuery>()
.CustomInstantiator(f => new GetDirectoriesQuery(
default!,
default
))
.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())];
}
}
@@ -0,0 +1,43 @@
#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.Fixtures.Core.FileSystemManagement.Files.Queries.GetFiles;
/// <summary>
/// Fixture class for the <see cref="GetFilesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 GetFilesQuery Create(string? path = null, bool includeHiddenElements = false)
{
return new Faker<GetFilesQuery>()
.CustomInstantiator(f => new GetFilesQuery(
default!,
default
))
.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())];
}
}
@@ -0,0 +1,43 @@
#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.Fixtures.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
/// <summary>
/// Fixture class for the <see cref="GetTreeFilesQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetTreeFilesQueryFixture
{
/// <summary>
/// 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 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 => 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())];
}
}
@@ -0,0 +1,39 @@
#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.Fixtures.Core.FileSystemManagement.Paths.Commands.SplitPath;
/// <summary>
/// Fixture class for the <see cref="SplitPathCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 SplitPathCommand Create(string? path = null)
{
return new Faker<SplitPathCommand>()
.CustomInstantiator(f => new SplitPathCommand(
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())];
}
}
@@ -0,0 +1,43 @@
#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.Fixtures.Core.FileSystemManagement.Paths.Queries.CheckPathExists;
/// <summary>
/// Fixture class for the <see cref="CheckPathExistsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 CheckPathExistsQuery Create(string? path = null, bool includeHiddenElements = true)
{
return new Faker<CheckPathExistsQuery>()
.CustomInstantiator(f => new CheckPathExistsQuery(
default!,
default
))
.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())];
}
}
@@ -0,0 +1,273 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using Bogus;
using Lumina.Application.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
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.Diagnostics.CodeAnalysis;
using System.Linq;
#endregion
namespace Lumina.Application.Fixtures.Core.MediaLibrary.WrittenContentLibrary.BooksLibrary.Books.Commands.AddBook;
/// <summary>
/// Fixture class for the <see cref="AddBookCommand"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class AddBookCommandFixture
{
private readonly Fixture _fixture;
private readonly Random _random = new();
private readonly Faker _faker;
/// <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 Create()
{
int releaseYear = _random.Next(2000, 2010);
int reReleaseYear = _random.Next(2010, 2020);
ReleaseInfoDto releaseInfo = new Faker<ReleaseInfoDto>()
.CustomInstantiator(f => new ReleaseInfoDto(
default,
default,
default,
default,
default,
default
))
.RuleFor(x => x.OriginalReleaseDate, _faker.DateOnlyBetween(new DateOnly(releaseYear, 1, 1), new DateOnly(releaseYear, 12, 31)))
.RuleFor(x => x.OriginalReleaseYear, releaseYear)
.RuleFor(x => x.ReReleaseDate, _faker.DateOnlyBetween(new DateOnly(reReleaseYear, 1, 1), new DateOnly(reReleaseYear, 12, 31)))
.RuleFor(x => x.ReReleaseYear, reReleaseYear)
.RuleFor(x => x.ReleaseCountry, f => f.Random.String2(2))
.RuleFor(x => x.ReleaseVersion, f => f.Random.String2(f.Random.Number(1, 50)))
.Generate();
Faker<GenreDto> genre = new Faker<GenreDto>()
.CustomInstantiator(f => new GenreDto(
default!
))
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<TagDto> tag = new Faker<TagDto>()
.CustomInstantiator(f => new TagDto(
default!
))
.RuleFor(e => e.Name, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<MediaContributorRoleDto> mediaContributorRole = new Faker<MediaContributorRoleDto>()
.CustomInstantiator(f => new MediaContributorRoleDto(
default!,
default!
))
.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!,
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(
default!,
default!
))
.RuleFor(e => e.Name, mediaContributorName)
.RuleFor(e => e.Role, mediaContributorRole);
Faker<BookRatingDto> rating = new Faker<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));
Faker<LanguageInfoDto> language = new Faker<LanguageInfoDto>()
.CustomInstantiator(f => new LanguageInfoDto(
default!,
default!,
default
))
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<LanguageInfoDto> originalLanguage = new Faker<LanguageInfoDto>()
.CustomInstantiator(f => new LanguageInfoDto(
default!,
default!,
default
))
.RuleFor(e => e.LanguageName, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(e => e.LanguageCode, f => f.Random.String2(2))
.RuleFor(e => e.NativeName, f => f.Random.String2(f.Random.Number(1, 50)));
Faker<WrittenContentMetadataDto> metadata = new Faker<WrittenContentMetadataDto>()
.CustomInstantiator(f => new WrittenContentMetadataDto(
default!,
default,
default,
default!,
default!,
default!,
default,
default,
default,
default
))
.RuleFor(x => x.Title, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.OriginalTitle, f => f.Random.String2(f.Random.Number(1, 255)))
.RuleFor(x => x.Description, f => f.Random.String2(f.Random.Number(1, 2000)))
.RuleFor(x => x.ReleaseInfo, releaseInfo)
.RuleFor(p => p.Genres, f => genre.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Tags, f => tag.Generate(f.Random.Number(1, 5)))
.RuleFor(x => x.Language, language)
.RuleFor(x => x.OriginalLanguage, originalLanguage)
.RuleFor(x => x.Publisher, f => f.Random.String2(f.Random.Number(1, 100)))
.RuleFor(x => x.PageCount, _random.Next(100, 300));
Faker<IsbnDto> isbn = new Faker<IsbnDto>()
.CustomInstantiator(f => new IsbnDto(
default!,
default
))
.RuleFor(i => i.Value, f =>
{
bool isIsbn13 = f.Random.Bool();
if (isIsbn13)
{
string prefix = f.Random.Bool() ? "978" : "979";
string group = f.Random.Number(0, 99999).ToString().PadLeft(5, '0');
string publisher = f.Random.Number(0, 999999).ToString().PadLeft(6, '0');
string title = f.Random.Number(0, 99).ToString().PadLeft(2, '0');
string isbn = $"{prefix}{group[..1]}{publisher}{title}";
int sum = 0;
for (int i = 0; i < 12; i++)
sum += (i % 2 == 0 ? 1 : 3) * int.Parse(isbn[i].ToString());
int checkDigit = (10 - sum % 10) % 10;
return $"{prefix}-{group[..1]}-{publisher}-{title}-{checkDigit}";
}
else
{
int[] digits = new int[9];
for (int i = 0; i < 9; i++)
digits[i] = f.Random.Number(0, 9);
int sum = 0;
for (int i = 0; i < 9; i++)
sum += (10 - i) * digits[i];
int checkDigit = (11 - sum % 11) % 11;
string checkChar = checkDigit == 10 ? "X" : checkDigit.ToString();
return $"{digits[0]}-{digits[1]}{digits[2]}-{digits[3]}{digits[4]}{digits[5]}{digits[6]}{digits[7]}{digits[8]}-{checkChar}";
}
})
.RuleFor(i => i.Format, (f, i) => i.Value!.Length > 13 ? IsbnFormat.Isbn13 : IsbnFormat.Isbn10);
return new Faker<AddBookCommand>()
.CustomInstantiator(f => new AddBookCommand(
default,
default!,
default!,
default,
default,
default,
default,
default,
default,
default,
default,
default,
default,
default,
default,
default!,
default!,
default!,
default!
))
.RuleFor(x => x.LibraryId, _fixture.Create<Guid>())
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.Metadata, metadata)
.RuleFor(x => x.Format, _fixture.Create<BookFormat>())
.RuleFor(x => x.Edition, f => f.Random.String2(f.Random.Number(1, 50)))
.RuleFor(x => x.VolumeNumber, _random.Next(1, 3))
.RuleFor(x => x.ASIN, f => f.Random.String2(10))
.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'))]);
string digits = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return letters + digits;
})
.RuleFor(x => x.OCLCNumber, f =>
{
string[] prefixes = ["ocm", "ocn", "on", "(OCoLC)"];
string prefix = f.Random.ArrayElement(prefixes);
string number;
switch (prefix)
{
case "ocm":
number = f.Random.String2(8, "0123456789");
break;
case "ocn":
number = f.Random.String2(f.Random.Number(9, 11), "0123456789");
break;
case "on":
number = f.Random.String2(10, "0123456789");
break;
case "(OCoLC)":
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
break;
default:
number = f.Random.String2(f.Random.Number(8, 10), "0123456789");
return number;
}
return prefix + number;
})
.RuleFor(x => x.OpenLibraryId, f =>
{
int firstDigit = f.Random.Number(1, 9);
string remainingDigits = f.Random.String2(f.Random.Number(0, 6), "0123456789");
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)])]);
})
.RuleFor(x => x.BarnesAndNobleId, f => f.Random.String2(10, "0123456789"))
.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)));
}
}
@@ -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())];
}
}
@@ -0,0 +1,34 @@
#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.Fixtures.Core.UsersManagement.Authentication.Queries.GetUsers;
/// <summary>
/// Fixture class for the <see cref="GetUsersQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
public class GetUsersQueryFixture
{
/// <summary>
/// Creates a random valid query to get users.
/// </summary>
/// <returns>The created query.</returns>
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())];
}
}
@@ -0,0 +1,53 @@
#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.Fixtures.Core.UsersManagement.Authentication.Queries.LoginUser;
/// <summary>
/// Fixture class for the <see cref="LoginUserQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 LoginUserQuery Create(
string? username = null,
string? password = null,
bool includeTotpCode = false)
{
string resolvedPassword = password ?? "Abcd123$";
Faker<LoginUserQuery> faker = new Faker<LoginUserQuery>()
.CustomInstantiator(f => new LoginUserQuery(
default!,
default!,
default
))
.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.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())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
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.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserPermissions;
/// <summary>
/// Fixture class for the <see cref="GetUserPermissionsQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 Create(Guid? userId = null)
{
return new Faker<GetUserPermissionsQuery>()
.CustomInstantiator(f => new GetUserPermissionsQuery(
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())];
}
}
@@ -0,0 +1,40 @@
#region ========================================================================= USING =====================================================================================
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.Fixtures.Core.UsersManagement.Authorization.Queries.GetUserRole;
/// <summary>
/// Fixture class for the <see cref="GetUserRoleQuery"/> class.
/// </summary>
[ExcludeFromCodeCoverage]
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 Create(Guid? userId = null)
{
return new Faker<GetUserRoleQuery>()
.CustomInstantiator(f => new GetUserRoleQuery(
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")]