From 42e9a8153c61596740a2c074206977445065687b Mon Sep 17 00:00:00 2001 From: Clement LESME Date: Wed, 31 Jan 2024 13:22:33 +0100 Subject: [PATCH] =?UTF-8?q?d=C3=A9but=20du=20stub=20pour=20les=20personEnt?= =?UTF-8?q?itie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App/Program.cs | 55 +++++++------------------------------- App/Test.Librairy.db | 0 StubContext/StubContext.cs | 20 +++++++++++++- 3 files changed, 29 insertions(+), 46 deletions(-) create mode 100644 App/Test.Librairy.db diff --git a/App/Program.cs b/App/Program.cs index 3f12144..44c4a99 100644 --- a/App/Program.cs +++ b/App/Program.cs @@ -3,51 +3,9 @@ using Entities; using Microsoft.Extensions.DependencyModel; using System.Diagnostics; 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 books = new List(); +List persons = new List(); StubContext myStub = new StubContext(); // Insertion de livres dans la base de données @@ -57,6 +15,13 @@ using (var context = new LibraryContext()) 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 foreach (var book in books) { @@ -66,7 +31,7 @@ using (var context = new LibraryContext()) // Enregistre les modifications dans la base de données await context.SaveChangesAsync(); } - +/* // Récupération et affichage des livres de la base de données using (var context = new LibraryContext()) { @@ -102,4 +67,4 @@ using (var context = new LibraryContext()) bookToUpdate.Title = "Soir"; await context.SaveChangesAsync(); } -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/App/Test.Librairy.db b/App/Test.Librairy.db new file mode 100644 index 0000000..e69de29 diff --git a/StubContext/StubContext.cs b/StubContext/StubContext.cs index a96badb..6dc4e90 100644 --- a/StubContext/StubContext.cs +++ b/StubContext/StubContext.cs @@ -1,5 +1,6 @@ using ContextLib; using Entities; +using Microsoft.Extensions.DependencyModel; using System; using System.Collections.Generic; using System.Linq; @@ -20,7 +21,8 @@ namespace StubbedContextLib Id = 1, Author = "Lechardeur", Title = "Comment pécho 100% garanti", - Isbn = "696969a" + Isbn = "696969a", + PersonEntityId = 1, }; BookEntity book2 = new BookEntity @@ -47,5 +49,21 @@ namespace StubbedContextLib return listBook; } + public async Task> personsStub() + { + List ListPerson = new List(); + List l = new List(); + + PersonEntity person1 = new PersonEntity + { + Id = 1, + FirstName = "Khena", + LastName = "Bruneau", + }; + + ListPerson.Add(person1); + + return ListPerson; + } } }