|
|
|
@ -1,12 +1,54 @@
|
|
|
|
|
using listBooksEF;
|
|
|
|
|
using ContextLib;
|
|
|
|
|
using Entities;
|
|
|
|
|
using Microsoft.Extensions.DependencyModel;
|
|
|
|
|
using Microsoft.Identity.Client;
|
|
|
|
|
using StubbedContextLib;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using Xunit;
|
|
|
|
|
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>();
|
|
|
|
|
StubbedContext myStub = new StubbedContext();
|
|
|
|
|
StubContext myStub = new StubContext();
|
|
|
|
|
|
|
|
|
|
// Insertion de livres dans la base de données
|
|
|
|
|
using (var context = new LibraryContext())
|
|
|
|
@ -18,7 +60,7 @@ using (var context = new LibraryContext())
|
|
|
|
|
// Ajoute chaque livre à la base de données de manière asynchrone
|
|
|
|
|
foreach (var book in books)
|
|
|
|
|
{
|
|
|
|
|
await context.Books.AddAsync(book);
|
|
|
|
|
await context.BooksSet.AddAsync(book);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Enregistre les modifications dans la base de données
|
|
|
|
@ -30,7 +72,7 @@ using (var context = new LibraryContext())
|
|
|
|
|
{
|
|
|
|
|
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}");
|
|
|
|
|
}
|
|
|
|
@ -41,10 +83,10 @@ using (var context = new LibraryContext())
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
context.Books.Remove(book);
|
|
|
|
|
context.BooksSet.Remove(book);
|
|
|
|
|
await context.SaveChangesAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -54,17 +96,10 @@ using (var context = new LibraryContext())
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
bookToUpdate.Title = "Soir";
|
|
|
|
|
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);
|
|
|
|
|
}
|