Adds user Alias. Make StoredDataUrls optionals.
This commit is contained in:
@@ -35,13 +35,13 @@ internal class TestDataSeeder(
|
||||
{
|
||||
if (contentContext.Contents.Any()) return;
|
||||
|
||||
_ = await CreateAdministratorAsync("admin");
|
||||
_ = await CreateUserAsync("userA");
|
||||
_ = await CreateUserAsync("userB");
|
||||
_users.Add(await CreateUserAsync("admin", Roles.Administrator));
|
||||
_users.Add(await CreateUserAsync("userA"));
|
||||
_users.Add(await CreateUserAsync("userB"));
|
||||
|
||||
foreach (var creator in _creators)
|
||||
{
|
||||
_ = await CreateCreatorAsync(creator);
|
||||
_users.Add(await CreateCreatorAsync(creator));
|
||||
|
||||
var contents = GenerateContent(creator, 100);
|
||||
foreach (var content in contents)
|
||||
@@ -96,15 +96,17 @@ internal class TestDataSeeder(
|
||||
for (var m = messageCount; m > 0; m--)
|
||||
{
|
||||
currentDate = currentDate.AddSeconds(-Random.Shared.Next(100, 100_000));
|
||||
var author = Random.Shared.GetItems(_creators, 1)[0];
|
||||
var author = Random.Shared.GetItems(_users.ToArray(), 1).First();
|
||||
|
||||
var message = new Message
|
||||
{
|
||||
Id = GuidHelper.GenerateUuidV7(),
|
||||
SubjectId = content.Id,
|
||||
CreatedBy = Guid.Parse(author.Id),
|
||||
CreatedAt = currentDate,
|
||||
Value = $"Message #{m} from {author.UserName} on {content.Title}"
|
||||
CreatedBy = Guid.Parse(author.Id),
|
||||
CreatedByName = author.Alias ?? $"{author.FirstName} {author.LastName}",
|
||||
CreatedByPortraitUrl = author.StoredDataUrls.ProfilePictureUrl,
|
||||
Value = $"Message #{m} on {content.Title}"
|
||||
};
|
||||
|
||||
messagingContext.Messages.Add(message);
|
||||
@@ -124,7 +126,7 @@ internal class TestDataSeeder(
|
||||
{
|
||||
currentDate = currentDate.AddSeconds(-Random.Shared.Next(100, 100_000));
|
||||
|
||||
var author = Random.Shared.GetItems(_creators, 1)[0];
|
||||
var author = Random.Shared.GetItems(_users.ToArray(), 1).First();
|
||||
|
||||
var message = new Message
|
||||
{
|
||||
@@ -132,8 +134,10 @@ internal class TestDataSeeder(
|
||||
SubjectId = content.Id,
|
||||
ParentId = parent.Id,
|
||||
CreatedBy = Guid.Parse(author.Id),
|
||||
CreatedByName = author.Alias ?? $"{author.FirstName} {author.LastName}",
|
||||
CreatedByPortraitUrl = author.StoredDataUrls.ProfilePictureUrl,
|
||||
CreatedAt = currentDate,
|
||||
Value = $"Reply {r} to {parent.Value}"
|
||||
Value = $"Reply {r} to {parent.Value} on {content.Title}"
|
||||
};
|
||||
|
||||
messagingContext.Messages.Add(message);
|
||||
@@ -144,31 +148,22 @@ internal class TestDataSeeder(
|
||||
return replies;
|
||||
}
|
||||
|
||||
private async Task<ApplicationUser> CreateAdministratorAsync(string name)
|
||||
{
|
||||
ArgumentException.ThrowIfNullOrWhiteSpace(name);
|
||||
|
||||
var administrator = new ApplicationUser { UserName = $"{name}@test", Email = $"{name}@test" };
|
||||
|
||||
await userManager.CreateAsync(administrator, DefaultPassword);
|
||||
await userManager.AddToRolesAsync(administrator, new[] { Roles.Administrator });
|
||||
|
||||
return administrator;
|
||||
}
|
||||
|
||||
private async Task<ApplicationUser> CreateUserAsync(string name)
|
||||
private async Task<ApplicationUser> CreateUserAsync(string name, params string[] roles)
|
||||
{
|
||||
var user = new ApplicationUser
|
||||
{
|
||||
UserName = $"{name}@test",
|
||||
Email = $"{name}@test",
|
||||
EmailConfirmed = true,
|
||||
Alias = name,
|
||||
FirstName = $"FirstName of {name}",
|
||||
LastName = $"LastName of {name}"
|
||||
};
|
||||
|
||||
await userManager.CreateAsync(user, DefaultPassword);
|
||||
|
||||
if (roles.Length > 0) await userManager.AddToRolesAsync(user, roles);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -180,12 +175,19 @@ internal class TestDataSeeder(
|
||||
}
|
||||
|
||||
|
||||
private readonly List<ApplicationUser> _users =
|
||||
[
|
||||
];
|
||||
|
||||
|
||||
private readonly static ApplicationUser Hutopy = new()
|
||||
{
|
||||
UserName = "hutopy@test",
|
||||
Email = "hutopy@test",
|
||||
EmailConfirmed = true,
|
||||
CreatorAlias = "hutopy",
|
||||
FirstName = "FirstName of a Brand/Creator",
|
||||
LastName = "LastName of a Brand/Creator",
|
||||
About = "Page officielle",
|
||||
Description = "Site officiel pour Hutopy. Venez-nous-y retrouver avec tous vos fans!",
|
||||
ProfileColors = new ProfileColors
|
||||
|
||||
Reference in New Issue
Block a user