public void GetUserByUsernameShouldReturnUserWithMatchingUsername(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUser u; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { u = uRepo.GetUserByUsernameAsync(username).Result; } else { u = uRepo.GetUserByUsername(username); } } //Assert Assert.Equal(username, u.Username); }
public void GetOwnedRestaurantsForUserShouldReturnCorrectNumberOfRestaurantsWhenUsernameFound(string username, int expected, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; List <Restaurant> results; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { results = uRepo.GetOwnedRestaurantsForUserAsync(username).Result.ToList(); } else { results = uRepo.GetOwnedRestaurantsForUser(username).ToList(); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.Equal(expected, results.Count); }
public void DBContainsUsernameShouldReturnFalseIfUsernameNotInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { result = uRepo.DBContainsUsernameAsync(username).Result; } else { result = uRepo.DBContainsUsername(username); } } //Assert Assert.False(result); }
public ActionResult Delete(AppUser account) { AppUserRepo repo = new AppUserRepo(); repo.DeleteAccount(account.userID); return(RedirectToAction("Index", "Home", new { })); }
public void DBContainsUsernameShouldNotThrowExceptionIfDBIsEmpty(bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB2") .Options; bool result = true; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { uRepo.DBContainsUsernameAsync("LiterallyAnything").Wait(); } else { uRepo.DBContainsUsername("LiterallyAnything"); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void DBContainsUsernameShouldReturnFalseIfIfDBIsEmpty(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB3") .Options; bool result; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { result = uRepo.DBContainsUsernameAsync(username).Result; } else { result = uRepo.DBContainsUsername(username); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.False(result); }
public void AddRestaurantToBlacklistShouldSucceedIfUserAndRestaurantAreValid(string username, string rId, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; Blacklist result; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); if (useAsync) { uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait(); } else { uRepo.AddRestaurantToBlacklist(username, rId, rRepo); } result = context.Blacklist.Find(rId, username); } //Assert Assert.Equal(username, result.Username); Assert.Equal(rId, result.RestaurantId); }
public ActionResult Edit(int userID) { AppUserRepo repo = new AppUserRepo(); AppUser account = repo.GetAccount(userID); return(View(account)); }
public WorkController(IConfiguration config, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) : base(config, webHostEnvironment, httpContextAccessor) { _WorkRepo = new WorkRepo(ConnString); _PaymentRepo = new PaymentRepo(ConnString); _JobRepo = new JobRepo(ConnString); _AppUserRepo = new AppUserRepo(ConnString); }
public void GetUsersShouldNotThrowExceptionIfDBIsEmpty() { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB1") .Options; bool result = true; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); try { uRepo.GetUsers(); } catch { result = false; } } //Assert Assert.True(result); }
public void GetUserByUsernameShouldNotThrowExceptionIfUsernameIsInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result = true; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); if (useAsync) { uRepo.GetUserByUsernameAsync(username).Wait(); } else { uRepo.GetUserByUsername(username); } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public ActionResult Edit(AppUser userAccount) { AppUserRepo repo = new AppUserRepo(); if (ModelState.IsValid) { repo.UpdateAccount(userAccount.userID, userAccount); return(RedirectToAction("Details", new { userID = userAccount.userID })); } return(View()); }
public ActionResult Create(AppUser newUser) { AppUserRepo repo = new AppUserRepo(); if (ModelState.IsValid) { repo.AddAccount(newUser); return(RedirectToAction("Details", new { userID = newUser.userID })); } else { return(View()); } }
public void AddRestaurantToFavoritesShouldThrowExceptionIfRestrauntAlreadyInUsersBlacklist(string username, string rId, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyAddFavoritesTestingDB") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; bool result = false; using (var context = new Project2DBContext(options)) { context.Favorite.Add(new Favorite { Username = username, RestaurantId = rId }); } //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); try { if (useAsync) { uRepo.AddRestaurantToFavoritesAsync(username, rId, rRepo).Wait(); } else { uRepo.AddRestaurantToFavorites(username, rId, rRepo); } } catch (DbUpdateException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }
public void GetUsersShouldReturnAListWithProperNumberOfUsers() { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; AppUserRepo uRepo; List <AppUser> uList; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); uList = uRepo.GetUsers().ToList(); } //Assert Assert.Equal(4, uList.Count); }
public virtual async Task <AppUser_Dto> RegisterAsync(RegisterDto input) { await CheckSelfRegistrationAsync(); var user = new IdentityUser(GuidGenerator.Create(), input.UserName, input.EmailAddress, CurrentTenant.Id); (await UserManager.CreateAsync(user, input.Password)).CheckErrors(); await UserManager.SetEmailAsync(user, input.EmailAddress); await UserManager.AddDefaultRolesAsync(user); var appUser = await AppUserRepo.GetAsync(x => x.Id == user.Id); appUser.EmployeeId = input.EmployeeId; var result = await AppUserRepo.UpdateAsync(appUser); return(ObjectMapper.Map <AppUser, AppUser_Dto>(result)); }
public ActionResult LogIn(string userName, string passWord) { //call repo method to get account absed on username AppUserRepo repo = new AppUserRepo(); var user = repo.GetUser(userName); if (user == null) { ViewBag.Error = "No account with that username"; return(View()); } if (user.passWord != passWord) { ViewBag.Error = "Incorrect password"; return(View()); } // pass accounts user ID to details view return(RedirectToAction("Details", new { userID = user.userID })); }
public UnitOfWork(ExamicaDbContext _context) { context = _context; Answers = new AnswerRepo(_context); AppUsers = new AppUserRepo(_context); ComplexQuestions = new ComplexQuestionRepo(_context); ExamAppUsers = new ExamAppUserRepo(_context); ExamComplexQuestions = new ExamComplexQuestionRepo(_context); ExamQuestions = new ExamQuestionRepo(_context); Exams = new ExamRepo(_context); Options = new OptionRepo(_context); OrganizationAdmins = new OrganizationAdminRepo(_context); organizationExaminees = new OrganizationExamineeRepo(_context); OrganizationExaminers = new OrganizationExaminerRepo(_context); OrganizationObservers = new OrganizationObsereverRepo(_context); Organizations = new OrganizationRepo(_context); QuestionComplexQuestions = new QuestionComplexQuestionRepo(_context); Questions = new QuestionRepo(_context); QuestionOptions = new QuestionOptionRepo(_context); Results = new ResultRepo(_context); PricingPlans = new PricingPlanRepo(_context); }
public void AddRestaurantToFavoritesShouldThrowExceptionIfUserNotInDB(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyDB9") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; bool result = false; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); try { if (useAsync) { uRepo.AddRestaurantToFavoritesAsync(username, "literally anything", rRepo).Wait(); } else { uRepo.AddRestaurantToFavorites(username, "literally anything", rRepo); } } catch (DbUpdateException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }
public void AddRestaurantToBlacklistShouldThrowExceptionIfRestaurantNotInDB(string username, string rId, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyAddTesting3DB") .Options; AppUserRepo uRepo; RestaurantRepo rRepo; bool result = false; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); rRepo = new RestaurantRepo(context); try { if (useAsync) { uRepo.AddRestaurantToBlacklistAsync(username, rId, rRepo).Wait(); } else { uRepo.AddRestaurantToBlacklist(username, rId, rRepo); } } catch (DbUpdateException) { result = true; } catch (AggregateException) { result = true; } } //Assert Assert.True(result); }
public void AddUserShouldThrowExceptionIfUsernameAlreadyInDB(string username) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyAddTesting1DB") .Options; AppUser u = new AppUser { Username = username, FirstName = "a", LastName = "b", Email = "e" }; AppUser u2 = new AppUser { Username = username, FirstName = "blah", LastName = "bleh", Email = "e" }; AppUserRepo uRepo; bool result = false; using (var context = new Project2DBContext(options)) { context.AppUser.Add(u2); context.SaveChanges(); } //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); try { uRepo.AddUser(u); } catch (DbUpdateException) { result = true; } } //Assert Assert.True(result); }
public void GetOwnedRestaurantsForUserShouldThrowExceptionIfIsUsernameNotFound(string username, bool useAsync) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "StaticFilledUserDB") .Options; bool result = false; AppUserRepo uRepo; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); try { if (useAsync) { uRepo.GetOwnedRestaurantsForUserAsync(username).Wait(); } else { uRepo.GetOwnedRestaurantsForUser(username); } } catch (NotSupportedException) { result = true; } catch (AggregateException) { result = true; } } //If exception is throw, test will exit before reaching Assert //Assert Assert.True(result); }
public void AddUserShouldAddCorrectUsertoDB(string username) { //Arrange var options = new DbContextOptionsBuilder <Project2DBContext>() .UseInMemoryDatabase(databaseName: "EmptyAddTesting2DB") .Options; AppUser u = new AppUser { Username = username, FirstName = "a", LastName = "b", Email = "e" }; AppUserRepo uRepo; AppUser result; //Act using (var context = new Project2DBContext(options)) { uRepo = new AppUserRepo(context); uRepo.AddUser(u); result = context.AppUser.Find(username); } //Assert Assert.Equal(u, result); }
public AccountController(IConfiguration config, IWebHostEnvironment webHostEnvironment, IHttpContextAccessor httpContextAccessor) : base(config, webHostEnvironment, httpContextAccessor) { _AppUserRepo = new AppUserRepo(ConnString); }