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 ShouldDefaultToPreferredSite() { // Arrange. var provider = GetVacancyPostingProvider(); // Act. var viewModel = provider.GetNewVacancyViewModel(VacancyOwnerRelationshipId, VacancyGuid, null); // Assert. MockProviderService.Verify(mock => mock.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true), Times.Once); MockEmployerService.Verify(s => s.GetEmployer(EmployerId, true), Times.Once); viewModel.Should().NotBeNull(); viewModel.VacancyOwnerRelationship.ProviderSiteId.Should().Be(ProviderSiteId); }
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 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 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 ))); }