public void TestInitializer() { productRepository = new Mock <IProductRepository>(); gebruikerRepository = new Mock <IGebruikerRepository>(); emailRepository = new Mock <IEmailRepository>(); productRepository.Setup(p => p.FindAll()).Returns(dummyContext.Producten); productRepository.Setup(p => p.FindById(1)).Returns(dummyContext.Schatkist); productRepository.Setup(p => p.FindById(2)).Returns(dummyContext.Draaischijf); productRepository.Setup(p => p.FindById(3)).Returns(dummyContext.Splitsbomen); emailRepository.Setup(e => e.FindByReservatieStatus(ReservatieStatus.Gereserveerd)).Returns(dummyContext.Email); emailRepository.Setup(e => e.FindByReservatieStatus(ReservatieStatus.Geblokkeerd)).Returns(dummyContext.Email); ctxMock = new Mock <HttpContextBase>(); controllerCtxMock = new Mock <ControllerContext>(); controllerCtxMock.SetupGet(con => con.HttpContext).Returns(ctxMock.Object); verlanglijstController = new VerlanglijstController(gebruikerRepository.Object, productRepository.Object, emailRepository.Object) { ControllerContext = controllerCtxMock.Object }; verlanglijst = new Verlanglijst(); verlanglijst.VoegProductToe(dummyContext.Schatkist); }
public void IndexZalVerlanglijstTonenAlsVerlanglijstNietLeegIs() { ViewResult result = verlanglijstController.Index(dummyContext.CurrentGebruiker) as ViewResult; Verlanglijst verlanglijstResult = result.ViewData.Model as Verlanglijst; Assert.AreEqual(1, verlanglijst.AantalItems); }
private void MaakGebruikerEnRollen(string email, string wachtwoord, string rolNaam, int nr, string voornaam, string achternaam) { //Gebruiker aanmaken ApplicationUser gebruiker = userManager.FindByName(email); if (gebruiker == null) { Verlanglijst verlanglijst = new Verlanglijst() { VerlanglijstId = nr }; if (rolNaam == "student") { gebruiker = new Student { Voornaam = voornaam, Naam = achternaam, GebruikersNummer = email, UserName = email, Email = email, Verlanglijst = verlanglijst, Reservaties = new List <Reservatie>() }; } else { gebruiker = new Personeel { Voornaam = voornaam, Naam = achternaam, GebruikersNummer = email, UserName = email, Email = email, Verlanglijst = verlanglijst, Reservaties = new List <Reservatie>() }; } IdentityResult resultaat = userManager.Create(gebruiker, wachtwoord); if (!resultaat.Succeeded) { throw new ApplicationException(resultaat.Errors.ToString()); } } //Rollen aanmaken IdentityRole rol = roleManager.FindByName(rolNaam); if (rol == null) { rol = new IdentityRole(rolNaam); IdentityResult resultaat = roleManager.Create(rol); if (!resultaat.Succeeded) { throw new ApplicationException(resultaat.Errors.ToString()); } } //Rol toekennen aan aangemaakte gebruiker IList <String> rollenVanGebruiker = userManager.GetRoles(gebruiker.Id); if (!rollenVanGebruiker.Contains(rol.Name)) { IdentityResult resultaat = userManager.AddToRole(gebruiker.Id, rolNaam); if (!resultaat.Succeeded) { throw new ApplicationException(resultaat.Errors.ToString()); } } }
public void Initialize() { context = new DummyCatalogusContext(); verlanglijst = new Verlanglijst(); }
// GET: Product public ActionResult Index(ApplicationUser gebruiker, string currentFilter, int?page, string searchString = null, string doelgroep = null, string leergebied = null) { ViewBag.Gebruiker = gebruiker; IEnumerable <Product> producten = productRepository.FindAll().ToList(); if (gebruiker is Student) { producten = producten.Where(b => b.Uitleenbaar).ToList(); } Verlanglijst verlanglijst = gebruiker.Verlanglijst; IEnumerable <ProductViewModel> productlijst = null; if (verlanglijst != null) { productlijst = producten.Select(p => new ProductViewModel(p, verlanglijst.BevatProduct(p), doelgroep)).ToList(); } if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; ViewBag.Doelgroepen = doelgroepRepository.FindAll().ToArray(); ViewBag.Leergebieden = leergebiedRepository.FindAll().ToArray(); if (doelgroep != null) { productlijst = productlijst.Where(p => p.Doelgroepen.Contains(doelgroepRepository.FindByName(doelgroep))); } if (leergebied != null) { productlijst = productlijst.Where(p => p.Leergebieden.Contains(leergebiedRepository.FindByName(leergebied))); } if (!String.IsNullOrEmpty(searchString)) { searchString = searchString.Trim().ToLower(); productlijst = productlijst.Where( n => n.Artikelnaam.ToLower().Contains(searchString) || n.Omschrijving.ToLower().Contains(searchString)); //|| n.BevatDoelgroep(searchString) || n.BevatLeergebied(searchString)); if (productlijst.Count() == 0) { return(View("GeenZoekResultaten")); } } int pageSize = 3; int pageNumber = (page ?? 1); if (Request.IsAjaxRequest()) { return(PartialView("Producten", productlijst.ToPagedList(pageNumber, pageSize))); } return(View(productlijst.ToPagedList(pageNumber, pageSize))); }