public void TestGetCurrentExperiment()
        {
            Experiment experiment = new Experiment()
            {
                Id = Guid.NewGuid()
            };

            _context.Experiments.Add(experiment);
            _context.SaveChanges();

            Experiment currentExperiment = _services.GetCurrentExperiment().Result;

            Assert.AreEqual(currentExperiment.Id, experiment.Id);
        }
示例#2
0
        public void TestGetCurrentRipening()
        {
            Cheese cheese = new Cheese()
            {
                Id = Guid.NewGuid()
            };

            _context.Cheeses.Add(cheese);

            Ripening ripening = _services.CreateRipening(cheese.Id);

            _context.Ripenings.Add(ripening);
            _context.SaveChanges();

            Ripening currentRipening = _services.GetCurrentRipening().Result;

            Assert.AreEqual(currentRipening.Id, ripening.Id);
        }
示例#3
0
        public IActionResult Create(Klant klant)
        {
            if (ModelState.IsValid)
            {
                Guid activationCode = Guid.NewGuid();
                if (_context.Klanten.Where(u => u.Email == klant.Email).Any())
                {
                    ModelState.AddModelError("Email", "E-Mail al in gebruik");
                }
                else
                {
                    var m = new Klant {
                        Id                = klant.Id,
                        Voornaam          = klant.Voornaam,
                        Achternaam        = klant.Achternaam,
                        Geslacht          = klant.Geslacht,
                        Geboortedatum     = klant.Geboortedatum,
                        Email             = klant.Email,
                        Wachtwoord        = klant.Wachtwoord,
                        confirmWachtwoord = klant.confirmWachtwoord,
                        Telnummer         = klant.Telnummer,
                        Straatnaam        = klant.Straatnaam,
                        Huisnummer        = klant.Huisnummer,
                        Postcode          = klant.Postcode,
                        ActivatieCode     = activationCode,
                        Geactiveerd       = "Nee"
                    };

                    SendActivationEmail(klant, activationCode);

                    _context.Add(m);
                    _context.SaveChanges();

                    return(RedirectToAction("Activatie_scherm"));
                }
            }
            return(View());
        }
示例#4
0
        public ActionResult <int> Post([FromBody] Cheese value)
        {
            try
            {
                var cheese = _context.Cheeses.Add(value);
                _context.SaveChanges();

                return(Ok(cheese.Entity.Id));
            }
            catch (Exception e)
            {
                if (e is DbUpdateException || e is InvalidOperationException)
                {
                    //Give user generic bad request error and would normally write error to log.
                    return(BadRequest(
                               "Unable to create new cheese. Please check data is correct and if you set an ID that it doesn't already exist!"));
                }

                //Not handling other exceptions to allow it to go to the global exception handler. In debug mode we get the exception and in prod we just get a error 500.
                //In a more complete app I would instead write this to a log file.
                throw;
            }
        }
示例#5
0
 //Helper method to add cheese into database to make unit tests more readable.
 public void AddEntry(Cheese data)
 {
     DBContext.Cheeses.Add(data);
     DBContext.SaveChanges();
 }