#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 = [],
CreatedOnUtc = f.Date.Past(),
CreatedBy = userId,
UpdatedOnUtc = null,
UpdatedBy = null
})
.Generate(libraryCount)];
return new Faker()
.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();
}
///
/// 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();
}
}