using DbConnectionLibrairie; using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace UnitTestsEntityManagers { /// /// an abstract class to init the dbContext /// (every unit tests need to implement it) /// public abstract class AbstractUnitTestEM { public MyDbContext dbContext; public HttpClient httpClient; /// /// constructor of the class : /// initialise the database context /// public AbstractUnitTestEM() { var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); var opt = new DbContextOptionsBuilder() .UseSqlite(connection) .Options; dbContext = new MyDbContext(opt); dbContext.Database.EnsureCreated(); httpClient = new HttpClient(); } /// /// destructor of the class : /// dispose the database context /// ~AbstractUnitTestEM() { dbContext.Dispose(); } } }