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());
 }
Example #2
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);
        }
Example #6
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 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);
        }
Example #8
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);
        }
        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);
        }
        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);
        }
Example #11
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();
        }
Example #13
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 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
                                                                                  )));
        }