#106 Ajout du mode Repositories Local
This commit is contained in:
@@ -49,20 +49,5 @@ namespace Webzine.Entity.Fixtures
|
||||
|
||||
return artisteFaker.Generate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Permet de retourner une liste d'artiste pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <param name="nombre"></param>
|
||||
/// <returns>Liste d'artiste.</returns>
|
||||
public static List<Artiste> CreerListeArtiste(int nombre)
|
||||
{
|
||||
Faker<Artiste> faker = new Faker<Artiste>("fr")
|
||||
.RuleFor(a => a.Nom, f => f.Person.FullName)
|
||||
.RuleFor(a => a.Biographie, f => f.Lorem.Paragraph(2));
|
||||
|
||||
return faker.Generate(nombre);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,26 +8,6 @@ namespace Webzine.Entity.Fixtures
|
||||
{
|
||||
public class CommentaireFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Seeder pour la base de données.
|
||||
/// </summary>
|
||||
/// <param name="titre">Titre.</param>
|
||||
/// <param name="min">Min.</param>
|
||||
/// <param name="max">Max.</param>
|
||||
/// <returns>Liste de commentaire.</returns>
|
||||
public static List<Commentaire> CreerListeCommentaire(Titre titre, int min = 0, int max = 5)
|
||||
{
|
||||
Random random = new Random();
|
||||
int count = random.Next(min, max + 1);
|
||||
|
||||
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
|
||||
.RuleFor(c => c.Auteur, f => f.Internet.UserName())
|
||||
.RuleFor(c => c.Contenu, f => f.Lorem.Sentences(2))
|
||||
.RuleFor(c => c.DateCreation, f => f.Date.Recent(60))
|
||||
.RuleFor(c => c.Titre, _ => titre)
|
||||
.RuleFor(c => c.IdTitre, _ => titre.IdTitre);
|
||||
|
||||
return faker.Generate(count);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,151 @@
|
||||
// </copyright>
|
||||
|
||||
namespace Webzine.Entity.Fixtures
|
||||
{
|
||||
{
|
||||
using Bogus;
|
||||
public class SeedDataLocal
|
||||
{
|
||||
public SeedDataLocal()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <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)
|
||||
{
|
||||
Faker<Artiste> artistes = new Faker<Artiste>("fr")
|
||||
.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 titre.
|
||||
/// </summary>
|
||||
/// <param name="count">Nombre de titre à créer.</param>
|
||||
/// <param name="artistes">Liste d'artiste.</param>
|
||||
/// <param name="styles">Liste de style.</param>
|
||||
/// <returns>Liste de titre.</returns>
|
||||
public static List<Titre> GenererListeTitre(
|
||||
int count,
|
||||
List<Artiste> artistes,
|
||||
List<Style> styles,
|
||||
List<string> albums)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
Faker<Titre> faker = new Faker<Titre>("fr")
|
||||
.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 => f.Date.Recent(120))
|
||||
.RuleFor(t => t.DateSortie, (f, t) => f.Date.Past(10, t.DateCreation))
|
||||
.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));
|
||||
|
||||
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 style pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <returns>Liste de style.</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 => new Style
|
||||
{
|
||||
Libelle = libelle,
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeder pour la base de données.
|
||||
/// </summary>
|
||||
/// <param name="titre">Titre.</param>
|
||||
/// <param name="min">Min.</param>
|
||||
/// <param name="max">Max.</param>
|
||||
/// <returns>Liste de commentaire.</returns>
|
||||
public static List<Commentaire> GenererListeCommentaire(Titre titre, int min = 0, int max = 5)
|
||||
{
|
||||
Random random = new Random();
|
||||
int count = random.Next(min, max + 1);
|
||||
|
||||
Faker<Commentaire> faker = new Faker<Commentaire>("fr")
|
||||
.RuleFor(c => c.Auteur, f => f.Internet.UserName())
|
||||
.RuleFor(c => c.Contenu, f => f.Lorem.Sentences(2))
|
||||
.RuleFor(c => c.DateCreation, f => f.Date.Recent(60))
|
||||
.RuleFor(c => c.Titre, _ => titre)
|
||||
.RuleFor(c => c.IdTitre, _ => titre.IdTitre);
|
||||
|
||||
return faker.Generate(count);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,47 +7,6 @@ namespace Webzine.Entity.Fixtures
|
||||
using Webzine.Entity;
|
||||
public class StyleFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Générer une liste de style pour seeder la base
|
||||
/// de données.
|
||||
/// </summary>
|
||||
/// <returns>Liste de style.</returns>
|
||||
public static List<Style> CreerListeStyle(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 => new Style
|
||||
{
|
||||
Libelle = libelle,
|
||||
})
|
||||
.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,50 +74,4 @@ namespace Webzine.Repository.Fake
|
||||
return titres;
|
||||
}
|
||||
}
|
||||
|
||||
public class TitreFactory
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TitreFactory"/> class.
|
||||
/// </summary>
|
||||
public TitreFactory()
|
||||
{
|
||||
}
|
||||
|
||||
public static List<Titre> CreerListeTitre(
|
||||
int count,
|
||||
List<Artiste> artistes,
|
||||
List<Style> styles)
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
Faker<Titre> faker = new Faker<Titre>("fr")
|
||||
.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 => f.Date.Recent(120))
|
||||
.RuleFor(t => t.DateSortie, (f, t) => f.Date.Past(10, t.DateCreation))
|
||||
.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.Company.CatchPhrase())
|
||||
.RuleFor(t => t.Artiste, f => f.PickRandom(artistes));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user