Beispiel #1
0
        public void ShouldHandleEmployerNameAnonymisation(
            string anonymousEmployerName, bool anonymised)
        {
            // Arrange.
            var fixture = new Fixture();

            var vacancy = fixture
                          .Build <Domain.Entities.Raa.Vacancies.VacancySummary>()
                          .With(each => each.EmployerAnonymousName, anonymousEmployerName)
                          .Create();

            var provider = fixture.Create <Domain.Entities.Raa.Parties.Provider>();
            var employer = fixture.Create <Domain.Entities.Raa.Parties.Employer>();

            var categories = fixture
                             .Build <Domain.Entities.ReferenceData.Category>()
                             .CreateMany(1)
                             .ToList();

            // Act.
            var summary = ApprenticeshipSummaryMapper.GetApprenticeshipSummary(
                vacancy, employer, provider, categories, _mockLogService.Object);

            // Assert.
            summary.Should().NotBeNull();
            summary.EmployerName.Should().Be(anonymised ? "Anonymous Employer Name" : employer.FullName);
        }
        public VacancySummaries GetVacancySummaries(int pageNumber)
        {
            //Page number coming in increments from 1 rather than 0, the repo expects pages to start at 0 so take one from the passed in value
            var query = new VacancySummaryByStatusQuery()
            {
                PageSize        = PageSize,
                RequestedPage   = pageNumber,
                DesiredStatuses = _desiredStatuses
            };

            int totalRecords;

            var vacancies      = _vacancySummaryService.GetWithStatus(query, out totalRecords);
            var vacancyParties = _providerService.GetVacancyOwnerRelationships(vacancies.Select(v => v.VacancyOwnerRelationshipId).Distinct(), false);
            var employers      = _employerService.GetEmployers(vacancyParties.Values.Select(v => v.EmployerId).Distinct()).ToDictionary(e => e.EmployerId, e => e);
            var providers      = _providerService.GetProviders(vacancies.Select(v => v.ContractOwnerId).Distinct()).ToDictionary(p => p.ProviderId, p => p);
            var categories     = _referenceDataProvider.GetCategories(CategoryStatus.Active, CategoryStatus.PendingClosure).ToList();
            //TODO: workaround to have the indexing partially working. Should be done properly
            var apprenticeshipSummaries =
                vacancies.Where(v => v.VacancyType == VacancyType.Apprenticeship).Select(
                    v =>
            {
                try
                {
                    return(ApprenticeshipSummaryMapper.GetApprenticeshipSummary(v,
                                                                                employers[vacancyParties[v.VacancyOwnerRelationshipId].EmployerId],
                                                                                providers[v.ContractOwnerId],
                                                                                categories, _logService));
                }
                catch (Exception ex)
                {
                    _logService.Error($"Error indexing the apprenticeship vacancy with ID={v.VacancyId}", ex);
                    return(null);
                }
            });

            var traineeshipSummaries =
                vacancies.Where(v => v.VacancyType == VacancyType.Traineeship).Select(
                    v =>
            {
                try
                {
                    return(TraineeshipSummaryMapper.GetTraineeshipSummary(v,
                                                                          employers[vacancyParties[v.VacancyOwnerRelationshipId].EmployerId],
                                                                          providers[v.ContractOwnerId],
                                                                          categories, _logService));
                }
                catch (Exception ex)
                {
                    _logService.Error($"Error indexing the traineeship vacancy with ID={v.VacancyId}", ex);
                    return(null);
                }
            });

            return(new VacancySummaries(apprenticeshipSummaries.Where(s => s != null), traineeshipSummaries.Where(s => s != null)));
        }
        public void PublishVacancySummaryUpdate(Vacancy vacancy)
        {
            if (vacancy == null)
            {
                return;
            }

            try
            {
                if (vacancy.Status == VacancyStatus.Live)
                {
                    var vacancySummary = _vacancySummaryService.GetByIds(new List <int> {
                        vacancy.VacancyId
                    }).Single();
                    var vacancyOwnerRelationship = _providerService.GetVacancyOwnerRelationships(new List <int> {
                        vacancySummary.VacancyOwnerRelationshipId
                    }, false).Single().Value;
                    var employer = _employerService.GetEmployers(new List <int> {
                        vacancyOwnerRelationship.EmployerId
                    }).Single();
                    var providers = _providerService.GetProviders(new List <int> {
                        vacancy.ContractOwnerId
                    }).Single();
                    var categories = _referenceDataProvider.GetCategories().ToList();

                    if (vacancy.VacancyType == VacancyType.Apprenticeship)
                    {
                        _logService.Info($"Publishing apprenticeship summary message for vacancy id {vacancy.VacancyId}");
                        var apprenticeshipSummary       = ApprenticeshipSummaryMapper.GetApprenticeshipSummary(vacancySummary, employer, providers, categories, _logService);
                        var apprenticeshipSummaryUpdate = _mapper.Map <ApprenticeshipSummary, ApprenticeshipSummaryUpdate>(apprenticeshipSummary);
                        apprenticeshipSummaryUpdate.UseAlias = true;
                        _serviceBus.PublishMessage(apprenticeshipSummaryUpdate);
                        _logService.Info($"Published apprenticeship summary message for vacancy id {vacancy.VacancyId}");
                    }

                    if (vacancy.VacancyType == VacancyType.Traineeship)
                    {
                        _logService.Info($"Publishing traineeship summary message for vacancy id {vacancy.VacancyId}");
                        var traineeshipSummary       = TraineeshipSummaryMapper.GetTraineeshipSummary(vacancySummary, employer, providers, categories, _logService);
                        var traineeshipSummaryUpdate = _mapper.Map <TraineeshipSummary, TraineeshipSummaryUpdate>(traineeshipSummary);
                        traineeshipSummaryUpdate.UseAlias = true;
                        _serviceBus.PublishMessage(traineeshipSummaryUpdate);
                        _logService.Info($"Published traineeship summary message for vacancy id {vacancy.VacancyId}");
                    }
                }
            }
            catch (Exception ex)
            {
                _logService.Warn($"Failed to publish vacancy summary message for vacancy id {vacancy.VacancyId}", ex);
            }
        }
