private void SetSectionStates(VacancyPreviewViewModel viewModel) { viewModel.TitleSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Title }, true, vm => vm.Title); viewModel.ShortDescriptionSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ShortDescription }, true, vm => vm.ShortDescription); viewModel.ClosingDateSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ClosingDate }, true, vm => vm.ClosingDate); viewModel.WorkingWeekSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.WorkingWeek }, true, vm => vm.HoursPerWeek, vm => vm.WorkingWeekDescription); viewModel.WageTextSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Wage }, true, vm => vm.HasWage, vm => vm.WageText); viewModel.ExpectedDurationSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ExpectedDuration }, true, vm => vm.ExpectedDuration); viewModel.PossibleStartDateSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.PossibleStartDate }, true, vm => vm.PossibleStartDate); viewModel.TrainingLevelSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.TrainingLevel }, true, vm => vm.HasProgramme, vm => vm.TrainingLevel); viewModel.NumberOfPositionsSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.NumberOfPositions }, true, vm => vm.NumberOfPositions); viewModel.DescriptionsSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.VacancyDescription, FieldIdentifiers.TrainingDescription, FieldIdentifiers.OutcomeDescription }, true, vm => vm.VacancyDescription, vm => vm.TrainingDescription, vm => vm.OutcomeDescription); viewModel.SkillsSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Skills }, true, vm => vm.Skills); viewModel.QualificationsSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Qualifications }, true, vm => vm.Qualifications); viewModel.ThingsToConsiderSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ThingsToConsider }, true, vm => vm.ThingsToConsider); viewModel.EmployerNameSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.EmployerName }, true, vm => vm.EmployerName); viewModel.EmployerDescriptionSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.EmployerDescription }, true, vm => vm.EmployerDescription); viewModel.EmployerWebsiteUrlSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.EmployerWebsiteUrl }, true, vm => vm.EmployerWebsiteUrl); viewModel.EmployerAddressSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.EmployerAddress }, true, vm => vm.EmployerAddressElements); viewModel.ApplicationInstructionsSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ApplicationInstructions }, true, vm => vm.ApplicationInstructions); viewModel.ApplicationMethodSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ApplicationMethod }, true, vm => vm.ApplicationMethod); viewModel.ApplicationUrlSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ApplicationUrl }, true, vm => vm.ApplicationUrl); viewModel.ProviderSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Provider }, true, vm => vm.ProviderName); viewModel.ProviderContactSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.ProviderContact }, false, vm => vm.ProviderContactName, vm => vm.ProviderContactEmail, vm => vm.ProviderContactTelephone); viewModel.TrainingSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.Training }, true, vm => vm.TrainingType, vm => vm.TrainingTitle); viewModel.DisabilityConfidentSectionState = GetSectionState(viewModel, new[] { FieldIdentifiers.DisabilityConfident }, true, vm => vm.IsDisabilityConfident); }
public async Task Then_If_There_Are_Skills_Qualifications_And_Other_Things_To_Consider_Added_Section_Set_To_Complete( string title, string programmeId, string description, string shortDescription, string trainingDescription, string outcomeDescription, List <string> skills, string otherThingsToConsider, List <Qualification> qualifications, Vacancies.Client.Domain.Entities.TrainingProvider provider, ApprenticeshipProgramme programme, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneAndSectionTwoVacancy(); vacancy.Skills = skills; vacancy.Qualifications = qualifications; vacancy.ThingsToConsider = otherThingsToConsider; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionThreeState.Should().Be(VacancyTaskListSectionState.Completed); }
public async Task Then_The_Section_State_Is_Set_to_Not_Started( string title, string programmeId, string description, string shortDescription, string trainingDescription, string outcomeDescription, string accountLegalEntityPublicHashedId, Vacancies.Client.Domain.Entities.TrainingProvider provider, ApprenticeshipProgramme programme, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneAndSectionTwoVacancy(); vacancy.NumberOfPositions = null; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.Completed); model.TaskListSectionTwoState.Should().Be(VacancyTaskListSectionState.InProgress); model.TaskListSectionThreeState.Should().Be(VacancyTaskListSectionState.NotStarted); }
public async Task Then_If_Has_Title_Training_Provider_ShortDescription_Then_In_Progress( string title, string programmeId, string shortDescription, Vacancies.Client.Domain.Entities.TrainingProvider provider, ApprenticeshipProgramme programme, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programmeId)).ReturnsAsync(programme); var vacancy = new Vacancy { Id = Guid.NewGuid(), Title = title, ProgrammeId = programmeId, ShortDescription = shortDescription, TrainingProvider = provider }; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.InProgress); }
public async Task Then_If_Has_Title_Training_Provider_ShortDescription_And_Descriptions_Then_Completed( string title, string programmeId, string description, string shortDescription, string trainingDescription, string outcomeDescription, string accountLegalEntityPublicHashedId, Vacancies.Client.Domain.Entities.TrainingProvider provider, ApprenticeshipProgramme programme, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programmeId)).ReturnsAsync(programme); var vacancy = new Vacancy { Id = Guid.NewGuid(), Title = title, ProgrammeId = programmeId, Description = description, TrainingDescription = trainingDescription, ShortDescription = shortDescription, OutcomeDescription = outcomeDescription, TrainingProvider = provider, AccountLegalEntityPublicHashedId = accountLegalEntityPublicHashedId }; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.Completed); }
public async Task Then_The_Vacancy_Is_Retrieved_And_Mapped( string findAnApprenticeshipUrl, VacancyRouteModel routeModel, ApprenticeshipProgramme programme, Vacancy vacancy, List <LegalEntity> legalEntities, [Frozen] Mock <IOptions <ExternalLinksConfiguration> > externalLinksConfiguration, [Frozen] Mock <IUtility> utility, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, [Frozen] Mock <IEmployerVacancyClient> employerVacancyClient, VacancyTaskListOrchestrator orchestrator) { vacancy.EmployerLocation = null; vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; programme.Id = vacancy.ProgrammeId; programme.EducationLevelNumber = 3; programme.ApprenticeshipLevel = ApprenticeshipLevel.Higher; employerVacancyClient.Setup(x => x.GetEmployerLegalEntitiesAsync(routeModel.EmployerAccountId)) .ReturnsAsync(legalEntities); utility.Setup(x => x.GetAuthorisedVacancyForEditAsync(It.Is <VacancyRouteModel>( c => c.VacancyId.Equals(routeModel.VacancyId) && c.EmployerAccountId.Equals(routeModel.EmployerAccountId)), RouteNames.EmployerTaskListGet)) .ReturnsAsync(vacancy); recruitVacancyClient.Setup(x => x.GetActiveApprenticeshipProgrammesAsync()) .ReturnsAsync(new List <ApprenticeshipProgramme> { programme }); recruitVacancyClient.Setup(x => x.GetApprenticeshipProgrammeAsync(programme.Id)) .ReturnsAsync(programme); recruitVacancyClient.Setup(x => x.GetEmployerDescriptionAsync(vacancy)).ReturnsAsync(vacancy.EmployerDescription); recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(vacancy.EmployerName); externalLinksConfiguration.Object.Value.FindAnApprenticeshipUrl = findAnApprenticeshipUrl; var expectedViewModel = new VacancyPreviewViewModel(); var mapper = new DisplayVacancyViewModelMapper(Mock.Of <IGeocodeImageService>(), externalLinksConfiguration.Object, recruitVacancyClient.Object); var viewModel = await orchestrator.GetVacancyTaskListModel(routeModel); await mapper.MapFromVacancyAsync(expectedViewModel, vacancy); viewModel.Should().BeEquivalentTo(expectedViewModel, options => options .Excluding(c => c.SoftValidationErrors) .Excluding(c => c.RejectedReason) .Excluding(c => c.HasProgramme) .Excluding(c => c.HasWage) .Excluding(c => c.CanShowReference) .Excluding(c => c.CanShowDraftHeader) .Excluding(c => c.EducationLevelName) .Excluding(c => c.ApprenticeshipLevel) .Excluding(c => c.AccountLegalEntityCount) .Excluding(c => c.HasSelectedEmployerNameOption) ); viewModel.ApprenticeshipLevel.Should().Be(programme.ApprenticeshipLevel); viewModel.AccountLegalEntityCount.Should().Be(legalEntities.Count); viewModel.HasSelectedEmployerNameOption.Should().BeTrue(); }
public async Task And_Section_One_Completed_And_Important_Dates_Not_Entered_Then_Not_Started(DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneVacancy(); vacancy.Id = Guid.NewGuid(); var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionTwoState.Should().Be(VacancyTaskListSectionState.NotStarted); }
private void AddSoftValidationErrorsToModelState(VacancyPreviewViewModel viewModel) { if (!viewModel.SoftValidationErrors.HasErrors) { return; } foreach (var error in viewModel.SoftValidationErrors.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } }
public async Task Then_Section_State_Is_Set_To_Complete_With_Employer_Name_Description_And_ApplicationMethod_Set( Vacancy vacancy, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { vacancy.EmployerNameOption = EmployerNameOption.RegisteredName; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionFourState.Should().Be(VacancyTaskListSectionState.Completed); }
public async Task Then_The_Section_State_Is_Set( DisplayVacancyViewModelMapper mapper) { var vacancy = new Vacancy() { Id = Guid.NewGuid() }; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.NotStarted); }
private bool IsSectionComplete(VacancyPreviewViewModel vm, bool requiresAll, params Expression <Func <VacancyPreviewViewModel, object> >[] sectionProperties) { foreach (var requiredPropertyExpression in sectionProperties) { var requiredPropertyFunc = requiredPropertyExpression.Compile(); var propertyValue = requiredPropertyFunc(vm); var result = true; switch (propertyValue) { case null: result = false; break; case string stringProperty: if (string.IsNullOrWhiteSpace(stringProperty)) { result = false; } break; case IEnumerable listProperty: if (listProperty.Cast <object>().Any() == false) { result = false; } break; case bool _: //No way to tell if a bool has been 'completed' so just skip break; default: //Skipping other types for now break; } if (requiresAll && result == false) { return(false); } if (!requiresAll && result) { return(true); } } return(requiresAll); }
public async Task Then_Section_State_Is_Set_To_In_Progress_If_Employer_Name_And_Description_Set( Vacancy vacancy, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { vacancy.ApplicationMethod = null; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionFourState.Should().Be(VacancyTaskListSectionState.InProgress); }
public async Task Then_If_Section_Started_Then_Set_To_In_Progress( string title, DisplayVacancyViewModelMapper mapper) { var vacancy = new Vacancy() { Id = Guid.NewGuid(), Title = title }; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.InProgress); }
public async Task And_Has_Important_Dates_Then_In_Progress( DateTime closingDate, DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneVacancy(); vacancy.Id = Guid.NewGuid(); vacancy.ClosingDate = closingDate; vacancy.StartDate = closingDate.AddMonths(1); var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionTwoState.Should().Be(VacancyTaskListSectionState.InProgress); }
private VacancyPreviewSectionState GetSectionState(VacancyPreviewViewModel vm, IEnumerable <string> reviewFieldIndicators, bool requiresAll, params Expression <Func <VacancyPreviewViewModel, object> >[] sectionProperties) { if (IsSectionModelStateValid(sectionProperties) == false) { return(IsSectionComplete(vm, requiresAll, sectionProperties) ? VacancyPreviewSectionState.Invalid : VacancyPreviewSectionState.InvalidIncomplete); } if (IsSectionForReview(vm, reviewFieldIndicators)) { return(VacancyPreviewSectionState.Review); } return(IsSectionComplete(vm, requiresAll, sectionProperties) ? VacancyPreviewSectionState.Valid : VacancyPreviewSectionState.Incomplete); }
public async Task Then_The_Section_State_Is_Set_To_Not_Started_If_Section_Three_Is_Complete_But_No_Name_On_Advert( Vacancy vacancy, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { recruitVacancyClient.Setup(x => x.GetEmployerNameAsync(vacancy)).ReturnsAsync(string.Empty); vacancy.EmployerDescription = null; vacancy.ApplicationMethod = null; vacancy.EmployerNameOption = null; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionFourState.Should().Be(VacancyTaskListSectionState.NotStarted); }
public async Task And_Has_All_Values_Then_Completed( Wage wage, DateTime closingDate, int numberOfPositions, Address employerLocation, DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneVacancy(); vacancy.Id = Guid.NewGuid(); vacancy.Wage = wage; vacancy.ClosingDate = closingDate; vacancy.StartDate = closingDate.AddMonths(1); vacancy.NumberOfPositions = numberOfPositions; vacancy.EmployerLocation = employerLocation; var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionTwoState.Should().Be(VacancyTaskListSectionState.Completed); }
public async Task Then_If_There_Section_Two_Is_Completed_Then_Section_Three_Set_To_NotStarted( string title, string programmeId, string description, string shortDescription, string trainingDescription, string outcomeDescription, List <string> skills, Vacancies.Client.Domain.Entities.TrainingProvider provider, ApprenticeshipProgramme programme, [Frozen] Mock <IRecruitVacancyClient> recruitVacancyClient, DisplayVacancyViewModelMapper mapper) { var vacancy = CreateCompletedSectionOneAndSectionTwoVacancy(); var model = new VacancyPreviewViewModel(); await mapper.MapFromVacancyAsync(model, vacancy); model.SetSectionStates(model, new ModelStateDictionary()); model.TaskListSectionOneState.Should().Be(VacancyTaskListSectionState.Completed); model.TaskListSectionTwoState.Should().Be(VacancyTaskListSectionState.Completed); model.TaskListSectionThreeState.Should().Be(VacancyTaskListSectionState.NotStarted); }
private bool IsSectionForReview(VacancyPreviewViewModel vm, IEnumerable <string> reviewFieldIndicators) { return(reviewFieldIndicators != null && reviewFieldIndicators.Any(reviewFieldIndicator => vm.Review.FieldIndicators.Select(r => r.ReviewFieldIdentifier) .Contains(reviewFieldIndicator))); }