Modification de documentation et suppression de methodes non utilisees.
This commit is contained in:
@@ -2,169 +2,168 @@
|
||||
// Copyright (c) PlaceholderCompany. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.Entity.Fixtures
|
||||
namespace Webzine.Entity.Fixtures;
|
||||
|
||||
using Bogus;
|
||||
|
||||
/// <summary>
|
||||
/// Classe pour générer des données de test locales, telles que des listes d'artistes, de
|
||||
/// titres, de styles, de commentaires et d'albums, afin de faciliter le peuplement de la base de données
|
||||
/// et les données lcoales.
|
||||
/// </summary>
|
||||
public class SeedDataLocal
|
||||
{
|
||||
using Bogus;
|
||||
|
||||
public class SeedDataLocal
|
||||
/// <summary>
|
||||
/// Génére une liste d'artiste.
|
||||
/// </summary>
|
||||
/// <param name="nombre">Nombre d'artiste.</param>
|
||||
/// <returns>Liste d'artiste.</returns>
|
||||
public static List<Artiste> GenererListeArtiste(int nombre)
|
||||
{
|
||||
public SeedDataLocal()
|
||||
int idStart = 1;
|
||||
Faker<Artiste> artistes = new Faker<Artiste>("fr")
|
||||
.RuleFor(a => a.IdArtiste, f => f.IndexFaker + idStart) // Créé les id des artistes de manière incrémentale
|
||||
.RuleFor(a => a.Nom, f => f.Person.FullName)
|
||||
.RuleFor(a => a.Biographie, f => f.Lorem.Paragraph(2));
|
||||
|
||||
return artistes.Generate(nombre);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Génére une liste de titres.
|
||||
/// </summary>
|
||||
/// <param name="count">Nombre de titres à créer.</param>
|
||||
/// <param name="artistes">Liste d'artistes.</param>
|
||||
/// <param name="styles">Liste de styles.</param>
|
||||
/// <param name="albums">Liste d'albums.</param>
|
||||
/// <returns>Liste de titres.</returns>
|
||||
public static List<Titre> GenererListeTitre(
|
||||
int count,
|
||||
List<Artiste> artistes,
|
||||
List<Style> styles,
|
||||
List<string> albums)
|
||||
{
|
||||
Random random = new Random();
|
||||
int idStart = 1;
|
||||
|
||||
Faker<Titre> faker = new Faker<Titre>("fr")
|
||||
.RuleFor(a => a.IdTitre, f => f.IndexFaker + idStart)
|
||||
.RuleFor(t => t.Libelle, f => f.Lorem.Sentence(3).Replace(".", string.Empty))
|
||||
.RuleFor(t => t.Chronique, f => f.Lorem.Paragraphs(3))
|
||||
.RuleFor(t => t.DateCreation, f => DateTime.SpecifyKind(f.Date.Recent(120), DateTimeKind.Utc))
|
||||
.RuleFor(t => t.DateSortie, (f, t) => DateTime.SpecifyKind(f.Date.Past(10, t.DateCreation), DateTimeKind.Utc))
|
||||
.RuleFor(t => t.Duree, f => f.Random.Int(120, 420))
|
||||
.RuleFor(t => t.UrlJaquette, f => $"https://picsum.photos/seed/{Guid.NewGuid():N}/640/640")
|
||||
.RuleFor(t => t.UrlEcoute, f => $"https://example.com/listen/{Guid.NewGuid():N}")
|
||||
.RuleFor(t => t.NbLectures, f => f.Random.Int(0, 5000))
|
||||
.RuleFor(t => t.NbLikes, f => f.Random.Int(0, 1000))
|
||||
.RuleFor(t => t.Album, f => f.PickRandom(albums))
|
||||
.RuleFor(t => t.Artiste, f => f.PickRandom(artistes))
|
||||
.RuleFor(t => t.Commentaires, f => new List<Commentaire>());
|
||||
List<Titre> titres = faker.Generate(count);
|
||||
|
||||
foreach (Titre titre in titres)
|
||||
{
|
||||
}
|
||||
int nbStyles = random.Next(1, 4);
|
||||
|
||||
/// <summary>
|
||||
/// Generer une liste d'artiste.
|
||||
/// </summary>
|
||||
/// <param name="nombre">Nombre d'artiste.</param>
|
||||
/// <returns>Liste d'artiste.</returns>
|
||||
public static List<Artiste> GenererListeArtiste(int nombre)
|
||||
{
|
||||
int idStart = 1;
|
||||
Faker<Artiste> artistes = new Faker<Artiste>("fr")
|
||||
.RuleFor(a => a.IdArtiste, f => f.IndexFaker + idStart) // Créé les id des artistes de manière incrémentale
|
||||
.RuleFor(a => a.Nom, f => f.Person.FullName)
|
||||
.RuleFor(a => a.Biographie, f => f.Lorem.Paragraph(2));
|
||||
|
||||
return artistes.Generate(nombre);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generer une liste de titres.
|
||||
/// </summary>
|
||||
/// <param name="count">Nombre de titres à créer.</param>
|
||||
/// <param name="artistes">Liste d'artistes.</param>
|
||||
/// <param name="styles">Liste de styles.</param>
|
||||
/// <param name="albums">Liste d'albums.</param>
|
||||
/// <param name="commentaires">Liste de commentaires.</param>
|
||||
/// <returns>Liste de titres.</returns>
|
||||
public static List<Titre> GenererListeTitre(
|
||||
int count,
|
||||
List<Artiste> artistes,
|
||||
List<Style> styles,
|
||||
List<string> albums)
|
||||
{
|
||||
Random random = new Random();
|
||||
int idStart = 1;
|
||||
|
||||
Faker<Titre> faker = new Faker<Titre>("fr")
|
||||
.RuleFor(a => a.IdTitre, f => f.IndexFaker + idStart)
|
||||
.RuleFor(t => t.Libelle, f => f.Lorem.Sentence(3).Replace(".", string.Empty))
|
||||
.RuleFor(t => t.Chronique, f => f.Lorem.Paragraphs(3))
|
||||
.RuleFor(t => t.DateCreation, f => DateTime.SpecifyKind(f.Date.Recent(120), DateTimeKind.Utc))
|
||||
.RuleFor(t => t.DateSortie, (f, t) => DateTime.SpecifyKind(f.Date.Past(10, t.DateCreation), DateTimeKind.Utc))
|
||||
.RuleFor(t => t.Duree, f => f.Random.Int(120, 420))
|
||||
.RuleFor(t => t.UrlJaquette, f => $"https://picsum.photos/seed/{Guid.NewGuid():N}/640/640")
|
||||
.RuleFor(t => t.UrlEcoute, f => $"https://example.com/listen/{Guid.NewGuid():N}")
|
||||
.RuleFor(t => t.NbLectures, f => f.Random.Int(0, 5000))
|
||||
.RuleFor(t => t.NbLikes, f => f.Random.Int(0, 1000))
|
||||
.RuleFor(t => t.Album, f => f.PickRandom(albums))
|
||||
.RuleFor(t => t.Artiste, f => f.PickRandom(artistes))
|
||||
.RuleFor(t => t.Commentaires, f => new List<Commentaire>());
|
||||
List<Titre> titres = faker.Generate(count);
|
||||
|
||||
foreach (Titre titre in titres)
|
||||
{
|
||||
int nbStyles = random.Next(1, 4);
|
||||
|
||||
titre.Styles = styles
|
||||
.OrderBy(_ => Guid.NewGuid())
|
||||
.Take(nbStyles)
|
||||
.ToList();
|
||||
|
||||
titre.IdArtiste = titre.Artiste.IdArtiste;
|
||||
}
|
||||
|
||||
return titres;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Générer une liste de styles pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="minCount">Le nombre minimum de styles pouvant être créés.</params>
|
||||
/// <param name="maxCount">Le nombre maximun de styles pouvant être créés.</params>
|
||||
/// <returns>Liste de styles.</returns>
|
||||
public static List<Style> GenererListeStyle(int minCount = 15, int maxCount = 20)
|
||||
{
|
||||
List<string> libelles = new List<string>
|
||||
{
|
||||
"Pop",
|
||||
"Rock",
|
||||
"Jazz",
|
||||
"Blues",
|
||||
"Hip-Hop",
|
||||
"Rap",
|
||||
"Electro",
|
||||
"Techno",
|
||||
"House",
|
||||
"Metal",
|
||||
"Funk",
|
||||
"Soul",
|
||||
"R&B",
|
||||
"Classique",
|
||||
"Reggae",
|
||||
"Punk",
|
||||
"Folk",
|
||||
"Disco",
|
||||
"Ambient",
|
||||
"Indie",
|
||||
};
|
||||
|
||||
Random random = new Random();
|
||||
int count = random.Next(minCount, maxCount + 1);
|
||||
|
||||
return libelles
|
||||
.Take(count)
|
||||
.Select((libelle, index) => new Style
|
||||
{
|
||||
IdStyle = index + 1,
|
||||
Libelle = libelle,
|
||||
})
|
||||
titre.Styles = styles
|
||||
.OrderBy(_ => Guid.NewGuid())
|
||||
.Take(nbStyles)
|
||||
.ToList();
|
||||
|
||||
titre.IdArtiste = titre.Artiste.IdArtiste;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Générer une liste de commentaires pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="titre">Titre.</param>
|
||||
/// <param name="min">Le nombre minimum de commentaires pouvant être créés. La valeur par défaut est 0.</params>
|
||||
/// <param name="max">Le nombre maximun de commentaires pouvant être créés. La valeur par défaut est 5.</params>
|
||||
/// <returns>Liste de commentaire.</returns>
|
||||
public static List<Commentaire> GenererListeCommentaire(Titre titre, int min = 0, int max = 5, int idStart = 1)
|
||||
return titres;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Génére une liste de styles pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="minCount">Le nombre minimum de styles pouvant être créés.</params>
|
||||
/// <param name="maxCount">Le nombre maximun de styles pouvant être créés.</params>
|
||||
/// <returns>Liste de styles.</returns>
|
||||
public static List<Style> GenererListeStyle(int minCount = 15, int maxCount = 20)
|
||||
{
|
||||
List<string> libelles = new List<string>
|
||||
{
|
||||
Random random = new Random();
|
||||
int count = random.Next(min, max + 1);
|
||||
"Pop",
|
||||
"Rock",
|
||||
"Jazz",
|
||||
"Blues",
|
||||
"Hip-Hop",
|
||||
"Rap",
|
||||
"Electro",
|
||||
"Techno",
|
||||
"House",
|
||||
"Metal",
|
||||
"Funk",
|
||||
"Soul",
|
||||
"R&B",
|
||||
"Classique",
|
||||
"Reggae",
|
||||
"Punk",
|
||||
"Folk",
|
||||
"Disco",
|
||||
"Ambient",
|
||||
"Indie",
|
||||
};
|
||||
|
||||
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
|
||||
.RuleFor(a => a.IdCommentaire, f => f.IndexFaker + idStart)
|
||||
.RuleFor(c => c.Auteur, f => f.Internet.UserName())
|
||||
.RuleFor(c => c.Contenu, f => f.Lorem.Sentences(2))
|
||||
.RuleFor(c => c.DateCreation, f => DateTime.SpecifyKind(f.Date.Recent(60), DateTimeKind.Utc))
|
||||
.RuleFor(c => c.Titre, _ => titre)
|
||||
.RuleFor(c => c.IdTitre, _ => titre.IdTitre);
|
||||
Random random = new Random();
|
||||
int count = random.Next(minCount, maxCount + 1);
|
||||
|
||||
return faker.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Générer une liste d'albums pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="nombre">Le nombre d'albums à générer.</param>
|
||||
/// <returns>Liste d'albums.</returns>
|
||||
public static List<string> GenererListeAlbums(int nombre)
|
||||
{
|
||||
Faker faker = new Faker("fr");
|
||||
|
||||
HashSet<string> albums = new HashSet<string>();
|
||||
|
||||
while (albums.Count < nombre)
|
||||
return libelles
|
||||
.Take(count)
|
||||
.Select((libelle, index) => new Style
|
||||
{
|
||||
albums.Add(faker.Company.CatchPhrase());
|
||||
}
|
||||
IdStyle = index + 1,
|
||||
Libelle = libelle,
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return albums.ToList();
|
||||
/// <summary>
|
||||
/// Génére une liste de commentaires pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="titre">Titre.</param>
|
||||
/// <param name="min">Le nombre minimum de commentaires pouvant être créés. La valeur par défaut est 0.</params>
|
||||
/// <param name="max">Le nombre maximun de commentaires pouvant être créés. La valeur par défaut est 5.</params>
|
||||
/// <returns>Liste de commentaire.</returns>
|
||||
public static List<Commentaire> GenererListeCommentaire(Titre titre, int min = 0, int max = 5, int idStart = 1)
|
||||
{
|
||||
Random random = new Random();
|
||||
int count = random.Next(min, max + 1);
|
||||
|
||||
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
|
||||
.RuleFor(a => a.IdCommentaire, f => f.IndexFaker + idStart)
|
||||
.RuleFor(c => c.Auteur, f => f.Internet.UserName())
|
||||
.RuleFor(c => c.Contenu, f => f.Lorem.Sentences(2))
|
||||
.RuleFor(c => c.DateCreation, f => DateTime.SpecifyKind(f.Date.Recent(60), DateTimeKind.Utc))
|
||||
.RuleFor(c => c.Titre, _ => titre)
|
||||
.RuleFor(c => c.IdTitre, _ => titre.IdTitre);
|
||||
|
||||
return faker.Generate(count);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Génére une liste d'albums pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="nombre">Le nombre d'albums à générer.</param>
|
||||
/// <returns>Liste d'albums.</returns>
|
||||
public static List<string> GenererListeAlbums(int nombre)
|
||||
{
|
||||
Faker faker = new Faker("fr");
|
||||
|
||||
HashSet<string> albums = new HashSet<string>();
|
||||
|
||||
while (albums.Count < nombre)
|
||||
{
|
||||
albums.Add(faker.Company.CatchPhrase());
|
||||
}
|
||||
|
||||
return albums.ToList();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user