Beispiel #4
0
        public void ShouldLogAndReturnNullOnFailureToGetApprenticeshipSummary(int categoryCount)
        {
            // Arrange.
            var fixture = new Fixture();

            var employer = fixture.Create <Domain.Entities.Raa.Parties.Employer>();
            var provider = fixture.Create <Domain.Entities.Raa.Parties.Provider>();

            var categories = fixture
                             .Build <Domain.Entities.ReferenceData.Category>()
                             .CreateMany(categoryCount)
                             .ToList();

            // Act.
            var summary = ApprenticeshipSummaryMapper.GetApprenticeshipSummary(
                null, employer, provider, categories, _mockLogService.Object);

            // Assert.
            summary.Should().BeNull();
            _mockLogService.Verify(mock =>
                                   mock.Error(It.IsAny <string>(), It.IsAny <Exception>()), Times.Once);
        }
Beispiel #5
0
        public void ShouldGetApprenticeshipSummary(int vacancyCount, int categoryCount)
        {
            for (var i = 0; i < vacancyCount; i++)
            {
                // Arrange.
                var fixture = new Fixture();

                var vacancy  = fixture.Create <Domain.Entities.Raa.Vacancies.VacancySummary>();
                var employer = fixture.Create <Domain.Entities.Raa.Parties.Employer>();
                var provider = fixture.Create <Domain.Entities.Raa.Parties.Provider>();

                var categories = fixture
                                 .Build <Domain.Entities.ReferenceData.Category>()
                                 .CreateMany(categoryCount)
                                 .ToList();

                // Act.
                var summary = ApprenticeshipSummaryMapper.GetApprenticeshipSummary(
                    vacancy, employer, provider, categories, _mockLogService.Object);

                // Assert.
                summary.Should().NotBeNull();
            }
        }