Changed the way the test-data is generated

This commit is contained in:
Jonathan Bourdon
2024-07-18 13:19:40 -04:00
parent a8b7860fd8
commit ed8f41cf96
5 changed files with 203 additions and 125 deletions

View File

@@ -1,9 +1,4 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Hutopy.Domain.Constants;
using Hutopy.Infrastructure.Identity;
using Hutopy.Infrastructure.Identity.OwnedEntities;
using Hutopy.Domain.Constants;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
@@ -29,7 +24,6 @@ public static class InitializerExtensions
public class ApplicationDbContextInitializer(
ILogger<ApplicationDbContextInitializer> logger,
ApplicationDbContext context,
ApplicationUserManager userManager,
RoleManager<IdentityRole> roleManager)
{
public async Task InitialiseAsync()
@@ -60,7 +54,6 @@ public class ApplicationDbContextInitializer(
private async Task TrySeedAsync()
{
// Default roles
var administratorRole = new IdentityRole(Roles.Administrator);
if (roleManager.Roles.All(r => r.Name != administratorRole.Name))
{
@@ -72,47 +65,5 @@ public class ApplicationDbContextInitializer(
{
await roleManager.CreateAsync(roleCreator);
}
// Default users
var administrator =
new ApplicationUser { UserName = "administrator@localhost", Email = "administrator@localhost" };
if (userManager.Users.All(u => u.UserName != administrator.UserName))
{
await userManager.CreateAsync(administrator, "Administrator1!");
await userManager.AddToRolesAsync(administrator, new[] { Roles.Administrator });
}
// ADD CREATORS
await AddDefaultCreator(new ApplicationUser
{
UserName = "hutopy@localhost",
Email = "hutopy@localhost",
CreatorAlias = "hutopy",
About = "Page officielle",
Description = "Site officiel pour Hutopy. Venez-nous-y retrouver avec tous vos fans!",
EmailConfirmed = true,
ProfileColors = new ProfileColors { BannerTop = "A30E79", BannerBottom = "6B0065", Accent = "23393B", Menu = "53B93B", },
SocialNetworks =
new SocialNetworks
{
XUrl = "https://twitter.com/Hutopyinc",
FacebookUrl = "https://www.facebook.com/Hutopy",
InstagramUrl = "https://www.instagram.com/hutopy.inc/"
},
StoredDataUrls = new StoredDataUrls
{
BannerPictureUrl = "/images/usersmedia/HutopyProfile/banners/banner01.png",
ProfilePictureUrl = "/images/usersmedia/HutopyProfile/profilepictures/profileHutopyProfile01.png"
}
});
}
private async Task AddDefaultCreator(ApplicationUser hutopy)
{
if (userManager.Users.All(u => u.UserName != hutopy.UserName))
{
await userManager.CreateAsync(hutopy, "Test123!");
await userManager.AddToRolesAsync(hutopy, new[] { Roles.Creator });
}
}
}