pull/2/head
Bastien OLLIER 2 years ago
parent 548a3f57cc
commit d7dab35998

@ -7,14 +7,14 @@ using Microsoft.EntityFrameworkCore;
namespace EFLol namespace EFLol
{ {
public class ChampionContext : DbContext public class MyDbContext : DbContext
{ {
public DbSet<ChampionEntity> Champions { get; set; } public DbSet<ChampionEntity> Champions { get; set; }
public ChampionContext() public MyDbContext()
{ } { }
public ChampionContext(DbContextOptions<ChampionContext> options) public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options) : base(options)
{ } { }

@ -17,7 +17,7 @@ ChampionEntity chewie = new ChampionEntity { Name = "Chewbacca", Bio = "Zeus is
ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." }; ChampionEntity yoda = new ChampionEntity { Name = "Yoda", Bio = "Zeus is the king of the gods." };
ChampionEntity ewok = new ChampionEntity { Name = "Ewok" , Bio = "Zeus is the king of the gods." }; ChampionEntity ewok = new ChampionEntity { Name = "Ewok" , Bio = "Zeus is the king of the gods." };
using (var context = new ChampionContext()) using (var context = new MyDbContext())
{ {
// Crée des nounours et les insère dans la base // Crée des nounours et les insère dans la base
Console.WriteLine("Creates and inserts new Nounours"); Console.WriteLine("Creates and inserts new Nounours");
@ -27,7 +27,7 @@ using (var context = new ChampionContext())
context.SaveChanges(); context.SaveChanges();
} }
using (var context = new ChampionContext()) using (var context = new MyDbContext())
{ {
foreach (var n in context.Champions) foreach (var n in context.Champions)
{ {

@ -16,12 +16,12 @@ namespace TestUnitaire
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
connection.Open(); connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>() var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection) .UseSqlite(connection)
.Options; .Options;
// Act // Act
using (var context = new ChampionContext(options)) using (var context = new MyDbContext(options))
{ {
await context.Database.EnsureCreatedAsync(); await context.Database.EnsureCreatedAsync();
var Dieu = new ChampionEntity var Dieu = new ChampionEntity
@ -50,12 +50,12 @@ namespace TestUnitaire
var connection = new SqliteConnection("DataSource=:memory:"); var connection = new SqliteConnection("DataSource=:memory:");
connection.Open(); connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>() var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection) .UseSqlite(connection)
.Options; .Options;
//prepares the database with one instance of the context //prepares the database with one instance of the context
using (var context = new ChampionContext(options)) using (var context = new MyDbContext(options))
{ {
//context.Database.OpenConnection(); //context.Database.OpenConnection();
context.Database.EnsureCreated(); context.Database.EnsureCreated();
@ -72,7 +72,7 @@ namespace TestUnitaire
} }
//uses another instance of the context to do the tests //uses another instance of the context to do the tests
using (var context = new ChampionContext(options)) using (var context = new MyDbContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();
@ -86,7 +86,7 @@ namespace TestUnitaire
} }
//uses another instance of the context to do the tests //uses another instance of the context to do the tests
using (var context = new ChampionContext(options)) using (var context = new MyDbContext(options))
{ {
context.Database.EnsureCreated(); context.Database.EnsureCreated();

Loading…
Cancel
Save