public async Task IfCategoryExistsThenItIsUpdated() { var jobCategoryGuid = Guid.NewGuid(); _siteFinityHttpService.GetAll <SiteFinityTrait>("traits").Returns(Task.FromResult(new List <SiteFinityTrait> { new SiteFinityTrait { Name = "Leader", JobProfileCategories = new List <Guid> { jobCategoryGuid } } })); _siteFinityHttpService.GetTaxonomyInstances("Job Profile Category").Returns(Task.FromResult( new List <TaxonomyHierarchy> { new TaxonomyHierarchy { Id = jobCategoryGuid, Title = "Animal care" } })); _jobCategoryRepository.GetJobCategory("AC").Returns(Task.FromResult(new JobCategory { Name = "Animal care" })); await _sut.RunOnce(_logger); await _jobCategoryRepository.Received(1).CreateOrUpdateJobCategory(Arg.Any <JobCategory>()); }
public async Task RunOnce(ILogger logger) { logger.LogInformation("Begin poll for JobCategories"); var data = await GetData(_appSettings.SiteFinityJobCategoriesTaxonomyId); logger.LogInformation($"Have {data?.Count} job Categorys to save"); foreach (var jobCategory in data) { var code = JobCategoryHelper.GetCode(jobCategory.Title); // Remove any old job categories that have this title but will have a different code var category = await _jobCategoryRepository.GetJobCategory(code); if (category == null) { category = new JobCategory() { Name = jobCategory.Title, Texts = new[] { new JobCategoryText() { LanguageCode = "en", Text = jobCategory.Description, Url = $"{jobCategory.UrlName}" } }, Traits = jobCategory.Traits.Select(x => x.ToUpper()).ToArray(), PartitionKey = partitionKey }; } else { category.Name = jobCategory.Title; category.Texts = new[] { new JobCategoryText() { LanguageCode = "en", Text = jobCategory.Description, Url = $"{jobCategory.UrlName}" } }; category.Traits = jobCategory.Traits.Select(x => x.ToUpper()).ToArray(); category.PartitionKey = partitionKey; } await _jobCategoryRepository.CreateOrUpdateJobCategory(category); } logger.LogInformation("End poll for JobCategories"); }
public async Task UpdatesAllOfTheCategoriesIfNotExist() { _siteFinityHttpService .GetAll <SiteFinityJobProfile>( "jobprofiles?$select=Id,Title,JobProfileCategories&$expand=RelatedSkills&$orderby=Title") .Returns(Task.FromResult(JobProfiles)); _siteFinityHttpService.GetTaxonomyInstances("Job Profile Category").Returns(Task.FromResult(JobCategories)); _jobCategoryRepository.GetJobCategory(Arg.Any <string>()).Returns(Task.FromResult(new JobCategory())); await _sut.RunOnce(_logger); await _jobCategoryRepository.Received(JobCategories.Count).CreateOrUpdateJobCategory(Arg.Any <JobCategory>()); }
private async Task CreateJobCategoryQuestionSet(JobCategorySkillMappingResult skillsMapping) { // Remove any old job categories that have this title but will have a different code var category = await _jobCategoryRepository.GetJobCategory(JobCategoryHelper.GetCode(skillsMapping.JobCategory)); if (category != null) { category.Skills.Clear(); category.Skills.AddRange(skillsMapping.SkillMappings); } else { _logger.LogError($"Unable to add skills to category {skillsMapping.JobCategory} - the category does not exist"); } await _jobCategoryRepository.CreateOrUpdateJobCategory(category); }
public async Task CalculateAssessement_ShouldReturn_CorrectSelectedJobProfiles(AnswerOption a, AnswerOption b, AnswerOption c, AnswerOption d, string profiles) { _questionRepository.GetQuestions("qs-1").Returns(Task.FromResult(new [] { new Question { QuestionId = "1", TraitCode = "A" }, new Question { QuestionId = "2", TraitCode = "B" }, new Question { QuestionId = "3", TraitCode = "C" }, new Question { QuestionId = "4", TraitCode = "D" } })); _jobCategoryRepository.GetJobCategory("AC").Returns(Task.FromResult(new JobCategory { Name = "Animal Care", Skills = new List <JobProfileSkillMapping> { new JobProfileSkillMapping { ONetAttribute = "A", JobProfiles = new List <JobProfileMapping> { new JobProfileMapping { JobProfile = "JP1", Included = true }, new JobProfileMapping { JobProfile = "JP2", Included = true }, new JobProfileMapping { JobProfile = "JP3", Included = true }, new JobProfileMapping { JobProfile = "JP4", Included = false }, new JobProfileMapping { JobProfile = "JP5", Included = true }, } }, new JobProfileSkillMapping { ONetAttribute = "B", JobProfiles = new List <JobProfileMapping> { new JobProfileMapping { JobProfile = "JP1", Included = true }, new JobProfileMapping { JobProfile = "JP2", Included = false }, new JobProfileMapping { JobProfile = "JP3", Included = true }, new JobProfileMapping { JobProfile = "JP4", Included = false }, new JobProfileMapping { JobProfile = "JP5", Included = true }, } }, new JobProfileSkillMapping { ONetAttribute = "C", JobProfiles = new List <JobProfileMapping> { new JobProfileMapping { JobProfile = "JP1", Included = false }, new JobProfileMapping { JobProfile = "JP2", Included = false }, new JobProfileMapping { JobProfile = "JP3", Included = true }, new JobProfileMapping { JobProfile = "JP4", Included = false }, new JobProfileMapping { JobProfile = "JP5", Included = true }, } }, new JobProfileSkillMapping { ONetAttribute = "D", JobProfiles = new List <JobProfileMapping> { new JobProfileMapping { JobProfile = "JP1", Included = false }, new JobProfileMapping { JobProfile = "JP2", Included = true }, new JobProfileMapping { JobProfile = "JP3", Included = true }, new JobProfileMapping { JobProfile = "JP4", Included = false }, new JobProfileMapping { JobProfile = "JP5", Included = true }, } } } })); var categoryResult = new JobCategoryResult { JobCategoryName = "Animal Care" }; var session = new UserSession { ResultData = new ResultData { JobCategories = new [] { categoryResult } }, AssessmentState = new AssessmentState("q-1", 1) { RecordedAnswers = new [] { new Answer { QuestionNumber = 1, SelectedOption = AnswerOption.Agree }, }, CurrentQuestion = 1 }, FilteredAssessmentState = new FilteredAssessmentState { CurrentFilterAssessmentCode = "AC", RecordedAnswers = new[] { new Answer { TraitCode = "A", SelectedOption = a }, new Answer { TraitCode = "B", SelectedOption = b }, new Answer { TraitCode = "C", SelectedOption = c }, new Answer { TraitCode = "D", SelectedOption = d } }, JobCategoryStates = new List <JobCategoryState> { new JobCategoryState("AC", "Animal Care", "qs-1", new[] { new JobCategorySkill { QuestionNumber = 1, Skill = "A" }, new JobCategorySkill { QuestionNumber = 2, Skill = "B" }, new JobCategorySkill { QuestionNumber = 3, Skill = "C" }, new JobCategorySkill { QuestionNumber = 4, Skill = "D" }, }) } } }; await _sut.CalculateAssessment(session, _logger); if (String.IsNullOrEmpty(profiles)) { Assert.Empty(categoryResult.FilterAssessmentResult.SuggestedJobProfiles); } else { foreach (var profile in profiles.Split(",", StringSplitOptions.RemoveEmptyEntries)) { Assert.Contains(profile, categoryResult.FilterAssessmentResult.SuggestedJobProfiles); } } }
public async Task CalculateAssessment(UserSession userSession, ILogger log) { foreach (var jobCategoryState in userSession.FilteredAssessmentState.JobCategoryStates.Where(j => j.IsComplete(userSession.FilteredAssessmentState.RecordedAnswers))) { var questions = await _questionRepository.GetQuestions(jobCategoryState.QuestionSetVersion); var category = await _jobCategoryRepository.GetJobCategory(jobCategoryState.JobCategoryCode); var jobProfiles = jobCategoryState.Skills.SelectMany((s, i) => { var c = category.Skills.First(cs => cs.ONetAttribute.EqualsIgnoreCase(s.Skill)); return(c.JobProfiles.Select(p => new { QuestionNumber = s.QuestionNumber, Profile = p.JobProfile, Answer = p.Included ? AnswerOption.Yes : AnswerOption.No })); }) .GroupBy(p => p.Profile) .Select(g => new { Profile = g.Key, Answers = g.OrderBy(q => q.QuestionNumber).Select(q => q.Answer) }); var categoryAnswers = userSession.FilteredAssessmentState.GetAnswersForCategory(jobCategoryState.JobCategoryCode); var answers = categoryAnswers .OrderBy(a => a.Index) .Select(a => a.Answer.SelectedOption) .ToArray(); var suggestedProfiles = new List <string>(); foreach (var jobProfile in jobProfiles) { if (jobProfile.Answers.SequenceEqual(answers, EqualityComparer <AnswerOption> .Default)) { suggestedProfiles.Add(jobProfile.Profile); } } var jobCategoryResult = userSession.ResultData.JobCategories.Single(jf => jf.JobCategoryCode.EqualsIgnoreCase(jobCategoryState.JobCategoryCode)); var recordedAnswers = categoryAnswers.Select(a => a.Answer).ToArray(); jobCategoryResult.FilterAssessmentResult = new FilterAssessmentResult { JobFamilyName = jobCategoryState.JobCategoryName, CreatedDt = DateTime.UtcNow, QuestionSetVersion = userSession.CurrentQuestionSetVersion, MaxQuestions = userSession.MaxQuestions, SuggestedJobProfiles = suggestedProfiles, RecordedAnswerCount = recordedAnswers.Length, RecordedAnswers = recordedAnswers, WhatYouToldUs = ComputeWhatYouToldUs(recordedAnswers, questions).Distinct().ToArray() }; } userSession.UpdateJobCategoryQuestionCount(); }
public IActionResult GetJobCategory(int id) { return(Ok(_repository.GetJobCategory(id))); }