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

@ -7,14 +7,14 @@ using Microsoft.EntityFrameworkCore;
namespace EFLol
{
public class ChampionContext : DbContext
public class MyDbContext : DbContext
{
public DbSet<ChampionEntity> Champions { get; set; }
public ChampionContext()
public MyDbContext()
{ }
public ChampionContext(DbContextOptions<ChampionContext> options)
public MyDbContext(DbContextOptions<MyDbContext> 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 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
Console.WriteLine("Creates and inserts new Nounours");
@ -27,7 +27,7 @@ using (var context = new ChampionContext())
context.SaveChanges();
}
using (var context = new ChampionContext())
using (var context = new MyDbContext())
{
foreach (var n in context.Champions)
{

@ -16,12 +16,12 @@ namespace TestUnitaire
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>()
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
// Act
using (var context = new ChampionContext(options))
using (var context = new MyDbContext(options))
{
await context.Database.EnsureCreatedAsync();
var Dieu = new ChampionEntity
@ -50,12 +50,12 @@ namespace TestUnitaire
var connection = new SqliteConnection("DataSource=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<ChampionContext>()
var options = new DbContextOptionsBuilder<MyDbContext>()
.UseSqlite(connection)
.Options;
//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.EnsureCreated();
@ -72,7 +72,7 @@ namespace TestUnitaire
}
//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();
@ -86,7 +86,7 @@ namespace TestUnitaire
}
//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();

Loading…
Cancel
Save