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