#region ========================================================================= USING ===================================================================================== using Bogus; using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management; using Lumina.Application.Common.DataAccess.Entities.UsersManagement; using Lumina.Domain.Common.Enums.MediaLibrary; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; #endregion namespace Lumina.Application.UnitTests.Common.Mapping.UserManagement.Users.Fixtures; /// /// Fixture class for the class. /// [ExcludeFromCodeCoverage] public class UserEntityFixture { /// /// Creates a random valid user entity. /// /// Number of libraries to generate. Default is 0. /// The created user entity. public static UserEntity CreateUserEntity(int libraryCount = 0) { Guid userId = Guid.NewGuid(); List libraries = [.. new Faker() .CustomInstantiator(f => new LibraryEntity { Id = Guid.NewGuid(), UserId = userId, Title = f.Commerce.ProductName(), LibraryType = f.PickRandom(), ContentLocations = [], Created = f.Date.Past(), Updated = null }) .Generate(libraryCount)]; return new Faker() .CustomInstantiator(f => new UserEntity { Id = userId, Username = default!, Password = default!, Created = default, TotpSecret = default, Libraries = libraries }) .RuleFor(x => x.Username, f => f.Internet.UserName()) .RuleFor(x => x.Password, f => Uri.EscapeDataString(f.Internet.Password())) .RuleFor(x => x.Created, f => f.Date.Past()) .RuleFor(x => x.TotpSecret, f => f.Random.Bool() ? f.Random.String2(32) : null) .Generate(); } /// /// Creates a list of user entities. /// /// The number of entities to create. /// The created list. public static List CreateMany(int count = 3) { return Enumerable.Range(0, count) .Select(_ => CreateUserEntity()) .ToList(); } }