public async Task IfProfilePictureIsNotNullCreateProfileSavesCorrectLink() { AutoMapperInitializer.InitializeMapper(); var context = InMemoryDbContextInitializer.InitializeContext(); var candidateRepository = new EfDeletableEntityRepository <Candidate>(context); var cloudinary = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret)); var candidatesService = this.GetMockedService(candidateRepository, null, null, cloudinary); var profilePicture = this.PrepareImage(); var model = new CreateCandidateProfileInputModel { FirstName = "Ivan", LastName = "Ivanov", ApplicationUserId = "1", ProfilePicture = profilePicture, }; var candidateId = await candidatesService.CreateProfileAsync(model); Assert.NotNull(candidateId); var pictureUrl = context.Candidates.Find(candidateId).ProfilePictureUrl; Assert.NotNull(pictureUrl); Assert.Contains(model.ApplicationUserId + "_profilePicture", pictureUrl); CloudinaryService.DeleteFile(cloudinary, model.ApplicationUserId + "_profilePicture"); }
public IActionResult CreateProfile() { var candidateId = this.candidatesService.GetCandidateIdByUsername(this.User.Identity.Name); if (candidateId != null) { return(this.RedirectToAction(nameof(this.UpdateProfile))); } var viewModel = new CreateCandidateProfileInputModel { ImageExtensions = this.allowedExtensions, Languages = this.languages, Skills = this.skills, }; return(this.View(viewModel)); }
public async Task CreateProfileAsyncSavesInfoCorrectly() { AutoMapperInitializer.InitializeMapper(); var context = InMemoryDbContextInitializer.InitializeContext(); var candidatesRepository = new EfDeletableEntityRepository <Candidate>(context); var languagesRepository = new EfDeletableEntityRepository <CandidateLanguage>(context); var skillsRepository = new EfDeletableEntityRepository <CandidateSkill>(context); var candidatesService = this.GetMockedService(candidatesRepository, languagesRepository, skillsRepository, null); var model = new CreateCandidateProfileInputModel { AboutMe = "some info", ApplicationUserId = "11", ContactAddress = "address", FirstName = "Georgi", LastName = "Georgiev", LanguagesIds = new List <int> { 1, 2, 3 }, SkillsIds = new List <int> { 4, 5, 6 }, }; var candidateId = await candidatesService.CreateProfileAsync(model); Assert.NotNull(candidateId); var record = await context.Candidates.Include(c => c.Languages).Include(c => c.Skills).Where(c => c.Id == candidateId).FirstOrDefaultAsync(); Assert.Equal(model.AboutMe, record.AboutMe); Assert.Equal(model.ApplicationUserId, record.ApplicationUserId); Assert.Equal(model.ContactAddress, record.ContactAddress); Assert.Null(record.Education); Assert.Null(record.PhoneNumber); Assert.Null(record.ProfilePictureUrl); Assert.Equal(3, record.Languages.Count()); Assert.Equal(3, record.Skills.Count()); }
public async Task <IActionResult> CreateProfile(CreateCandidateProfileInputModel input) { if (this.candidatesService.GetCandidateIdByUsername(this.User.Identity.Name) != null) { return(this.RedirectToAction(nameof(this.UpdateProfile))); } if (!this.ModelState.IsValid) { input.ImageExtensions = this.allowedExtensions; input.Languages = this.languages; input.Skills = this.skills; return(this.View(input)); } if (input.ProfilePicture != null && !this.allowedExtensions.Any(ae => input.ProfilePicture.FileName.EndsWith(ae))) { this.ModelState.AddModelError(string.Empty, GlobalConstants.FileExtensionNotSupported); input.ImageExtensions = this.allowedExtensions; return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); input.ApplicationUserId = user.Id; var candidateId = await this.candidatesService.CreateProfileAsync(input); if (candidateId == null) { return(this.RedirectToAction("Error", "Home")); } user.CandidateId = candidateId; await this.userManager.UpdateAsync(user); this.TempData["Success"] = GlobalConstants.ProfileSuccessfullyCreated; return(this.RedirectToAction("Upload", "Documents")); }
public async Task IfPictureIsInvalidCreateProfileReturnsNull() { AutoMapperInitializer.InitializeMapper(); var context = InMemoryDbContextInitializer.InitializeContext(); var candidatesRepository = new EfDeletableEntityRepository <Candidate>(context); var cloudinary = new Cloudinary(new Account(CloudinaryConfig.CloudName, CloudinaryConfig.ApiKey, CloudinaryConfig.ApiSecret)); var candidatesService = this.GetMockedService(candidatesRepository, null, null, cloudinary); var profilePicture = this.PrepareInvalidImage(); var model = new CreateCandidateProfileInputModel { FirstName = "Ivan", LastName = "Ivanov", ApplicationUserId = "1", ProfilePicture = profilePicture, }; var candidateId = await candidatesService.CreateProfileAsync(model); Assert.Null(candidateId); }
public async Task <string> CreateProfileAsync(CreateCandidateProfileInputModel model) { var candidate = AutoMapperConfig.MapperInstance.Map <Candidate>(model); if (model.ProfilePicture != null) { var pictureUrl = await CloudinaryService.UploadImageAsync(this.cloudinary, model.ProfilePicture, model.ApplicationUserId + PictureNameAddIn); if (pictureUrl == null) { return(null); } candidate.ProfilePictureUrl = pictureUrl; } candidate.CreatedOn = DateTime.UtcNow; var candidateLanguages = new List <CandidateLanguage>(); foreach (var languageId in model.LanguagesIds) { var language = new CandidateLanguage { Candidate = candidate, LanguageId = languageId, CreatedOn = DateTime.UtcNow, }; candidateLanguages.Add(language); } var candidateSkills = new List <CandidateSkill>(); foreach (var skillId in model.SkillsIds) { var skill = new CandidateSkill { Candidate = candidate, SkillId = skillId, CreatedOn = DateTime.UtcNow, }; candidateSkills.Add(skill); } try { await this.candidatesRepository.AddAsync(candidate); await this.candidateLanguagesRepository.AddRangeAsync(candidateLanguages); await this.candidateSkillsRepository.AddRangeAsync(candidateSkills); await this.candidatesRepository.SaveChangesAsync(); await this.candidateLanguagesRepository.SaveChangesAsync(); await this.candidateSkillsRepository.SaveChangesAsync(); return(candidate.Id); } catch (Exception) { return(null); } }