public async Task<IActionResult> Create(UserInput input) { var user = new User {UserName = input.Username, Email = input.Email}; var result = await _userManager.CreateAsync(user, input.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(_userManager.FindByEmailAsync(input.Email).Result, "User"); //Adds UserDetails for newly added user var repo = new UserDetailsRepository(); var userDetails = new UserDetails(); userDetails.UserId = _userManager.FindByEmailAsync(input.Email).Result.Id; repo.Add(userDetails); var detailsId = repo.GetAll() .First(x => x.UserId == _userManager.FindByEmailAsync(input.Email).Result.Id).Id; user.DetailsId = detailsId; await _userManager.UpdateAsync(user); _logger.LogInformation("Account Created",user); return Ok(); } return BadRequest(result.Errors); }
public void GetAllUsersInSchool() { var repo = new SchoolRepository(); var userRepo = new UserDetailsRepository(); var schoolId = repo.GetAll().Last().Id; userRepo.Add(new UserDetails("null", null, schoolId)); var users = repo.GetAll().Last().Users; Assert.True(users.Count > 0); }
public void Delete_Normal_Conditions() { var repo = new CandidacyRepository(); var user = new UserDetails(); var userRepo = new UserDetailsRepository(); userRepo.Add(user); var candidacy = new Candidacy("John", "empty description", "empty", user); repo.Add(candidacy); repo.Delete(repo.GetAll().FirstOrDefault()); }
public void Edit_Normal_Conditions() { var repo = new CandidacyRepository(); var user = new UserDetails(); var userRepo = new UserDetailsRepository(); userRepo.Add(user); var candidacy = new Candidacy("John", "empty description", "empty", user); repo.Add(candidacy); var temp = repo.GetAll().FirstOrDefault(); temp.PhotoPath = "foo"; temp.Description = "bar"; repo.Edit(temp); }
public void Edit_PhotoPath_Null() { var repo = new CandidacyRepository(); var user = new UserDetails(); var userRepo = new UserDetailsRepository(); userRepo.Add(user); var candidacy = new Candidacy("John", "empty description", "empty", user); repo.Add(candidacy); var temp = repo.GetAll().FirstOrDefault(); Assert.Throws <ArgumentNullException>(() => { temp.PhotoPath = null; temp.Description = "bar"; repo.Edit(temp); }); }