public void ShouldReturnOkIfThereIsntAnyValidationError() { var vacancyReferenceNumber = 1; var closingDate = DateTime.Now; var apprenticeshipVacancy = new Vacancy { VacancyReferenceNumber = vacancyReferenceNumber, Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null) }; var viewModel = new FurtherVacancyDetailsViewModel { Wage = new WageViewModel(), VacancyReferenceNumber = vacancyReferenceNumber, VacancyDatesViewModel = new VacancyDatesViewModel { ClosingDate = new DateViewModel(closingDate) }, }; MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber)) .Returns(apprenticeshipVacancy); MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())) .Returns(apprenticeshipVacancy); MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(apprenticeshipVacancy)) .Returns(viewModel); var provider = GetVacancyPostingProvider(); provider.CloseVacancy(viewModel); MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.Status == VacancyStatus.Closed))); }
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))); }
public void ShouldCreateApprenticeshipLevelIfTrainingTypeStandard(int standardId, ApprenticeshipLevel expectedApprenticeshipLevel) { // Arrange. var trainingDetailsViewModel = new TrainingDetailsViewModel { VacancyReferenceNumber = VacancyReferenceNumber, ApprenticeshipLevel = expectedApprenticeshipLevel, TrainingType = TrainingType.Standards, StandardId = standardId }; MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v); MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())) .Returns((Vacancy av) => new TrainingDetailsViewModel() { ApprenticeshipLevel = av.ApprenticeshipLevel }); var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.UpdateVacancy(trainingDetailsViewModel); // Assert. viewModel.ApprenticeshipLevel.Should().Be(expectedApprenticeshipLevel); }
public void RemoveLocationAddressesShouldCallRemoveLocationAddresses() { //Arrange int vacancyReferenceNumber = 1; var vacancyGuid = Guid.NewGuid(); const bool isEmployerLocationMainApprenticeshipLocation = false; var vacancyWithLocationAddresses = GetVacancyWithLocationAddresses(vacancyGuid, vacancyReferenceNumber, 1, isEmployerLocationMainApprenticeshipLocation, null, null, string.Empty); MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(vacancyWithLocationAddresses.Vacancy); var provider = GetVacancyPostingProvider(); //Act provider.RemoveLocationAddresses(vacancyGuid); //Assert MockVacancyPostingService.Verify( s => s.UpdateVacancy(It.Is <Vacancy>( v => v.IsEmployerLocationMainApprenticeshipLocation == vacancyWithLocationAddresses.Vacancy.IsEmployerLocationMainApprenticeshipLocation && v.NumberOfPositions == vacancyWithLocationAddresses.Vacancy.NumberOfPositions && v.AdditionalLocationInformation == null && v.AdditionalLocationInformationComment == vacancyWithLocationAddresses.Vacancy.AdditionalLocationInformationComment))); MockVacancyPostingService.Verify( s => s.DeleteVacancyLocationsFor(It.IsAny <int>())); }
public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithMultipleAddresses() { // Arrange. var geopoint = new Fixture().Create <GeoPoint>(); var geopoint2 = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); var postalAddress2 = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint2).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel> { new VacancyLocationAddressViewModel { Address = addressViewModel }, new VacancyLocationAddressViewModel { Address = addressViewModel } } }; var vacancyLocations = new List <VacancyLocation> { new VacancyLocation { Address = postalAddress }, new VacancyLocation { Address = postalAddress2 } }; MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[0])).Returns(vacancyLocations[0]); MockMapper.Setup(m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(locationSearchViewModel.Addresses[1])).Returns(vacancyLocations[1]); MockVacancyPostingService.Setup(v => v.CreateVacancy(It.IsAny <Vacancy>())) .Returns(new Vacancy()); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Exactly(2)); MockVacancyPostingService.Verify(m => m.DeleteVacancyLocationsFor(vacancy.VacancyId)); MockVacancyPostingService.Verify(m => m.CreateVacancyLocations(It.IsAny <List <VacancyLocation> >()), Times.Once); }
public void ShouldUpdateWage() { //Arrange. const int vacancyReferenceNumber = 1; var closingDate = DateTime.Today.AddDays(20); var possibleStartDate = DateTime.Today.AddDays(30); var wageViewModel = new WageViewModel() { Type = WageType.Custom, CustomType = CustomWageType.Fixed, Amount = 450, AmountLowerBound = null, AmountUpperBound = null, Text = null, Unit = WageUnit.Monthly, HoursPerWeek = 37.5m }; var wage = new Wage(WageType.Custom, 450, null, null, null, WageUnit.Monthly, 37.5m, null); var updatedViewModel = new FurtherVacancyDetailsViewModel { VacancyDatesViewModel = new VacancyDatesViewModel { ClosingDate = new DateViewModel(closingDate), PossibleStartDate = new DateViewModel(possibleStartDate) }, VacancyReferenceNumber = vacancyReferenceNumber, Wage = wageViewModel }; var dbApprenticeshipVacancy = new Vacancy { VacancyReferenceNumber = vacancyReferenceNumber, Wage = new Wage(WageType.NationalMinimum, null, null, null, "Legacy text", WageUnit.Weekly, 30, null) }; MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber)) .Returns(dbApprenticeshipVacancy); MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())) .Returns(dbApprenticeshipVacancy); MockMapper.Setup(m => m.Map <WageViewModel, Wage>(It.IsAny <WageViewModel>())).Returns(wage); MockMapper.Setup(m => m.Map <Wage, WageViewModel>(It.IsAny <Wage>())).Returns(wageViewModel); //this line kind of invalidates this test. MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(dbApprenticeshipVacancy)) .Returns(updatedViewModel); var provider = GetVacancyPostingProvider(); //Act. provider.UpdateVacancyDates(updatedViewModel); //Assert. MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>( v => v.PossibleStartDate == possibleStartDate && v.Wage.Type == updatedViewModel.Wage.Type && v.Wage.Amount == updatedViewModel.Wage.Amount && v.Wage.Text == dbApprenticeshipVacancy.Wage.Text && v.Wage.Unit == updatedViewModel.Wage.Unit && v.Wage.HoursPerWeek == dbApprenticeshipVacancy.Wage.HoursPerWeek))); }
public void ShouldFillApprenticeshipLevelIfTrainingTypeIsStandardAndApprenticeshipLevelIsUnknown() { // Arrange. var trainingDetailsViewModel = new TrainingDetailsViewModel { VacancyReferenceNumber = VacancyReferenceNumber, ApprenticeshipLevel = ApprenticeshipLevel.Unknown, TrainingType = TrainingType.Standards, StandardId = 1 }; MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v); MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())) .Returns((Vacancy av) => new TrainingDetailsViewModel() { FrameworkCodeName = av.FrameworkCodeName, ApprenticeshipLevel = av.ApprenticeshipLevel }); var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.UpdateVacancy(trainingDetailsViewModel); // Assert. viewModel.ApprenticeshipLevel.Should().NotBe(ApprenticeshipLevel.Unknown); }
public void ShouldCreateNullFrameworkCodeIfTrainingTypeStandard() { // Arrange. var trainingDetailsViewModel = new TrainingDetailsViewModel { VacancyReferenceNumber = VacancyReferenceNumber, ApprenticeshipLevel = ApprenticeshipLevel.Unknown, TrainingType = TrainingType.Standards, StandardId = 1, FrameworkCodeName = "ShouldBeNulled" }; MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())).Returns <Vacancy>(v => v); MockMapper.Setup(m => m.Map <Vacancy, TrainingDetailsViewModel>(It.IsAny <Vacancy>())) .Returns((Vacancy av) => new TrainingDetailsViewModel() { FrameworkCodeName = av.FrameworkCodeName }); var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.UpdateVacancy(trainingDetailsViewModel); // Assert. viewModel.FrameworkCodeName.Should().BeNullOrEmpty(); }
public void ShouldIncrementSubmissionCountWhenSumbittingTheVacancy() { var vacancyPostingProvider = GetVacancyPostingProvider(); const int referenceNumber = 1; var apprenticeshipVacancy = new Vacancy { VacancyOwnerRelationshipId = 42, IsEmployerLocationMainApprenticeshipLocation = true, SubmissionCount = 2 }; MockVacancyPostingService.Setup(ps => ps.GetVacancyByReferenceNumber(It.IsAny <int>())).Returns(apprenticeshipVacancy); MockVacancyPostingService.Setup(ps => ps.UpdateVacancy(It.IsAny <Vacancy>())) .Returns(apprenticeshipVacancy); MockProviderService.Setup(ps => ps.GetProviderSite(It.IsAny <string>())) .Returns(new ProviderSite { Address = new PostalAddress() }); MockReferenceDataService.Setup(ds => ds.GetSubCategoryByCode(It.IsAny <string>())).Returns(Category.EmptyFramework); vacancyPostingProvider.SubmitVacancy(referenceNumber); MockVacancyPostingService.Verify( ps => ps.UpdateVacancy( It.Is <Vacancy>(v => v.SubmissionCount == 3))); }
public void ShouldAssignLocalAuthorityCodeOnUpdatingVacancyLocationsWithSingleAddressDifferentToEmployer() { // Arrange. const string localAuthorityCode = "ABCD"; var geopoint = new Fixture().Create <GeoPoint>(); var addressViewModel = new Fixture().Build <AddressViewModel>().Create(); var postalAddress = new Fixture().Build <PostalAddress>().With(a => a.GeoPoint, geopoint).Create(); MockGeocodeService.Setup(gs => gs.GetGeoPointFor(It.IsAny <PostalAddress>())).Returns(geopoint); var locationSearchViewModel = new LocationSearchViewModel { EmployerId = EmployerId, ProviderSiteId = ProviderSiteId, EmployerEdsUrn = EdsUrn, Addresses = new List <VacancyLocationAddressViewModel>() { new VacancyLocationAddressViewModel() { Address = addressViewModel } } }; MockMapper.Setup( m => m.Map <VacancyLocationAddressViewModel, VacancyLocation>(It.IsAny <VacancyLocationAddressViewModel>())) .Returns(new VacancyLocation { Address = postalAddress }); MockMapper.Setup(m => m.Map <AddressViewModel, PostalAddress>(addressViewModel)).Returns(postalAddress); var geoPointViewModel = new Fixture().Create <GeoPointViewModel>(); MockMapper.Setup(m => m.Map <GeoPoint, GeoPointViewModel>(geopoint)) .Returns(geoPointViewModel); MockMapper.Setup(m => m.Map <GeoPointViewModel, GeoPoint>(geoPointViewModel)).Returns(geopoint); MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(It.IsAny <string>())) .Returns(localAuthorityCode); var vacancy = new Fixture().Create <Vacancy>(); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(vacancy); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); var provider = GetVacancyPostingProvider(); // Act. provider.AddLocations(locationSearchViewModel); // Assert. MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(It.IsAny <string>()), Times.Once); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.Is <Vacancy>(av => av.LocalAuthorityCode == localAuthorityCode))); MockVacancyPostingService.Verify(m => m.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); }
public void SetUp() { _validNewVacancyViewModelWithReferenceNumber = new NewVacancyViewModel() { VacancyReferenceNumber = 1, OfflineVacancy = false, VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() }; MockVacancyPostingService.Setup(mock => mock.GetVacancyByReferenceNumber(_validNewVacancyViewModelWithReferenceNumber.VacancyReferenceNumber.Value)) .Returns(_existingVacancy); MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockReferenceDataService.Setup(mock => mock.GetSectors()) .Returns(new List <Sector> { new Sector { Id = 1, Standards = new List <Standard> { new Standard { Id = 1, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Intermediate }, new Standard { Id = 2, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Advanced }, new Standard { Id = 3, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Higher }, new Standard { Id = 4, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.FoundationDegree }, new Standard { Id = 5, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Degree }, new Standard { Id = 6, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Masters } } } }); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)) .Returns(new Provider()); MockEmployerService.Setup(s => s.GetEmployer(EmployerId, It.IsAny <bool>())).Returns(new Fixture().Build <Employer>().Create()); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())) .Returns(new NewVacancyViewModel()); }
public void CreateVacancyShouldGeoCodeTheEmpoyersAddressIfTheGeoPointIsInvalid() { const int vacancyOwnerRelationshipId = 1; const int employerId = 2; const string ukprn = "1234"; const string employersPostcode = "cv1 9SX"; var vacancyGuid = Guid.NewGuid(); const int vacancyReferenceNumber = 123456; const bool isEmployerLocationMainApprenticeshipLocation = true; int? numberOfPositions = 2; var address = new Fixture().Build <PostalAddress>() .With(a => a.Postcode, employersPostcode) .With(a => a.GeoPoint, null) .Create(); const int providerId = 4; const string localAuthorityCode = "lac"; // Arrange. MockVacancyPostingService.Setup(s => s.GetNextVacancyReferenceNumber()).Returns(vacancyReferenceNumber); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(vacancyOwnerRelationshipId, true)) .Returns( new Fixture().Build <VacancyOwnerRelationship>() .With(v => v.VacancyOwnerRelationshipId, vacancyOwnerRelationshipId) .With(v => v.EmployerId, employerId) .Create()); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns( new Fixture().Build <Employer>() .With(e => e.EmployerId, employerId) .With(e => e.Address, address) .Create()); MockProviderService.Setup(s => s.GetProvider(ukprn, true)) .Returns(new Fixture().Build <Provider>().With(p => p.ProviderId, providerId).Create()); MockLocalAuthorityService.Setup(s => s.GetLocalAuthorityCode(employersPostcode)).Returns(localAuthorityCode); // Act. var provider = GetVacancyPostingProvider(); provider.CreateVacancy(new VacancyMinimumData { IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, VacancyGuid = vacancyGuid, VacancyOwnerRelationshipId = vacancyOwnerRelationshipId, Ukprn = ukprn, NumberOfPositions = numberOfPositions }); // Assert. MockGeoCodingService.Verify(s => s.GetGeoPointFor(address)); }
public void ShouldUpdateVacancyProviderSiteEmployerLinkIfTheVacancyAlreadyExists() { // Arrange var vacancyGuid = Guid.NewGuid(); var apprenticeshipVacancy = new Vacancy(); var vacancyOwnerRelationshipId = 42; var providerSiteId = 1; var employerId = 2; var edsErn = "232"; var vacancyOwnerRelationship = new VacancyOwnerRelationship { VacancyOwnerRelationshipId = vacancyOwnerRelationshipId, ProviderSiteId = providerSiteId, EmployerId = employerId, EmployerDescription = "Description", EmployerWebsiteUrl = "Url" }; MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(apprenticeshipVacancy); MockProviderService.Setup(s => s.SaveVacancyOwnerRelationship(vacancyOwnerRelationship)) .Returns(vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(providerSiteId, edsErn)) .Returns(vacancyOwnerRelationship); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns(new Fixture().Build <Employer>().With(e => e.EmployerId, employerId).Create()); var provider = GetProviderProvider(); // Act provider.ConfirmVacancyOwnerRelationship(new VacancyOwnerRelationshipViewModel { ProviderSiteId = providerSiteId, Employer = new EmployerViewModel { EmployerId = employerId, EdsUrn = edsErn, Address = new AddressViewModel() }, VacancyGuid = vacancyGuid, IsEmployerLocationMainApprenticeshipLocation = true, NumberOfPositions = 4 }); // Assert MockVacancyPostingService.Verify(s => s.GetVacancy(vacancyGuid), Times.Once); MockProviderService.Verify(s => s.SaveVacancyOwnerRelationship(vacancyOwnerRelationship), Times.Once); MockVacancyPostingService.Verify( s => s.UpdateVacancy( It.Is <Vacancy>(v => v.VacancyOwnerRelationshipId == vacancyOwnerRelationshipId)), Times.Once); }
public void SetUp() { _validVacancyMinimumDataSansReferenceNumber = new VacancyMinimumData { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId }; _validNewVacancyViewModelSansReferenceNumber = new NewVacancyViewModel { VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId, ProviderSiteId = ProviderSiteId, Employer = new EmployerViewModel { EmployerId = EmployerId, EdsUrn = EdsUrn, Address = new AddressViewModel() } }, OfflineVacancy = false, }; _validNewVacancyViewModelWithReferenceNumber = new NewVacancyViewModel { VacancyOwnerRelationship = new VacancyOwnerRelationshipViewModel() { VacancyOwnerRelationshipId = VacancyOwnerRelationshipId, ProviderSiteId = ProviderSiteId, Employer = new EmployerViewModel { EmployerId = EmployerId, EdsUrn = EdsUrn, Address = new AddressViewModel() } }, OfflineVacancy = false, VacancyReferenceNumber = 1, VacancyGuid = Guid.NewGuid() }; MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true)) .Returns(_vacancyOwnerRelationship); MockEmployerService.Setup(s => s.GetEmployer(EmployerId, true)).Returns(new Fixture().Build <Employer>().Create()); }
public void ShouldSetVacancyApplicationStateAfterUpdate(int applicationCount, VacancyApplicationsState expectedState) { // Arrange. const int vacancyId = 1; const int vacancyReferenceNumber = 2; var closingDate = DateTime.Today.AddDays(20); var possibleStartDate = DateTime.Today.AddDays(30); var viewModel = new FurtherVacancyDetailsViewModel { Wage = new WageViewModel(), VacancyDatesViewModel = new VacancyDatesViewModel { ClosingDate = new DateViewModel(closingDate), PossibleStartDate = new DateViewModel(possibleStartDate) }, VacancyReferenceNumber = vacancyReferenceNumber }; var vacancy = new Vacancy { VacancyId = vacancyId, VacancyReferenceNumber = vacancyReferenceNumber, Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null) }; MockVacancyPostingService.Setup(mock => mock .GetVacancyByReferenceNumber(vacancyReferenceNumber)) .Returns(vacancy); MockVacancyPostingService.Setup(mock => mock .UpdateVacancy(It.IsAny <Vacancy>())) .Returns(vacancy); MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(vacancy)) .Returns(viewModel); MockApprenticeshipApplicationService.Setup(mock => mock. GetApplicationCount(vacancyId)) .Returns(applicationCount); var provider = GetVacancyPostingProvider(); // Act. var result = provider.UpdateVacancyDates(viewModel); // Assert. result.VacancyApplicationsState.Should().Be(expectedState); }
public void SetUp() { MockVacancyPostingService.Setup(mock => mock.GetVacancyByReferenceNumber(It.IsAny <int>())) .Returns(_existingVacancy); MockVacancyPostingService.Setup(mock => mock.CreateVacancy(It.IsAny <Vacancy>())) .Returns <Vacancy>(v => v); MockReferenceDataService.Setup(mock => mock.GetSectors()) .Returns(new List <Sector> { new Sector { Id = 1, Standards = new List <Standard> { new Standard { Id = 1, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Intermediate }, new Standard { Id = 2, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Advanced }, new Standard { Id = 3, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Higher }, new Standard { Id = 4, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.FoundationDegree }, new Standard { Id = 5, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Degree }, new Standard { Id = 6, ApprenticeshipSectorId = 1, ApprenticeshipLevel = ApprenticeshipLevel.Masters } } } }); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(ProviderSiteId, EdsUrn)) .Returns(_vacancyOwnerRelationship); MockConfigurationService .Setup(mock => mock.Get <CommonWebConfiguration>()) .Returns(_webConfiguration); MockReferenceDataService .Setup(mock => mock.GetCategories()) .Returns(_categories); }
public void IfTheVacancyAlreadyExistsShouldFillTheViewModelWithItsInformation() { const string ukprn = "ukprn"; const int employerId = 2; const int providerSiteId = 43; var vacancyWithLocationAddresses = GetVacancyWithLocationAddresses(_vacancyGuid); MockVacancyPostingService.Setup(s => s.GetVacancy(_vacancyGuid)).Returns(vacancyWithLocationAddresses.Vacancy); MockVacancyPostingService.Setup(s => s.GetVacancyLocations(vacancyWithLocationAddresses.Vacancy.VacancyId)) .Returns(vacancyWithLocationAddresses.LocationAddresses); var provider = GetVacancyPostingProvider(); var result = provider.LocationAddressesViewModel(ukprn, providerSiteId, employerId, _vacancyGuid); result.Addresses.Count.Should().Be(2); }
public void IfTheVacancyHasOnlyOneAddressAndItsDifferentFromTheEmployerAddressShouldAddTheVacancyAddressToVacancyLocationsList() { const string ukprn = "ukprn"; const int employerId = 2; const int providerSiteId = 43; const string additionalLocationInformation = "additional location information"; const int numberOfPositions = 4; var vacancy = GetVacancy(_vacancyGuid, 1, numberOfPositions, false, additionalLocationInformation); MockVacancyPostingService.Setup(s => s.GetVacancy(_vacancyGuid)).Returns(vacancy); MockVacancyPostingService.Setup(s => s.GetVacancyLocations(vacancy.VacancyId)) .Returns(new List <VacancyLocation>()); var provider = GetVacancyPostingProvider(); var result = provider.LocationAddressesViewModel(ukprn, providerSiteId, employerId, _vacancyGuid); result.Addresses.Count.Should().Be(1); }
public void ShouldAssignLocalAuthorityCodeToVacancyWithSameAddressAsEmployer() { // Arrange. const string localAuthorityCode = "ABCD"; var vvm = new Fixture().Build <NewVacancyViewModel>().Create(); var employerWithGeocode = new Fixture().Create <Employer>(); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())).Returns(vvm); MockEmployerService.Setup(m => m.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())).Returns(employerWithGeocode); MockLocalAuthorityLookupService.Setup(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode)).Returns(localAuthorityCode); MockProviderService.Setup(s => s.GetProvider(Ukprn, true)).Returns(new Provider()); MockVacancyPostingService.Setup(s => s.GetVacancy(It.IsAny <Guid>())).Returns(new Fixture().Create <Vacancy>()); var provider = GetVacancyPostingProvider(); // Act. provider.UpdateVacancy(_validVacancyMinimumDataSansReferenceNumber); // Assert. MockLocalAuthorityLookupService.Verify(m => m.GetLocalAuthorityCode(employerWithGeocode.Address.Postcode), Times.Once); MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.LocalAuthorityCode == localAuthorityCode)), Times.Once); }
public void ShouldReturnANewVacancyIfVacancyGuidDoesNotExists() { // Arrange var vacancyGuid = Guid.NewGuid(); Vacancy vacancy = null; MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(vacancy); var provider = GetVacancyPostingProvider(); // Act var result = provider.GetNewVacancyViewModel(VacancyOwnerRelationshipId, vacancyGuid, null); // Assert MockVacancyPostingService.Verify(s => s.GetVacancy(vacancyGuid), Times.Once); MockProviderService.Verify(s => s.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true), Times.Once); MockEmployerService.Verify(s => s.GetEmployer(EmployerId, It.IsAny <bool>()), Times.Once); result.Should() .Match <NewVacancyViewModel>( r => r.VacancyOwnerRelationship.EmployerDescription == _vacancyOwnerRelationship.EmployerDescription && r.VacancyOwnerRelationship.ProviderSiteId == ProviderSiteId); }
public void ShouldUpdateIfVacancyReferenceIsPresent() { // Arrange. var vvm = new Fixture().Build <NewVacancyViewModel>().Create(); MockMapper.Setup(m => m.Map <Vacancy, NewVacancyViewModel>(It.IsAny <Vacancy>())).Returns(vvm); MockProviderService.Setup(m => m.GetVacancyOwnerRelationship(It.IsAny <int>(), true)).Returns(new VacancyOwnerRelationship()); MockEmployerService.Setup(m => m.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())).Returns(new Fixture().Create <Employer>()); var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.UpdateVacancy(_validNewVacancyViewModelWithReferenceNumber); // Assert. MockVacancyPostingService.Verify(mock => mock.GetVacancyByReferenceNumber(_validNewVacancyViewModelWithReferenceNumber.VacancyReferenceNumber.Value), Times.Once); MockVacancyPostingService.Verify(mock => mock.GetNextVacancyReferenceNumber(), Times.Never); MockVacancyPostingService.Verify(mock => mock.UpdateVacancy(It.IsAny <Vacancy>()), Times.Once); viewModel.VacancyReferenceNumber.Should().HaveValue(); }
public void CloneVacancyShouldSaveTheClonedVacancy() { const int initialVacancyReferenceNumber = 1; const string initialVacancyTitle = "title"; const int newVacancyReferenceNumber = 2; var dateTimeNow = DateTime.UtcNow; MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(initialVacancyReferenceNumber)) .Returns(GetLiveVacancyWithComments(initialVacancyReferenceNumber, initialVacancyTitle)); MockVacancyPostingService.Setup(s => s.GetNextVacancyReferenceNumber()).Returns(newVacancyReferenceNumber); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(It.IsAny <int>(), true)) .Returns(new Fixture().Build <VacancyOwnerRelationship>().Create()); MockEmployerService.Setup(s => s.GetEmployer(It.IsAny <int>(), It.IsAny <bool>())) .Returns(new Fixture().Build <Employer>().Create()); MockTimeService.Setup(s => s.UtcNow).Returns(dateTimeNow); var provider = GetVacancyPostingProvider(); provider.CloneVacancy(initialVacancyReferenceNumber); MockVacancyPostingService.Verify(s => s.CreateVacancy(It.Is <Vacancy>(v => CheckClonedVacancy(v, newVacancyReferenceNumber, dateTimeNow)))); }
public void RemoveVacancyLocationInformationShouldCallReplaceLocationInformation() { var vacancyReferenceNumber = 1; var vacancyGuid = Guid.NewGuid(); var vacancyWithLocationAddresses = GetVacancyWithLocationAddresses(vacancyGuid, vacancyReferenceNumber); MockVacancyPostingService.Setup(s => s.GetVacancy(vacancyGuid)).Returns(vacancyWithLocationAddresses.Vacancy); MockVacancyPostingService.Setup(s => s.GetVacancyLocations(vacancyWithLocationAddresses.Vacancy.VacancyId)).Returns(vacancyWithLocationAddresses.LocationAddresses); var provider = GetVacancyPostingProvider(); provider.RemoveVacancyLocationInformation(vacancyGuid); MockVacancyPostingService.Verify( s => s.UpdateVacancy(It.Is <Vacancy>(v => v.IsEmployerLocationMainApprenticeshipLocation == null && v.NumberOfPositions == null && v.LocationAddressesComment == null && v.AdditionalLocationInformation == null && v.AdditionalLocationInformationComment == null))); MockVacancyPostingService.Verify( s => s.DeleteVacancyLocationsFor(It.IsAny <int>())); }
public void ShouldUpdatePossibleStartDate() { const int vacancyReferenceNumber = 1; var closingDate = DateTime.Today.AddDays(20); var possibleStartDate = DateTime.Today.AddDays(30); var viewModel = new FurtherVacancyDetailsViewModel { Wage = new WageViewModel(), VacancyDatesViewModel = new VacancyDatesViewModel { ClosingDate = new DateViewModel(closingDate), PossibleStartDate = new DateViewModel(possibleStartDate) }, VacancyReferenceNumber = vacancyReferenceNumber }; var apprenticeshipVacancy = new Vacancy { VacancyReferenceNumber = vacancyReferenceNumber, Wage = new Wage(WageType.NationalMinimum, null, null, null, null, WageUnit.Weekly, 30, null) }; MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber)) .Returns(apprenticeshipVacancy); MockVacancyPostingService.Setup(s => s.UpdateVacancy(It.IsAny <Vacancy>())) .Returns(apprenticeshipVacancy); MockMapper.Setup(m => m.Map <Vacancy, FurtherVacancyDetailsViewModel>(apprenticeshipVacancy)) .Returns(viewModel); var provider = GetVacancyPostingProvider(); provider.UpdateVacancyDates(viewModel); MockVacancyPostingService.Verify(s => s.UpdateVacancy(It.Is <Vacancy>(v => v.PossibleStartDate == possibleStartDate))); }
public void AddLocationsSetVacancyNumberOfPositionsFromVacancyLocationsIfTheresOnlyOneLocationAndItsDifferentFromEmployerAddress() { const int vacancyReferenceNumber = 1; const int numberOfPositions = 4; const string additionalLocationInformation = "additional location information"; var vacancy = GetVacancy(_vacancyGuid, 1, numberOfPositions, false, additionalLocationInformation); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancy); MockVacancyPostingService.Setup(s => s.GetVacancyLocations(vacancy.VacancyId)).Returns(new List <VacancyLocation>()); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(It.IsAny <int>(), It.IsAny <string>())) .Returns(new VacancyOwnerRelationship()); var provider = GetVacancyPostingProvider(); var locationSearchViewModel = GetLocationSearchViewModelWithOneLocationDifferentFromEmployerAddress(vacancyReferenceNumber, numberOfPositions); provider.AddLocations(locationSearchViewModel); MockVacancyPostingService.Verify( s => s.UpdateVacancy( It.Is <Vacancy>( v => v.IsEmployerLocationMainApprenticeshipLocation == locationSearchViewModel.IsEmployerLocationMainApprenticeshipLocation && v.NumberOfPositions == numberOfPositions))); MockVacancyPostingService.Verify( s => s.DeleteVacancyLocationsFor(It.IsAny <int>())); }
public void TransferVacancy_IfRelationshipExists_UpdateVacancyOwnerRelationshipIdOfVacancy() { var vacancyTransferViewModel = new ManageVacancyTransferViewModel { ProviderId = 10, ProviderSiteId = 12, VacancyReferenceNumbers = new List <int> { 1001 } }; MockVacancyPostingService.Setup( vps => vps.GetVacancyByReferenceNumber( vacancyTransferViewModel.VacancyReferenceNumbers.FirstOrDefault())) .Returns(_existingVacancy); MockProviderService.Setup(ps => ps.GetVacancyOwnerRelationship(_existingVacancy.VacancyOwnerRelationshipId, false)).Returns(_vacancyOwnerRelationship); MockProviderService.Setup(ps => ps.GetVacancyOwnerRelationship(_vacancyOwnerRelationship.EmployerId, vacancyTransferViewModel.ProviderSiteId)).Returns(_vacancyOwnerRelationshipWithRelationship); var vacancyPostingProvider = GetVacancyPostingProvider(); //Act vacancyPostingProvider.TransferVacancies(vacancyTransferViewModel); //Assert //Vacancy should have new provider and provider site ids set and use the VOR id from the new provider's VOR MockVacancyPostingService.Verify(mvps => mvps.UpdateVacanciesWithNewProvider(It.Is <Vacancy>(v => v.DeliveryOrganisationId == vacancyTransferViewModel.ProviderSiteId && v.VacancyManagerId == vacancyTransferViewModel.ProviderSiteId && v.ContractOwnerId == vacancyTransferViewModel.ProviderId && v.VacancyOwnerRelationshipId == _vacancyOwnerRelationshipWithRelationship.VacancyOwnerRelationshipId))); //Neither VOR should have been updated MockProviderService.Verify(mps => mps.SaveVacancyOwnerRelationship(It.Is <VacancyOwnerRelationship>(vp => vp.VacancyOwnerRelationshipId == _vacancyOwnerRelationship.VacancyOwnerRelationshipId)), Times.Never); MockProviderService.Verify(mps => mps.SaveVacancyOwnerRelationship(It.Is <VacancyOwnerRelationship>(vp => vp.VacancyOwnerRelationshipId == _vacancyOwnerRelationshipWithRelationship.VacancyOwnerRelationshipId)), Times.Never); }
public void AddLocationsShouldCallReplaceLocationInformation() { var vacancyReferenceNumber = 1; const string additionalLocationInformation = "additional location information"; const string aNewAdditionalLocationInformation = "a new additional location information"; const string aNewAdditionalLocationInformationComment = "a new additional location information comment"; const string aNewLocationAddressesComment = "a new additional location addresses comment"; var vacancyWithLocationAddresses = GetVacancyWithLocationAddresses(additionalLocationInformation); MockVacancyPostingService.Setup(s => s.GetVacancyByReferenceNumber(vacancyReferenceNumber)).Returns(vacancyWithLocationAddresses.Vacancy); MockVacancyPostingService.Setup(s => s.GetVacancyLocations(vacancyWithLocationAddresses.Vacancy.VacancyId)).Returns(vacancyWithLocationAddresses.LocationAddresses); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(It.IsAny <int>(), It.IsAny <string>())) .Returns(new VacancyOwnerRelationship()); var provider = GetVacancyPostingProvider(); var locationSearchViewModel = GetLocationSearchViewModel(aNewAdditionalLocationInformation, aNewAdditionalLocationInformationComment, vacancyReferenceNumber, aNewLocationAddressesComment); provider.AddLocations(locationSearchViewModel); MockVacancyPostingService.Verify( s => s.UpdateVacancy(It.Is <Vacancy>(v => v.IsEmployerLocationMainApprenticeshipLocation == locationSearchViewModel.IsEmployerLocationMainApprenticeshipLocation && v.NumberOfPositions == null && v.LocationAddressesComment == aNewLocationAddressesComment && v.AdditionalLocationInformation == aNewAdditionalLocationInformation && v.AdditionalLocationInformationComment == aNewAdditionalLocationInformationComment))); MockVacancyPostingService.Verify( s => s.DeleteVacancyLocationsFor(It.IsAny <int>())); }
public void TransferVacancy_IfNoRelationshipExists_CreateVacancyOwnerRelationship() { const int newVorId = 1234; var vacancyTransferViewModel = new ManageVacancyTransferViewModel { ProviderId = 10, ProviderSiteId = 12, VacancyReferenceNumbers = new List <int> { 1001 } }; MockVacancyPostingService.Setup( vps => vps.GetVacancyByReferenceNumber( vacancyTransferViewModel.VacancyReferenceNumbers.FirstOrDefault())) .Returns(_existingVacancy); MockProviderService.Setup(ps => ps.GetVacancyOwnerRelationship(_existingVacancy.VacancyOwnerRelationshipId, false)).Returns(_vacancyOwnerRelationship); //This method actually returns a new VOR with a zero'd ID instead of null if it doesn't exist MockProviderService.Setup(ps => ps.GetVacancyOwnerRelationship(_vacancyOwnerRelationship.EmployerId, vacancyTransferViewModel.ProviderSiteId)).Returns <int, int>((employerId, providerSiteId) => new VacancyOwnerRelationship { EmployerId = employerId, ProviderSiteId = providerSiteId }); MockProviderService.Setup(ps => ps.SaveVacancyOwnerRelationship(It.Is <VacancyOwnerRelationship>( vor => vor.VacancyOwnerRelationshipId == 0 && vor.EmployerId == _vacancyOwnerRelationship.EmployerId && vor.ProviderSiteId == vacancyTransferViewModel.ProviderSiteId && vor.EmployerDescription == _vacancyOwnerRelationship.EmployerDescription && vor.EmployerWebsiteUrl == _vacancyOwnerRelationship.EmployerWebsiteUrl))) .Returns <VacancyOwnerRelationship>( vor => { vor.VacancyOwnerRelationshipId = newVorId; return(vor); }); var vacancyPostingProvider = GetVacancyPostingProvider(); //Act vacancyPostingProvider.TransferVacancies(vacancyTransferViewModel); //Assert //A new VOR should have been created for the new provider and provider site MockProviderService.Verify( mps => mps.SaveVacancyOwnerRelationship( It.Is <VacancyOwnerRelationship>( vor => vor.VacancyOwnerRelationshipId == newVorId && vor.EmployerId == _vacancyOwnerRelationship.EmployerId && vor.ProviderSiteId == vacancyTransferViewModel.ProviderSiteId && vor.EmployerDescription == _vacancyOwnerRelationship.EmployerDescription && vor.EmployerWebsiteUrl == _vacancyOwnerRelationship.EmployerWebsiteUrl))); //And the vacancy should now use that new VOR as well as the new provider and provider site ids MockVacancyPostingService.Verify(mvps => mvps.UpdateVacanciesWithNewProvider(It.Is <Vacancy>(v => v.DeliveryOrganisationId == vacancyTransferViewModel.ProviderSiteId && v.VacancyManagerId == vacancyTransferViewModel.ProviderSiteId && v.ContractOwnerId == vacancyTransferViewModel.ProviderId && v.VacancyOwnerRelationshipId == newVorId))); }
public void CreateVacancyShouldCreateTheVacancy() { const int vacancyOwnerRelationshipId = 1; const int employerId = 2; const string ukprn = "1234"; const string employersPostcode = "cv1 9SX"; var vacancyGuid = Guid.NewGuid(); const int vacancyReferenceNumber = 123456; const bool isEmployerLocationMainApprenticeshipLocation = true; int? numberOfPositions = 2; var address = new Fixture().Build <PostalAddress>().With(a => a.Postcode, employersPostcode).Create(); const int providerId = 4; const string localAuthorityCode = "lac"; const string employerWebsiteUrl = "www.google.com"; const string employerDescription = "employer description"; // Arrange. MockVacancyPostingService.Setup(s => s.GetNextVacancyReferenceNumber()).Returns(vacancyReferenceNumber); MockProviderService.Setup(s => s.GetVacancyOwnerRelationship(vacancyOwnerRelationshipId, true)) .Returns( new Fixture().Build <VacancyOwnerRelationship>() .With(v => v.VacancyOwnerRelationshipId, vacancyOwnerRelationshipId) .With(v => v.EmployerId, employerId) .Create()); MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>())) .Returns( new Fixture().Build <Employer>() .With(e => e.EmployerId, employerId) .With(e => e.Address, address) .Create()); MockProviderService.Setup(s => s.GetProvider(ukprn, true)) .Returns(new Fixture().Build <Provider>().With(p => p.ProviderId, providerId).Create()); MockLocalAuthorityService.Setup(s => s.GetLocalAuthorityCode(employersPostcode)).Returns(localAuthorityCode); // Act. var provider = GetVacancyPostingProvider(); provider.CreateVacancy(new VacancyMinimumData { IsEmployerLocationMainApprenticeshipLocation = isEmployerLocationMainApprenticeshipLocation, VacancyGuid = vacancyGuid, VacancyOwnerRelationshipId = vacancyOwnerRelationshipId, Ukprn = ukprn, NumberOfPositions = numberOfPositions, EmployerWebsiteUrl = employerWebsiteUrl, EmployerDescription = employerDescription }); // Assert. MockVacancyPostingService.Verify(s => s.GetNextVacancyReferenceNumber()); MockProviderService.Verify(s => s.GetVacancyOwnerRelationship(vacancyOwnerRelationshipId, true)); MockEmployerService.Verify(s => s.GetEmployer(employerId, It.IsAny <bool>())); MockProviderService.Verify(s => s.GetProvider(ukprn, true)); MockLocalAuthorityService.Verify(s => s.GetLocalAuthorityCode(employersPostcode)); MockVacancyPostingService.Verify(s => s.CreateVacancy(It.Is <Vacancy>(v => v.VacancyGuid == vacancyGuid && v.VacancyReferenceNumber == vacancyReferenceNumber && v.Title == null && v.ShortDescription == null && v.VacancyOwnerRelationshipId == vacancyOwnerRelationshipId && v.Status == VacancyStatus.Draft && v.OfflineVacancy.HasValue == false && v.OfflineApplicationUrl == null && v.OfflineApplicationInstructions == null && v.IsEmployerLocationMainApprenticeshipLocation == isEmployerLocationMainApprenticeshipLocation && v.NumberOfPositions == numberOfPositions && v.VacancyType == VacancyType.Unknown && v.Address == address && v.ContractOwnerId == providerId && v.LocalAuthorityCode == localAuthorityCode && v.EmployerWebsiteUrl == employerWebsiteUrl && v.EmployerDescription == employerDescription ))); }