public ActionResult Index() { EmailSendVM model = new EmailSendVM(); CandidatesService canService = new CandidatesService(); model.Recievers = canService.GetAll(); TryUpdateModel(model); if (!String.IsNullOrEmpty(model.Search)) { switch (model.SearchType) { case SearchEnum.UsedTechnology: EmailService.Recievers = model.Recievers.Where(c => c.UsedTechnologies .Any(t => t.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.ProgrammingLanguage: EmailService.Recievers = model.Recievers.Where(c => c.ProgrammingLanguages .Any(p => p.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.Name: default: EmailService.Recievers = model.Recievers.Where(c => c.FirstName.ToLower().Contains(model.Search.ToLower()) || c.LastName.ToLower().Contains(model.Search.ToLower())).ToList(); break; } } return(View(model)); }
public ActionResult Index() { EmailSendVM model = new EmailSendVM(); CandidatesService canService = new CandidatesService(); model.Recievers = canService.GetAll(); TryUpdateModel(model); if (!String.IsNullOrEmpty(model.Search)) { switch (model.SearchType) { case SearchEnum.UsedTechnology: EmailService.Recievers = model.Recievers.Where(c => c.UsedTechnologies .Any(t => t.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.ProgrammingLanguage: EmailService.Recievers = model.Recievers.Where(c => c.ProgrammingLanguages .Any(p => p.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.Name: default: EmailService.Recievers = model.Recievers.Where(c => c.FirstName.ToLower().Contains(model.Search.ToLower()) || c.LastName.ToLower().Contains(model.Search.ToLower())).ToList(); break; } } return View(model); }
public ActionResult Edit(int?id) { CandidatesService candidatesService = new CandidatesService(); CandidateEditVM model = new CandidateEditVM(); Candidate candidate; if (!id.HasValue) { candidate = new Candidate(); } else { candidate = candidatesService.GetById(id.Value); if (candidate == null) { return(RedirectToAction("List")); } } model.Id = candidate.Id; model.FirstName = candidate.FirstName; model.MiddleName = candidate.MiddleName; model.LastName = candidate.LastName; model.Email = candidate.Email; model.Notes = candidate.Notes; model.UsedTechnologies = candidatesService.GetSelectedUsedTechnologies(candidate.UsedTechnologies); model.ProgrammingLanguages = candidatesService.GetSelectedProgrammingLanguages(candidate.ProgrammingLanguages); return(View(model)); }
public async Task Shoud_Get_Candidates_In_CandidateService() { var candidates = GetCandidateModelFixture(); var candidatesDTO = new List <CandidateDTO>(); candidatesDTO = candidates.Select(d => new CandidateDTO(d.FirstName, d.LastName, d.Test.Title, 3)).ToList(); var testModel = new List <TestModel>(); testModel.Add(new TestModel("c#", 1, 10)); testModel.Add(new TestModel("python", 2, 10)); testModel.Add(new TestModel(".net core", 3, 10)); var answers = new List <AnswerModel>(); answers.Add(new AnswerModel(1, 1, "1", "a", 1)); answers.Add(new AnswerModel(2, 2, "2", "b", 1)); answers.Add(new AnswerModel(3, 3, "3", "c", 1)); var mockRepository = Substitute.For <ICandidatesRepository>(); var logger = Substitute.For <ILog>(); mockRepository.GetCandidatesAsync().Returns(candidates); mockRepository.GetTestsAsync().Returns(testModel); mockRepository.GetAnswersAsync().Returns(answers); var candidateService = new CandidatesService(mockRepository, logger); var result = await candidateService.GetCandidatesAsync(); string serialize1 = JsonConvert.SerializeObject(candidatesDTO); string serialize2 = JsonConvert.SerializeObject(result); Assert.AreEqual(serialize1, serialize2); }
public ActionResult Edit(int? id) { CandidatesService candidatesService = new CandidatesService(); CandidateEditVM model = new CandidateEditVM(); Candidate candidate; if (!id.HasValue) { candidate = new Candidate(); } else { candidate = candidatesService.GetById(id.Value); if (candidate == null) { return RedirectToAction("List"); } } model.Id = candidate.Id; model.FirstName = candidate.FirstName; model.MiddleName = candidate.MiddleName; model.LastName = candidate.LastName; model.Email = candidate.Email; model.Notes = candidate.Notes; model.UsedTechnologies = candidatesService.GetSelectedUsedTechnologies(candidate.UsedTechnologies); model.ProgrammingLanguages = candidatesService.GetSelectedProgrammingLanguages(candidate.ProgrammingLanguages); return View(model); }
public void CheckIfCandidateAlreadyAppliedTest() { var mockRepository = new Mock <IDeletableEntityRepository <Candidate> >(); mockRepository.Setup(x => x.All()).Returns(this.GetCandidatesData()); var service = new CandidatesService(mockRepository.Object); var check = service.CheckIfCandidateAlreadyApplied("1", "2"); Assert.True(check); }
public ActionResult Delete(int?id) { if (!id.HasValue) { return(RedirectToAction("List")); } CandidatesService candidatesService = new CandidatesService(); candidatesService.Delete(id.Value); return(RedirectToAction("List")); }
public ActionResult List() { CandidatesService candidatesService = new CandidatesService(); CandidateListVM model = new CandidateListVM(); model.Candidates = candidatesService.GetAll(); TryUpdateModel(model); // search if (!String.IsNullOrEmpty(model.Search)) { switch (model.SearchType) { case SearchEnum.UsedTechnology: model.Candidates = model.Candidates.Where(c => c.UsedTechnologies .Any(t => t.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.ProgrammingLanguage: model.Candidates = model.Candidates.Where(c => c.ProgrammingLanguages .Any(p => p.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.Name: default: model.Candidates = model.Candidates.Where(c => c.FirstName.ToLower().Contains(model.Search.ToLower()) || c.LastName.ToLower().Contains(model.Search.ToLower())).ToList(); break; } } // sort switch (model.SortOrder) { case "lname_asc": model.Candidates = model.Candidates.OrderBy(c => c.LastName).ToList(); break; case "lname_desc": model.Candidates = model.Candidates.OrderByDescending(c => c.LastName).ToList(); break; case "fname_desc": model.Candidates = model.Candidates.OrderByDescending(c => c.FirstName).ToList(); break; case "fname_asc": default: model.Candidates = model.Candidates.OrderBy(c => c.FirstName).ToList(); break; } return(View(model)); }
/// <summary> /// Konstruktor klasy HomeController. Przez parametry konstruktora wstrzykujemy wszystkie potrzebne klasy, /// które zostały zarejestrowane w klasie Startup. /// </summary> public HomeController( ILogger <HomeController> logger, TokenGenerator tokenGenerator, TokensService tokensService, CandidatesService candidatesService, UsersService usersService, UserManager <ApplicationUser> userManager ) { _logger = logger; _tokenGenerator = tokenGenerator; _tokensService = tokensService; _candidatesService = candidatesService; _usersService = usersService; _userManager = userManager; }
public void GetAllJobPostingsIdsTest() { var mockRepository = new Mock <IDeletableEntityRepository <Candidate> >(); mockRepository.Setup(x => x.All()).Returns(this.GetCandidatesData()); var service = new CandidatesService(mockRepository.Object); var check = service.GetAllJobPostingsIds("1"); var listOfJobPostings = new List <string> { "2" }; Assert.Equal(listOfJobPostings, check); }
public ActionResult List() { CandidatesService candidatesService = new CandidatesService(); CandidateListVM model = new CandidateListVM(); model.Candidates = candidatesService.GetAll(); TryUpdateModel(model); // search if (!String.IsNullOrEmpty(model.Search)) { switch (model.SearchType) { case SearchEnum.UsedTechnology: model.Candidates = model.Candidates.Where(c => c.UsedTechnologies .Any(t => t.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.ProgrammingLanguage: model.Candidates = model.Candidates.Where(c => c.ProgrammingLanguages .Any(p => p.Name.ToLower().Contains(model.Search.ToLower()))).ToList(); break; case SearchEnum.Name: default: model.Candidates = model.Candidates.Where(c => c.FirstName.ToLower().Contains(model.Search.ToLower()) || c.LastName.ToLower().Contains(model.Search.ToLower())).ToList(); break; } } // sort switch (model.SortOrder) { case "lname_asc": model.Candidates = model.Candidates.OrderBy(c => c.LastName).ToList(); break; case "lname_desc": model.Candidates = model.Candidates.OrderByDescending(c => c.LastName).ToList(); break; case "fname_desc": model.Candidates = model.Candidates.OrderByDescending(c => c.FirstName).ToList(); break; case "fname_asc": default: model.Candidates = model.Candidates.OrderBy(c => c.FirstName).ToList(); break; } return View(model); }
public async Task UpdateProfileCorrectlyRemovesOldLanguagesAndSkills() { 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 = new CandidatesService(candidatesRepository, languagesRepository, skillsRepository, null); var candidateId = await candidatesService.CreateProfileAsync(new CreateCandidateProfileInputModel { FirstName = "Ivan", LastName = "Ivanov", ApplicationUserId = "1", LanguagesIds = new List <int> { 1 }, SkillsIds = new List <int> { 1 } }); var updateModel = new UpdateCandidateProfileViewModel { LanguagesIds = new List <int> { 2, 3 }, SkillsIds = new List <int> { 4, 5 }, }; await candidatesService.UpdateProfileAsync(candidateId, updateModel); var candidateLanguages = await context.Candidates .Where(c => c.Id == candidateId) .Select(c => c.Languages.Select(l => l.LanguageId).ToList()) .FirstOrDefaultAsync(); var candidateSkills = await context.Candidates .Where(c => c.Id == candidateId) .Select(c => c.Skills.Select(l => l.SkillId).ToList()) .FirstOrDefaultAsync(); Assert.Equal(2, candidateLanguages.Count); Assert.Equal(2, candidateSkills.Count); Assert.Contains(2, candidateLanguages); Assert.Contains(3, candidateLanguages); Assert.Contains(4, candidateSkills); Assert.Contains(5, candidateSkills); }
private void BindCandidatesGrid() { if (CachedCandidates == null) { string searchString = ""; if (txtMinimumExp.Text != "") { searchString += "YearsExperience='" + txtMinimumExp.Text + "'"; } if (txtTherapicExp.Text != "") { searchString += (searchString == "" ? "" : " OR ") + "TherapeuticExperience='" + txtTherapicExp.Text + "'"; } if (ddlFieldExp.SelectedIndex != 0) { searchString += (searchString == "" ? "" : " OR ") + "FieldTypeExperience='" + ddlFieldExp.SelectedValue + "'"; } CandidatesService objCandidatesService = new CandidatesService(); if (searchString != "") { TList <Candidates> objCandidatesList = objCandidatesService.Find(searchString); DataSet ds = objCandidatesList.ToDataSet(false); ds.Tables[0].Columns.Add(new DataColumn("Selected", System.Type.GetType("System.Boolean"))); ds.Tables[0].PrimaryKey = new DataColumn[] { ds.Tables[0].Columns["CandidateID"] }; CachedCandidates = ds;//caching data becuase we want to track candidates user select GVCandidates.DataSource = ds; GVCandidates.DataBind(); } else { GVCandidates.DataBind(); } } else { GVCandidates.DataSource = CachedCandidates; GVCandidates.DataBind(); } }
public async Task Shoud_Get_EcartType_In_CandidateService(double ecartType) { var testModel = new List <TestModel>(); testModel.Add(new TestModel("c#a", 1, 10)); testModel.Add(new TestModel("c#b", 2, 10)); testModel.Add(new TestModel("c#c", 3, 10)); testModel.Add(new TestModel("c#d", 4, 10)); var answers = new List <AnswerModel>(); answers.Add(new AnswerModel(1, 1, "1", "a", 1)); answers.Add(new AnswerModel(2, 2, "2", "b", 0)); answers.Add(new AnswerModel(3, 3, "3", "c", 1)); answers.Add(new AnswerModel(4, 4, "4", "d", 0)); var results = new List <ResultModel>(); results.Add(new ResultModel(1, true)); results.Add(new ResultModel(2, false)); results.Add(new ResultModel(3, true)); results.Add(new ResultModel(4, false)); var candidates = new List <Candidate>() { new Candidate("minamba", "camara", testModel[0], results), new Candidate("naruto", "uzumaki", testModel[1], results), new Candidate("sasuke", "uchiha", testModel[2], results), new Candidate("madara", "uchiha", testModel[3], results), }; var mockRepository = Substitute.For <ICandidatesRepository>(); var logger = Substitute.For <ILog>(); mockRepository.GetCandidatesAsync().Returns(candidates); mockRepository.GetTestsAsync().Returns(testModel); mockRepository.GetAnswersAsync().Returns(answers); var candidateService = new CandidatesService(mockRepository, logger); double result = await candidateService.GetEcartTypeAsync(); Assert.AreEqual(ecartType, result); }
public async Task Shoud_Get_Average_LOG_In_CandidateService_with_0_value() { var testModel = new List <TestModel>(); testModel.Add(new TestModel("c#a", 1, 10)); testModel.Add(new TestModel("c#b", 2, 10)); testModel.Add(new TestModel("c#c", 3, 10)); testModel.Add(new TestModel("c#d", 4, 10)); var answers = new List <AnswerModel>(); answers.Add(new AnswerModel(1, 1, "1", "a", 0)); answers.Add(new AnswerModel(2, 2, "2", "b", 0)); answers.Add(new AnswerModel(3, 3, "3", "c", 0)); answers.Add(new AnswerModel(4, 4, "4", "d", 0)); var results = new List <ResultModel>(); results.Add(new ResultModel(1, false)); results.Add(new ResultModel(2, false)); results.Add(new ResultModel(3, false)); results.Add(new ResultModel(4, false)); var candidates = new List <Candidate>() { new Candidate("minamba", "camara", testModel[0], results), new Candidate("naruto", "uzumaki", testModel[1], results), new Candidate("sasuke", "uchiha", testModel[2], results), }; var mockRepository = Substitute.For <ICandidatesRepository>(); var logger = Substitute.For <ILog>(); mockRepository.GetCandidatesAsync().Returns(candidates); mockRepository.GetTestsAsync().Returns(testModel); mockRepository.GetAnswersAsync().Returns(answers); var candidateService = new CandidatesService(mockRepository, logger); logger.Received(1).Error(candidateService.GetAverageAsync().ToString()); }
[DataRow(8)] // Un autre moyen de passer des paramètres pour les tests public async Task Shoud_Get_Average_In_CandidateService(double average) { var testModel = new List <TestModel>(); testModel.Add(new TestModel("c#a", 1, 10)); testModel.Add(new TestModel("c#b", 2, 10)); testModel.Add(new TestModel("c#c", 3, 10)); testModel.Add(new TestModel("c#d", 4, 10)); var answers = new List <AnswerModel>(); answers.Add(new AnswerModel(1, 1, "1", "a", 1)); answers.Add(new AnswerModel(2, 2, "2", "b", 0)); answers.Add(new AnswerModel(3, 3, "3", "c", 1)); answers.Add(new AnswerModel(4, 4, "4", "d", 0)); var results = new List <ResultModel>(); results.Add(new ResultModel(1, true)); results.Add(new ResultModel(2, false)); results.Add(new ResultModel(3, true)); results.Add(new ResultModel(4, false)); var candidates = new List <Candidate>() { new Candidate("minamba", "camara", testModel[0], results), new Candidate("naruto", "uzumaki", testModel[1], results), new Candidate("sasuke", "uchiha", testModel[2], results), }; var mockRepository = Substitute.For <ICandidatesRepository>(); var logger = Substitute.For <ILog>(); mockRepository.GetCandidatesAsync().Returns(candidates); mockRepository.GetTestsAsync().Returns(testModel); mockRepository.GetAnswersAsync().Returns(answers); var candidateService = new CandidatesService(mockRepository, logger); double result = await candidateService.GetAverageAsync(); Assert.AreEqual(average, result); // Pas beson de serialization car ce ne sont pas des types références (c'est à dire des objets) mais des types valeurs donc direct Assert.AreEqual }
public ActionResult Edit() { CandidatesService candidatesService = new CandidatesService(); CandidateEditVM model = new CandidateEditVM(); TryUpdateModel(model); Candidate candidate; if (model.Id == 0) { candidate = new Candidate(); } else { candidate = candidatesService.GetById(model.Id); if (candidate == null) { return(RedirectToAction("List")); } } if (!ModelState.IsValid) { model.UsedTechnologies = candidatesService.GetSelectedUsedTechnologies(candidate.UsedTechnologies); model.ProgrammingLanguages = candidatesService.GetSelectedProgrammingLanguages(candidate.ProgrammingLanguages); return(View(model)); } candidate.Id = model.Id; candidate.FirstName = model.FirstName; candidate.MiddleName = model.MiddleName; candidate.LastName = model.LastName; candidate.Email = model.Email; candidate.Notes = model.Notes; candidatesService.SetSelectedUsedTechnologies(candidate, model.SelectedUsedTechnologies); candidatesService.SetSelectedProgrammingLanguages(candidate, model.SelectedProgrammingLanguages); candidatesService.Save(candidate); return(RedirectToAction("List")); }
public async Task Shoud_Add_CandidateTest_In_CandidateService() { var candidate = new Candidate() { FirstName = "Minamba", LastName = "Camara", Test = new TestModel() { Title = "c#" } }; var mockRepository = Substitute.For <ICandidatesRepository>(); var logger = Substitute.For <ILog>(); mockRepository.AddCandidateTestAsync(candidate).Returns(candidate); var candidateService = new CandidatesService(mockRepository, logger); var result = await candidateService.AddCandidateTestAsync(candidate); Assert.AreEqual(candidate, result); }
public async Task CreateNewCandidateForJobPostingAsyncTest() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Candidate>(new ApplicationDbContext(options.Options)); foreach (var item in this.GetCandidatesData()) { await repository.AddAsync(item); await repository.SaveChangesAsync(); } var service = new CandidatesService(repository); await service.CreateNewCandidateForJobPostingAsync("8", "9"); var candidatesCount = repository.All().ToList().Count; Assert.Equal(4, candidatesCount); }
public async Task MarkAllApplyingsAsDeleted() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfDeletableEntityRepository <Candidate>(new ApplicationDbContext(options.Options)); foreach (var item in this.GetCandidatesData()) { await repository.AddAsync(item); await repository.SaveChangesAsync(); } var service = new CandidatesService(repository); await service.MarkAllApplyingsAsDeleted("1"); var user = repository.AllWithDeleted().Where(x => x.UserId == "1").FirstOrDefault(); Assert.True(user.IsDeleted); }
public ActionResult Delete(int? id) { if (!id.HasValue) { return RedirectToAction("List"); } CandidatesService candidatesService = new CandidatesService(); candidatesService.Delete(id.Value); return RedirectToAction("List"); }
public ActionResult Edit() { CandidatesService candidatesService = new CandidatesService(); CandidateEditVM model = new CandidateEditVM(); TryUpdateModel(model); Candidate candidate; if (model.Id == 0) { candidate = new Candidate(); } else { candidate = candidatesService.GetById(model.Id); if (candidate == null) { return RedirectToAction("List"); } } if (!ModelState.IsValid) { model.UsedTechnologies = candidatesService.GetSelectedUsedTechnologies(candidate.UsedTechnologies); model.ProgrammingLanguages = candidatesService.GetSelectedProgrammingLanguages(candidate.ProgrammingLanguages); return View(model); } candidate.Id = model.Id; candidate.FirstName = model.FirstName; candidate.MiddleName = model.MiddleName; candidate.LastName = model.LastName; candidate.Email = model.Email; candidate.Notes = model.Notes; candidatesService.SetSelectedUsedTechnologies(candidate, model.SelectedUsedTechnologies); candidatesService.SetSelectedProgrammingLanguages(candidate, model.SelectedProgrammingLanguages); candidatesService.Save(candidate); return RedirectToAction("List"); }