public void ShouldIncludeLocationTypeAndNumberOfPositionsInTheViewModelReturnedWhenThereIsAValidationError() { var numberOfPositions = 5; var viewModel = new VacancyOwnerRelationshipViewModel { IsEmployerLocationMainApprenticeshipLocation = true, NumberOfPositions = numberOfPositions, ProviderSiteId = 42, Employer = new EmployerViewModel { EmployerId = 7, } }; ProviderProvider.Setup(p => p.GetVacancyOwnerRelationshipViewModel(It.IsAny <int>(), It.IsAny <string>())) .Returns(new VacancyOwnerRelationshipViewModel { Employer = new EmployerViewModel { Address = new AddressViewModel() } }); var mediator = GetMediator(); var result = mediator.ConfirmEmployer(viewModel, Ukprn); result.ViewModel.IsEmployerLocationMainApprenticeshipLocation.Should() .Be(true); result.ViewModel.NumberOfPositions.Should().Be(numberOfPositions); }
public ActionResult EmployerInformation(VacancyOwnerRelationshipViewModel viewModel) { var response = _vacancyMediator.UpdateEmployerInformation(viewModel); switch (response.Code) { case VacancyMediatorCodes.UpdateEmployerInformation.FailedValidation: ModelState.Clear(); response.ValidationResult.AddToModelState(ModelState, string.Empty); return(View(response.ViewModel)); case VacancyMediatorCodes.UpdateEmployerInformation.Ok: if (response.ViewModel.IsEmployerLocationMainApprenticeshipLocation.HasValue && response.ViewModel.IsEmployerLocationMainApprenticeshipLocation.Value) { return(RedirectToRoute(ManagementRouteNames.ReviewVacancy, new { vacancyReferenceNumber = response.ViewModel.VacancyReferenceNumber })); } return(RedirectToRoute(ManagementRouteNames.AddLocations, new { vacancyReferenceNumber = viewModel.VacancyReferenceNumber })); default: throw new InvalidMediatorCodeException(response.Code); } }
public void EmptyVacancyIfPreviousStateEmployerLocationIsDifferentFromCurrentStateEmployerLocation() { var numberOfPositions = 5; const string initialVacancyTitle = "title"; var viewModel = new VacancyOwnerRelationshipViewModel { IsEmployerLocationMainApprenticeshipLocation = false, NumberOfPositions = numberOfPositions, ProviderSiteId = 42, Employer = new EmployerViewModel { EmployerId = 7 }, EmployerDescription = "Text about Employer Description", VacancyReferenceNumber = AnInt }; MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(AnInt)) .Returns(GetLiveVacancyWithComments(AnInt, initialVacancyTitle)); var provider = GetVacancyPostingProvider(); provider.EmptyVacancyLocation(viewModel.VacancyReferenceNumber); MockVacancyPostingService.Verify( s => s.UpdateVacancy(It.Is <Vacancy>(v => v.Address == null && v.NumberOfPositions == null && v.NumberOfPositionsComment == null))); }
private Vacancy GetVacancy(VacancyOwnerRelationshipViewModel viewModel) { var vacancy = _vacancyPostingService.GetVacancy(viewModel.VacancyGuid) ?? _vacancyPostingService.GetVacancyByReferenceNumber(viewModel.VacancyReferenceNumber); return(vacancy); }
public void ShouldValidateDescription_ForAnonymousEmployer( string description, bool expectValid) { // Arrange. var viewModel = new VacancyOwnerRelationshipViewModel { AnonymousEmployerDescription = description, IsAnonymousEmployer = true, AnonymousEmployerReason = description, AnonymousAboutTheEmployer = description }; // Act. var validator = new VacancyOwnerRelationshipViewModelValidator(); // Assert. if (expectValid) { validator.ShouldNotHaveValidationErrorFor(m => m.AnonymousEmployerDescription, viewModel); validator.ShouldNotHaveValidationErrorFor(m => m.AnonymousAboutTheEmployer, viewModel); validator.ShouldNotHaveValidationErrorFor(m => m.AnonymousEmployerReason, viewModel); } else { validator.ShouldHaveValidationErrorFor(m => m.AnonymousEmployerDescription, viewModel); validator.ShouldHaveValidationErrorFor(m => m.AnonymousAboutTheEmployer, viewModel); validator.ShouldHaveValidationErrorFor(m => m.AnonymousEmployerReason, viewModel); } }
public void ShouldValidateDescription( string description, bool expectValid) { // Arrange. var viewModel = new VacancyOwnerRelationshipViewModel { EmployerWebsiteUrl = "http://www.valid.com", EmployerDescription = description, IsAnonymousEmployer = false }; // Act. var validator = new VacancyOwnerRelationshipViewModelValidator(); // Assert. if (expectValid) { validator.ShouldNotHaveValidationErrorFor(m => m.EmployerDescription, viewModel); } else { validator.ShouldHaveValidationErrorFor(m => m.EmployerDescription, viewModel); } }
public void ShouldValidateWebSiteUrl( string websiteUrl, bool expectValid) { // Arrange. var viewModel = new VacancyOwnerRelationshipViewModel { EmployerWebsiteUrl = websiteUrl, EmployerDescription = "populated" }; string uriString = null; // Act. var validator = new VacancyOwnerRelationshipViewModelValidator(); Action uriAction = () => { uriString = new UriBuilder(viewModel.EmployerWebsiteUrl).Uri.ToString(); }; // Assert. if (expectValid) { validator.ShouldNotHaveValidationErrorFor(m => m.EmployerWebsiteUrl, viewModel); if (!string.IsNullOrEmpty(websiteUrl)) { uriAction.ShouldNotThrow(); uriString.Should().NotBeNullOrEmpty(); } } else { validator.ShouldHaveValidationErrorFor(m => m.EmployerWebsiteUrl, viewModel); } }
public VacancyOwnerRelationshipViewModel ConfirmVacancyOwnerRelationship(VacancyOwnerRelationshipViewModel viewModel) { if (_providerService.IsADeletedVacancyOwnerRelationship(viewModel.ProviderSiteId, viewModel.Employer.EdsUrn)) { _providerService.ResurrectVacancyOwnerRelationship(viewModel.ProviderSiteId, viewModel.Employer.EdsUrn); } var vacancyOwnerRelationship = _providerService.GetVacancyOwnerRelationship(viewModel.ProviderSiteId, viewModel.Employer.EdsUrn); vacancyOwnerRelationship.EmployerWebsiteUrl = viewModel.EmployerWebsiteUrl; vacancyOwnerRelationship.EmployerDescription = viewModel.EmployerDescription; vacancyOwnerRelationship = _providerService.SaveVacancyOwnerRelationship(vacancyOwnerRelationship); var vacancy = GetVacancy(viewModel); if (vacancy != null) { vacancy.VacancyOwnerRelationshipId = vacancyOwnerRelationship.VacancyOwnerRelationshipId; vacancy.EmployerWebsiteUrl = vacancyOwnerRelationship.EmployerWebsiteUrl; vacancy.EmployerDescription = vacancyOwnerRelationship.EmployerDescription; if (viewModel.IsEmployerLocationMainApprenticeshipLocation != null) { vacancy.IsEmployerLocationMainApprenticeshipLocation = viewModel.IsEmployerLocationMainApprenticeshipLocation.Value; } if (viewModel.NumberOfPositions != null) { vacancy.NumberOfPositions = viewModel.NumberOfPositions.Value; } if (viewModel.IsAnonymousEmployer != null && viewModel.IsAnonymousEmployer.Value) { vacancy.EmployerAnonymousName = viewModel.AnonymousEmployerDescription; vacancy.EmployerAnonymousReason = viewModel.AnonymousEmployerReason; vacancy.AnonymousAboutTheEmployer = viewModel.AnonymousAboutTheEmployer; } else { vacancy.EmployerAnonymousName = null; vacancy.EmployerAnonymousReason = null; vacancy.AnonymousAboutTheEmployer = null; } _vacancyPostingService.UpdateVacancy(vacancy); } var employer = _employerService.GetEmployer(vacancyOwnerRelationship.EmployerId, true); var result = vacancyOwnerRelationship.Convert(employer); return(result); }
public void ShouldCreateTheVacancyIfItDoesnExist() { // Arrange const string ukprn = "1234"; var vacancyGuid = Guid.NewGuid(); const int vacanyPartyId = 1; const bool isEmployerLocationMainApprenticeshipLocation = true; int? numberOfPositions = 2; const string employerWebsiteUrl = "www.google.com"; const string employerDescription = "description"; var viewModel = new VacancyOwnerRelationshipViewModel { IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, NumberOfPositions = numberOfPositions, ProviderSiteId = 42, Employer = new EmployerViewModel { EmployerId = 7 }, EmployerDescription = employerDescription, EmployerWebsiteUrl = employerWebsiteUrl, VacancyOwnerRelationshipId = vacanyPartyId, VacancyGuid = vacancyGuid, IsAnonymousEmployer = false }; ProviderProvider.Setup(p => p.ConfirmVacancyOwnerRelationship(viewModel)).Returns(viewModel); // Act. var mediator = GetMediator(); mediator.ConfirmEmployer(viewModel, ukprn); // Assert. VacancyPostingProvider.Verify(p => p.CreateVacancy(new VacancyMinimumData { Ukprn = ukprn, VacancyGuid = vacancyGuid, VacancyOwnerRelationshipId = vacanyPartyId, IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, NumberOfPositions = numberOfPositions, EmployerWebsiteUrl = employerWebsiteUrl, EmployerDescription = employerDescription })); }
public void ShouldReturnErrorIfFailsGeocodingTheVacancy() { // Arrange const string ukprn = "1234"; var vacancyGuid = Guid.NewGuid(); const int vacanyPartyId = 1; const bool isEmployerLocationMainApprenticeshipLocation = true; int? numberOfPositions = 2; const string employerWebsiteUrl = "www.google.com"; const string employerDescription = "description"; var viewModel = new VacancyOwnerRelationshipViewModel { IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, NumberOfPositions = numberOfPositions, ProviderSiteId = 42, Employer = new EmployerViewModel { EmployerId = 7 }, EmployerDescription = employerDescription, EmployerWebsiteUrl = employerWebsiteUrl, VacancyOwnerRelationshipId = vacanyPartyId, VacancyGuid = vacancyGuid, IsAnonymousEmployer = false }; ProviderProvider.Setup(p => p.ConfirmVacancyOwnerRelationship(viewModel)).Returns(viewModel); VacancyPostingProvider .Setup(p => p.CreateVacancy(It.IsAny <VacancyMinimumData>())) .Throws(new CustomException(ErrorCodes.GeoCodeLookupProviderFailed)); // Act. var mediator = GetMediator(); var result = mediator.ConfirmEmployer(viewModel, ukprn); // Assert. result.AssertMessage(VacancyPostingMediatorCodes.ConfirmEmployer.FailedGeoCodeLookup, ApplicationPageMessages.PostcodeLookupFailed, UserMessageLevel.Error); }
public static VacancyOwnerRelationshipViewModel Convert( this VacancyOwnerRelationship vacancyOwnerRelationship, Employer employer, Vacancy vacancy = null) { var viewModel = new VacancyOwnerRelationshipViewModel { VacancyOwnerRelationshipId = vacancyOwnerRelationship.VacancyOwnerRelationshipId, ProviderSiteId = vacancyOwnerRelationship.ProviderSiteId, EmployerDescription = vacancyOwnerRelationship.EmployerDescription, EmployerWebsiteUrl = vacancyOwnerRelationship.EmployerWebsiteUrl, Employer = employer.Convert(), IsEmployerAddressValid = true }; if (!string.IsNullOrWhiteSpace(vacancy?.EmployerAnonymousName)) { viewModel.IsAnonymousEmployer = true; viewModel.Employer.FullName = vacancy.EmployerAnonymousName; viewModel.OriginalFullName = employer.FullName; viewModel.AnonymousEmployerReason = vacancy.EmployerAnonymousReason ?? string.Empty; viewModel.AnonymousEmployerDescription = vacancy.EmployerAnonymousName; viewModel.AnonymousAboutTheEmployer = vacancy.AnonymousAboutTheEmployer; } return(viewModel); }
public MediatorResponse <VacancyOwnerRelationshipViewModel> UpdateEmployerInformation(VacancyOwnerRelationshipViewModel viewModel) { var validationResult = _vacancyOwnerRelationshipViewModelValidator.Validate(viewModel); var existingVacancy = _vacancyQaProvider.GetNewVacancyViewModel(viewModel.VacancyReferenceNumber); var existingViewModel = existingVacancy.VacancyOwnerRelationship; existingViewModel.EmployerWebsiteUrl = viewModel.EmployerWebsiteUrl; existingViewModel.EmployerDescription = viewModel.EmployerDescription; existingViewModel.IsEmployerLocationMainApprenticeshipLocation = viewModel.IsEmployerLocationMainApprenticeshipLocation; existingViewModel.NumberOfPositions = viewModel.NumberOfPositions; existingViewModel.VacancyGuid = viewModel.VacancyGuid; existingViewModel.NumberOfPositionsComment = viewModel.NumberOfPositionsComment; existingViewModel.EmployerDescriptionComment = viewModel.EmployerDescriptionComment; existingViewModel.EmployerWebsiteUrlComment = viewModel.EmployerWebsiteUrlComment; existingViewModel.IsAnonymousEmployer = viewModel.IsAnonymousEmployer; existingViewModel.AnonymousEmployerReason = viewModel.AnonymousEmployerReason; existingViewModel.AnonymousEmployerDescription = viewModel.AnonymousEmployerDescription; existingViewModel.AnonymousAboutTheEmployer = viewModel.AnonymousAboutTheEmployer; existingViewModel.AnonymousEmployerReasonComment = viewModel.AnonymousEmployerReasonComment; existingViewModel.AnonymousEmployerDescriptionComment = viewModel.AnonymousEmployerDescriptionComment; existingViewModel.AnonymousAboutTheEmployerComment = viewModel.AnonymousAboutTheEmployerComment; if (!validationResult.IsValid) { return(GetMediatorResponse(VacancyMediatorCodes.UpdateEmployerInformation.FailedValidation, existingViewModel, validationResult)); } _providerQaProvider.ConfirmVacancyOwnerRelationship(viewModel); existingVacancy.IsEmployerLocationMainApprenticeshipLocation = viewModel.IsEmployerLocationMainApprenticeshipLocation; existingVacancy.NumberOfPositions = viewModel.NumberOfPositions; existingVacancy.VacancyGuid = viewModel.VacancyGuid; existingVacancy.NumberOfPositionsComment = viewModel.NumberOfPositionsComment; existingVacancy.EmployerDescriptionComment = viewModel.EmployerDescriptionComment; existingVacancy.EmployerWebsiteUrlComment = viewModel.EmployerWebsiteUrlComment; existingVacancy.IsAnonymousEmployer = viewModel.IsAnonymousEmployer; existingVacancy.AnonymousEmployerReason = viewModel.AnonymousEmployerReason; existingVacancy.AnonymousEmployerDescription = viewModel.AnonymousEmployerDescription; existingVacancy.AnonymousAboutTheEmployer = viewModel.AnonymousAboutTheEmployer; existingVacancy.AnonymousEmployerReasonComment = viewModel.AnonymousEmployerReasonComment; existingVacancy.AnonymousEmployerDescriptionComment = viewModel.AnonymousEmployerDescriptionComment; existingVacancy.AnonymousAboutTheEmployerComment = viewModel.AnonymousAboutTheEmployerComment; _vacancyQaProvider.UpdateEmployerInformationWithComments(existingVacancy); if (viewModel.IsEmployerLocationMainApprenticeshipLocation.HasValue && viewModel.IsEmployerLocationMainApprenticeshipLocation.Value) { _vacancyQaProvider.RemoveLocationAddresses(viewModel.VacancyGuid); } return(GetMediatorResponse(VacancyMediatorCodes.UpdateEmployerInformation.Ok, viewModel)); }