public void Test1() { var options = new DbContextOptionsBuilder <MijnContext>() .UseInMemoryDatabase("Naam") .Options; var context = new MijnContext(options); context.Studenten.Add(new Student { Naam = "Bob" }); context.Studenten.Add(new Student { Naam = "Bill" }); context.Studenten.Add(new Student { Naam = "Jake" }); context.Studenten.Add(new Student { Naam = "Alice" }); context.Studenten.Add(new Student { Naam = "Joey" }); context.SaveChanges(); HomeController c = new HomeController(context); var result = Xunit.Assert.IsType <ViewResult>(c.Index()); var model = Xunit.Assert.IsType <List <Student> >(result.Model); Xunit.Assert.True(model.Count == 5); }
public void Test2() { var options = new DbContextOptionsBuilder <MijnContext>() .UseInMemoryDatabase("Naam") .Options; var context = new MijnContext(options); context.Studenten.Add(new Student { Naam = "Bob" }); context.Studenten.Add(new Student { Naam = "Bill" }); context.Studenten.Add(new Student { Naam = "Jacob-Allexander" }); context.Studenten.Add(new Student { Naam = "Alice" }); context.Studenten.Add(new Student { Naam = "Joey" }); context.SaveChanges(); HomeController c = new HomeController(context); }
private MijnContext GetInMemoryDBMetData() { MijnContext context = GetNewInMemoryDatabase(true); AddStudentsInDb(context); return(GetNewInMemoryDatabase(false)); // gebruik een nieuw (clean) object voor de context }
private string databaseName; // zonder deze property kun je geen clean context maken. private void AddStudentsInDb(MijnContext context) { context.Add(new Student { studentNumber = 1, firstName = "Koen", email = "*****@*****.**" }); context.Add(new Student { studentNumber = 2, firstName = "Robin", email = "*****@*****.**" }); context.Add(new Student { studentNumber = 3, firstName = "Binh", email = "*****@*****.**" }); context.Add(new Student { studentNumber = 4, firstName = "Mehdi", email = "*****@*****.**" }); context.Add(new Student { studentNumber = 5, firstName = "Klaas", email = "*****@*****.**" }); context.SaveChanges(); }
public HomeController(MijnContext context_) { context = context_; }
public StudentController(MijnContext context) { this.context = context; }
public HomeController(MijnContext context) { this.context = context; }
public StudentAdministratieController(MijnContext context) { this.context = context; }
public StudentsController(MijnContext context) : base(context) { }
public HomeController(MijnContext context) : base(context) { }