Example #1
0
        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);
        }
Example #2
0
        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);
        }