Ejemplo n.º 1
0
 public IActionResult Create(Student student)
 {
     if (ModelState.IsValid)
     {
         context.students.Add(student);
         context.SaveChanges();
         return(RedirectToAction("Details", new { id = student.studentNumber }));
     }
     else
     {
         ViewData["error"] = "invalid Input!";
         return(View());
     }
 }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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();
        }