Exemplo n.º 1
0
        public void ShouldGetProviderViewModel()
        {
            // Arrange.
            var providerProvider = GetProviderProvider();

            var provider = new Fixture()
                           .Create <Provider>();

            MockProviderService.Setup(mock =>
                                      mock.GetProvider(provider.Ukprn, true))
            .Returns(provider);

            var providerSites = new Fixture()
                                .Build <ProviderSite>()
                                .CreateMany(5)
                                .ToArray();

            MockProviderService.Setup(mock =>
                                      mock.GetProviderSites(provider.Ukprn))
            .Returns(providerSites);

            // Act.
            var viewModel = providerProvider.GetProviderViewModel(provider.Ukprn);

            // Assert.
            viewModel.Should().NotBeNull();

            viewModel.ProviderId.Should().Be(provider.ProviderId);
            viewModel.FullName.Should().Be(provider.FullName);
            viewModel.TradingName.Should().Be(provider.TradingName);
            viewModel.IsMigrated.Should().Be(provider.IsMigrated);

            viewModel.ProviderSiteViewModels.Should().NotBeNull();
            viewModel.ProviderSiteViewModels.Count().Should().Be(providerSites.Length);
        }
Exemplo n.º 2
0
        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)));
        }
Exemplo n.º 3
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);
        }
 public void SetUp()
 {
     MockProviderService
     .Setup(mock => mock.GetVacancyOwnerRelationship(VacancyOwnerRelationshipId, true))
     .Returns(VacancyOwnerRelationship);
     MockEmployerService.Setup(s => s.GetEmployer(VacancyOwnerRelationship.EmployerId, true))
     .Returns(new Fixture().Build <Employer>().Create());
 }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public void ShoulReturnEmployersForNameAndLocationEmployerSearchViewModel(int unactivatedEmployerCount)
        {
            // Arrange.
            var searchViewModel = new EmployerSearchViewModel
            {
                FilterType     = EmployerFilterType.NameAndLocation,
                ProviderSiteId = 42,
                Name           = "a",
                Location       = "b",
                Employers      = new PageableViewModel <EmployerViewModel>
                {
                    CurrentPage = 3
                }
            };

            var employers = new Fixture()
                            .CreateMany <Employer>(PageSize)
                            .ToArray();

            var vacancyParties = BuildFakeVacancyParties(employers, unactivatedEmployerCount);

            var pageableVacancyParties = new Fixture()
                                         .Build <Pageable <VacancyOwnerRelationship> >()
                                         .With(each => each.Page, vacancyParties)
                                         .Create();

            Expression <Func <EmployerSearchRequest, bool> > matchingSearchRequest = it => it.ProviderSiteId == searchViewModel.ProviderSiteId;

            MockProviderService.Setup(mock => mock
                                      .GetVacancyOwnerRelationships(It.Is(matchingSearchRequest), searchViewModel.Employers.CurrentPage, PageSize))
            .Returns(pageableVacancyParties);

            Expression <Func <IEnumerable <int>, bool> > matchingEmployerIds = it => true;

            MockEmployerService.Setup(mock => mock
                                      .GetEmployers(It.Is(matchingEmployerIds), It.IsAny <bool>()))
            .Returns(employers);

            var provider = GetProviderProvider();

            // Act.
            var viewModel = provider.GetVacancyOwnerRelationshipViewModels(searchViewModel);

            // Assert.
            viewModel.Should().NotBeNull();

            viewModel.ProviderSiteId.Should().Be(searchViewModel.ProviderSiteId);

            viewModel.Employers.Should().NotBeNull();
            viewModel.Employers.Page.Count().Should().Be(PageSize - unactivatedEmployerCount);

            viewModel.FilterType.Should().Be(EmployerFilterType.NameAndLocation);
            viewModel.Name.Should().NotBeEmpty();
            viewModel.Location.Should().NotBeEmpty();
        }
        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);
        }
Exemplo n.º 10
0
        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 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);
        }
Exemplo n.º 12
0
        public void ShoulReturnEmployersForProviderSite(int unactivatedEmployerCount)
        {
            // Arrange.
            const int pageNumber     = 1;
            const int providerSiteId = 42;

            var employers = new Fixture()
                            .CreateMany <Employer>(PageSize)
                            .ToArray();

            var vacancyParties = BuildFakeVacancyParties(employers, unactivatedEmployerCount);

            var pageableVacancyParties = new Fixture()
                                         .Build <Pageable <VacancyOwnerRelationship> >()
                                         .With(each => each.Page, vacancyParties)
                                         .Create();

            Expression <Func <EmployerSearchRequest, bool> > matchingSearchRequest = it => it.ProviderSiteId == providerSiteId;

            MockProviderService.Setup(mock => mock
                                      .GetVacancyOwnerRelationships(It.Is(matchingSearchRequest), pageNumber, PageSize))
            .Returns(pageableVacancyParties);

            Expression <Func <IEnumerable <int>, bool> > matchingEmployerIds = it => true;

            MockEmployerService.Setup(mock => mock
                                      .GetEmployers(It.Is(matchingEmployerIds), It.IsAny <bool>()))
            .Returns(employers);

            var provider = GetProviderProvider();

            // Act.
            var viewModel = provider.GetVacancyOwnerRelationshipViewModels(providerSiteId);

            // Assert.
            viewModel.Should().NotBeNull();

            viewModel.ProviderSiteId.Should().Be(providerSiteId);

            viewModel.Employers.Should().NotBeNull();
            viewModel.Employers.Page.Count().Should().Be(PageSize - unactivatedEmployerCount);
        }
Exemplo n.º 13
0
        public void WhenCreatingANewVacancyShouldReturnANewLocationSearchViewModel()
        {
            const string ukprn          = "ukprn";
            const int    employerId     = 1;
            const int    providerSiteId = 42;

            var provider = GetVacancyPostingProvider();

            MockProviderService.Setup(s => s.GetProviderSite(providerSiteId))
            .Returns(new Fixture().Build <ProviderSite>().With(ps => ps.ProviderSiteId, providerSiteId).Create());
            MockEmployerService.Setup(s => s.GetEmployer(employerId, It.IsAny <bool>()))
            .Returns(new Fixture().Build <Employer>().With(e => e.EmployerId, employerId).Create());

            var result = provider.LocationAddressesViewModel(ukprn, providerSiteId, employerId, _vacancyGuid);

            result.Ukprn.Should().Be(ukprn);
            result.EmployerId.Should().Be(employerId);
            result.ProviderSiteId.Should().Be(providerSiteId);
            result.VacancyGuid.Should().Be(_vacancyGuid);
            result.Addresses.Should().HaveCount(0);
        }
Exemplo n.º 14
0
        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 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();
        }
Exemplo n.º 16
0
        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 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);
        }
Exemplo n.º 18
0
        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>()));
        }
Exemplo n.º 19
0
        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
                                                                                  )));
        }