public void TestAdministratorGetAllOK2() { IMMRequestContext IMMRequestContext = ContextFactory.GetNewContext(); AdministratorRepository adminRepo = new AdministratorRepository(IMMRequestContext); adminRepo.Add(new Administrator { Id = Guid.NewGuid(), Name = "Just Testing", Email = "*****@*****.**", Password = "******" }); adminRepo.Add(new Administrator { Id = Guid.NewGuid(), Name = "Just Testing again", Email = "*****@*****.**", Password = "******" }); adminRepo.Save(); var admins = adminRepo.GetAll().ToList().Count(); Assert.AreEqual(2, admins); }
public void TestAdministratorGet2() { var id = Guid.NewGuid(); IMMRequestContext IMMRequestContext = ContextFactory.GetNewContext(); AdministratorRepository adminRepo = new AdministratorRepository(IMMRequestContext); Administrator admin1 = new Administrator() { Id = Guid.NewGuid(), Name = "Just Testing", Email = "*****@*****.**", Password = "******" }; Administrator admin2 = new Administrator() { Id = id, Name = "Just Testing again", Email = "*****@*****.**", Password = "******" }; adminRepo.Add(admin1); adminRepo.Add(admin2); adminRepo.Save(); Assert.AreEqual(adminRepo.Get(id), admin2); }
public ActionResult Edit(int id, AdminControllerAdminVM model) { AdministratorRepository adminRepository = new AdministratorRepository(); TryUpdateModel(model); if (ModelState.IsValid) { Administrator admin = null; if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null) { admin = new Administrator(); admin.UserName = model.UserName; admin.Password = SecurityService.CreateHash(model.Password); admin.FirstName = model.FirstName; admin.LastName = model.LastName; admin.IsActive = true; adminRepository.Save(admin); return(RedirectToAction("ManageAdministrators")); } else { throw new ArgumentException("Invalid username !"); } } return(View(model)); }
public void TestAdministratorGetAll3() { IMMRequestContext IMMRequestContext = ContextFactory.GetNewContext(); AdministratorRepository adminRepo = new AdministratorRepository(IMMRequestContext); Administrator admin = new Administrator() { Id = Guid.NewGuid(), Name = "Just Testing", Email = "*****@*****.**", Password = "******" }; adminRepo.Add(admin); adminRepo.Save(); var admins = adminRepo.GetAll().ToList(); Assert.AreEqual(admins.First(), admin); }
public ActionResult Edit(int id, AdminControllerAdminVM model) { AdministratorRepository adminRepository = new AdministratorRepository(); TryUpdateModel(model); if (ModelState.IsValid) { Administrator admin = null; if (adminRepository.GetAll(filter: a => a.UserName == model.UserName).FirstOrDefault() == null) { admin = new Administrator(); admin.UserName = model.UserName; admin.Password = SecurityService.CreateHash(model.Password); admin.FirstName = model.FirstName; admin.LastName = model.LastName; admin.IsActive = true; adminRepository.Save(admin); return RedirectToAction("ManageAdministrators"); } else { throw new ArgumentException("Invalid username !"); } } return View(model); }