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 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 ))); }