|
|
@ -11,6 +11,55 @@ namespace UnitTests
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class UnitTest1
|
|
|
|
public class UnitTest1
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void Delete_TestPerson()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<LibraryContext>()
|
|
|
|
|
|
|
|
.UseSqlite()
|
|
|
|
|
|
|
|
.Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
|
|
|
|
var allPers = context.PersonSet;
|
|
|
|
|
|
|
|
foreach (var person in allPers)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.PersonSet.Remove(person);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, context.PersonSet.Count());
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void Delete_TestBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<LibraryContext>().UseSqlite().Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
|
|
|
|
var allBooks = context.BooksSet;
|
|
|
|
|
|
|
|
foreach (var book in allBooks)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.BooksSet.Remove(book);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, context.BooksSet.Count());
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void Add_TestBooks()
|
|
|
|
public void Add_TestBooks()
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -25,9 +74,9 @@ namespace UnitTests
|
|
|
|
//context.Database.OpenConnection();
|
|
|
|
//context.Database.OpenConnection();
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
context.Database.EnsureCreated();
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
BookEntity the100 = new BookEntity { Title = "the100", Author = "", Isbn = "", Id =3 };
|
|
|
|
BookEntity the100 = new BookEntity { Title = "the100", Author = "", Isbn = "", Id =8 };
|
|
|
|
BookEntity princeOfPersia = new BookEntity { Title = "princeOfPersia", Author = "", Isbn = "", Id = 4 };
|
|
|
|
BookEntity princeOfPersia = new BookEntity { Title = "princeOfPersia", Author = "", Isbn = "", Id = 10 };
|
|
|
|
BookEntity PercyJackson = new BookEntity { Title = "PercyJackson", Author = "", Isbn = "", Id = 5 };
|
|
|
|
BookEntity PercyJackson = new BookEntity { Title = "PercyJackson", Author = "", Isbn = "", Id = 9 };
|
|
|
|
context.BooksSet.Add(the100);
|
|
|
|
context.BooksSet.Add(the100);
|
|
|
|
context.BooksSet.Add(princeOfPersia);
|
|
|
|
context.BooksSet.Add(princeOfPersia);
|
|
|
|
context.BooksSet.Add(PercyJackson);
|
|
|
|
context.BooksSet.Add(PercyJackson);
|
|
|
@ -119,7 +168,6 @@ namespace UnitTests
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -143,55 +191,10 @@ namespace UnitTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void Delete_TestPerson()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<LibraryContext>().UseSqlite().Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
|
|
|
|
var nb = context.PersonSet.Count();
|
|
|
|
|
|
|
|
if (nb > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.PersonSet.Remove(context.PersonSet.FirstOrDefault());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(context.PersonSet.Count(), nb - 1);
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void Delete_TestBook()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
|
|
|
|
connection.Open();
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<LibraryContext>().UseSqlite().Options;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.PersonSet.Include(pers => pers.Books).ToList();
|
|
|
|
|
|
|
|
var nb = context.BooksSet.Count();
|
|
|
|
|
|
|
|
if (nb > 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
context.BooksSet.Remove(context.BooksSet.FirstOrDefault());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Assert.Equal(context.BooksSet.Count(), nb - 1);
|
|
|
|
|
|
|
|
context.SaveChanges();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void Delete_TestEmprunt()
|
|
|
|
public void Update_TestEmprunt()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
connection.Open();
|
|
|
|
connection.Open();
|
|
|
@ -199,7 +202,6 @@ namespace UnitTests
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = context.BooksSet;
|
|
|
|
var books = context.BooksSet;
|
|
|
@ -223,7 +225,7 @@ namespace UnitTests
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void Delete_TestRendu()
|
|
|
|
public void Update_TestRendu()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
var connection = new SqliteConnection("DataSource=:memory:");
|
|
|
|
connection.Open();
|
|
|
|
connection.Open();
|
|
|
@ -231,8 +233,7 @@ namespace UnitTests
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
|
|
|
|
|
|
|
|
//prepares the database with one instance of the context
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
using (var context = new StubbedContext(options))
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var books = context.BooksSet;
|
|
|
|
var books = context.BooksSet;
|
|
|
|
|
|
|
|
|
|
|
|