|
|
@ -1,12 +1,12 @@
|
|
|
|
using listBooksEF;
|
|
|
|
using ContextLib;
|
|
|
|
|
|
|
|
using Entities;
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
|
|
using Microsoft.Identity.Client;
|
|
|
|
|
|
|
|
using StubbedContextLib;
|
|
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using Xunit;
|
|
|
|
using StubbedContextLib;
|
|
|
|
|
|
|
|
|
|
|
|
List<BookEntity> books = new List<BookEntity>();
|
|
|
|
List<BookEntity> books = new List<BookEntity>();
|
|
|
|
StubbedContext myStub = new StubbedContext();
|
|
|
|
List<PersonEntity> persons = new List<PersonEntity>();
|
|
|
|
|
|
|
|
StubContext myStub = new StubContext();
|
|
|
|
|
|
|
|
|
|
|
|
// Insertion de livres dans la base de données
|
|
|
|
// Insertion de livres dans la base de données
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
using (var context = new LibraryContext())
|
|
|
@ -15,22 +15,29 @@ 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)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
await context.Books.AddAsync(book);
|
|
|
|
await context.BooksSet.AddAsync(book);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine("Récupération\n");
|
|
|
|
Console.WriteLine("Récupération\n");
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var book in context.Books)
|
|
|
|
foreach (var book in context.BooksSet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine($"{book.Title}, Auteur : {book.Author}");
|
|
|
|
Console.WriteLine($"{book.Title}, Auteur : {book.Author}");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -41,10 +48,10 @@ using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine("Suppression\n");
|
|
|
|
Console.WriteLine("Suppression\n");
|
|
|
|
|
|
|
|
|
|
|
|
var book = context.Books.FirstOrDefault(b => b.Id == 2);
|
|
|
|
var book = context.BooksSet.FirstOrDefault(b => b.Id == 2);
|
|
|
|
if (book != null)
|
|
|
|
if (book != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
context.Books.Remove(book);
|
|
|
|
context.BooksSet.Remove(book);
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,17 +61,10 @@ using (var context = new LibraryContext())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Console.WriteLine("Modification\n");
|
|
|
|
Console.WriteLine("Modification\n");
|
|
|
|
|
|
|
|
|
|
|
|
var bookToUpdate = context.Books.FirstOrDefault(b => b.Author == "Martin");
|
|
|
|
var bookToUpdate = context.BooksSet.FirstOrDefault(b => b.Author == "Martin");
|
|
|
|
if (bookToUpdate != null)
|
|
|
|
if (bookToUpdate != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bookToUpdate.Title = "Soir";
|
|
|
|
bookToUpdate.Title = "Soir";
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
// Assertion sur le nombre de livres dans la base de données
|
|
|
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var cpt = context.Books.Count();
|
|
|
|
|
|
|
|
Assert.Equal(cpt, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
|