début du stub pour les personEntitie

part2
Clement LESME 1 year ago
parent 0a41a1ccd0
commit 42e9a8153c

@ -3,51 +3,9 @@ using Entities;
using Microsoft.Extensions.DependencyModel; using Microsoft.Extensions.DependencyModel;
using System.Diagnostics; using System.Diagnostics;
using StubbedContextLib; using StubbedContextLib;
/*
namespace App
{
class Program
{
static void Main(string[] args)
{
BookEntity book2 = new BookEntity
{
Id = 2,
Author = "Vianney",
Title = "Gros",
Isbn = "0015150"
};
BookEntity book3 = new BookEntity
{
Id = 3,
Author = "Khéna",
Title = "Khéna. Un homme, un livre",
Isbn = "666666b"
};
using (var context = new LibraryContext())
{
Console.WriteLine("insertion");
context.Add(book2);
context.Add(book3);
context.SaveChanges();
}
using (var context = new LibraryContext())
{
foreach (var n in context.BooksSet)
{
Console.WriteLine($"{n.Id} - {n.Author}");
}
context.SaveChanges();
}
}
}
}*/
List<BookEntity> books = new List<BookEntity>(); List<BookEntity> books = new List<BookEntity>();
List<PersonEntity> persons = new List<PersonEntity>();
StubContext myStub = new StubContext(); StubContext myStub = new StubContext();
// Insertion de livres dans la base de données // Insertion de livres dans la base de données
@ -57,6 +15,13 @@ using (var context = new LibraryContext())
books = await myStub.booksStub(); books = await myStub.booksStub();
// Ajoute chaque person à la base de données de manière asynchrone
foreach (var person in persons)
{
await context.PersonsSet.AddAsync(person);
}
// Ajoute chaque livre à la base de données de manière asynchrone // Ajoute chaque livre à la base de données de manière asynchrone
foreach (var book in books) foreach (var book in books)
{ {
@ -66,7 +31,7 @@ using (var context = new LibraryContext())
// Enregistre les modifications dans la base de données // Enregistre les modifications dans la base de données
await context.SaveChangesAsync(); await context.SaveChangesAsync();
} }
/*
// Récupération et affichage des livres de la base de données // Récupération et affichage des livres de la base de données
using (var context = new LibraryContext()) using (var context = new LibraryContext())
{ {
@ -102,4 +67,4 @@ using (var context = new LibraryContext())
bookToUpdate.Title = "Soir"; bookToUpdate.Title = "Soir";
await context.SaveChangesAsync(); await context.SaveChangesAsync();
} }
} }*/

@ -1,5 +1,6 @@
using ContextLib; using ContextLib;
using Entities; using Entities;
using Microsoft.Extensions.DependencyModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -20,7 +21,8 @@ namespace StubbedContextLib
Id = 1, Id = 1,
Author = "Lechardeur", Author = "Lechardeur",
Title = "Comment pécho 100% garanti", Title = "Comment pécho 100% garanti",
Isbn = "696969a" Isbn = "696969a",
PersonEntityId = 1,
}; };
BookEntity book2 = new BookEntity BookEntity book2 = new BookEntity
@ -47,5 +49,21 @@ namespace StubbedContextLib
return listBook; return listBook;
} }
public async Task<List<PersonEntity>> personsStub()
{
List<PersonEntity> ListPerson = new List<PersonEntity>();
List<BookEntity> l = new List<BookEntity>();
PersonEntity person1 = new PersonEntity
{
Id = 1,
FirstName = "Khena",
LastName = "Bruneau",
};
ListPerson.Add(person1);
return ListPerson;
}
} }
} }

Loading…
Cancel
Save