public void GetCountsForVacancyIds_GetApplicationCount() { // TODO: This test doesn't really have any value, but it has been kept working anyway //Arrange var vacancy = new ApprenticeshipSummary { ClosingDate = DateTime.Today.AddDays(90), Id = 1 }; var expectedCounts = new Mock <IApplicationCounts>(); expectedCounts.Setup(mock => mock.AllApplications).Returns(2); expectedCounts.Setup(mock => mock.NewApplications).Returns(1); var expected = new Dictionary <int, IApplicationCounts> { { vacancy.Id, expectedCounts.Object } }; var vacancies = new[] { vacancy.Id }; _mockApprenticeshipApplicationStatsRepository.Setup(mock => mock.GetCountsForVacancyIds(vacancies)).Returns(expected); //Act var response = _apprenticeshipApplicationService.GetApplicationCount(vacancy.Id); //Assert Assert.AreEqual(response, expected[vacancy.Id].AllApplications); }
public ApprenticeshipSummary Build() { var summary = new ApprenticeshipSummary { Id = _vacancyId }; return(summary); }
public void ShouldQueueCorrectNumberOfVacanySummaries(int vacanciesReturned) { var summaryPage = new VacancySummaryPage { PageNumber = vacanciesReturned, ScheduledRefreshDateTime = DateTime.Today }; _vacancyProviderMock.Setup(x => x.GetVacancySummaries(vacanciesReturned)) .Returns((int vr) => { var traineeshipSummaries = new List <TraineeshipSummary>(vr); var apprenticeshipSummaries = new List <ApprenticeshipSummary>(vr); for (int i = 1; i <= vr; i++) { var apprenticeshipSummary = new ApprenticeshipSummary { Id = i }; apprenticeshipSummaries.Add(apprenticeshipSummary); } return(new VacancySummaries(apprenticeshipSummaries, traineeshipSummaries)); }); _mapperMock.Setup( x => x.Map <IEnumerable <ApprenticeshipSummary>, IEnumerable <ApprenticeshipSummaryUpdate> >( It.IsAny <IEnumerable <ApprenticeshipSummary> >())) .Returns((IEnumerable <ApprenticeshipSummary> vacancies) => { var vacUpdates = new List <ApprenticeshipSummaryUpdate>(vacancies.Count()); vacancies.ToList() .ForEach( v => vacUpdates.Add(new ApprenticeshipSummaryUpdate { Id = v.Id, ScheduledRefreshDateTime = summaryPage.ScheduledRefreshDateTime })); return(vacUpdates); }); var vacancyConsumer = GetGatewayVacancySummaryProcessor(); vacancyConsumer.QueueVacancySummaries(summaryPage); _vacancyProviderMock.Verify(x => x.GetVacancySummaries( It.Is <int>(pn => pn == vacanciesReturned)), Times.Once); _mapperMock.Verify( x => x.Map <IEnumerable <ApprenticeshipSummary>, IEnumerable <ApprenticeshipSummaryUpdate> >( It.Is <IEnumerable <ApprenticeshipSummary> >(vc => vc.Count() == vacanciesReturned)), Times.Once); _busMock.Verify(x => x.PublishMessage(It.IsAny <ApprenticeshipSummary>()), Times.Exactly(vacanciesReturned)); }
public static ApprenticeshipSummary GetApprenticeshipSummary(VacancySummary vacancy, Employer employer, Provider provider, IList <Category> categories, ILogService logService) { try { //Manually mapping rather than using automapper as the two enties are significantly different var location = GetGeoPoint(vacancy); var category = vacancy.GetCategory(categories); var subcategory = vacancy.GetSubCategory(categories); LogCategoryAndSubCategory(vacancy, logService, category, subcategory); var summary = new ApprenticeshipSummary { Id = vacancy.VacancyId, //Goes into elastic unformatted for searching VacancyReference = vacancy.VacancyReferenceNumber.ToString(), Title = vacancy.Title, // ReSharper disable PossibleInvalidOperationException PostedDate = vacancy.DateQAApproved.Value, StartDate = vacancy.PossibleStartDate.Value, ClosingDate = vacancy.ClosingDate.Value, // ReSharper restore PossibleInvalidOperationException Description = vacancy.ShortDescription, NumberOfPositions = vacancy.NumberOfPositions, EmployerName = string.IsNullOrEmpty(vacancy.EmployerAnonymousName) ? employer.FullName : vacancy.EmployerAnonymousName, ProviderName = provider.TradingName, IsPositiveAboutDisability = employer.IsPositiveAboutDisability, IsEmployerAnonymous = !string.IsNullOrEmpty(vacancy.EmployerAnonymousName), Location = location, VacancyLocationType = vacancy.VacancyLocationType == VacancyLocationType.Nationwide ? ApprenticeshipLocationType.National : ApprenticeshipLocationType.NonNational, ApprenticeshipLevel = vacancy.ApprenticeshipLevel.GetApprenticeshipLevel(), Wage = vacancy.Wage, WorkingWeek = vacancy.WorkingWeek, CategoryCode = category.CodeName, Category = category.FullName, SubCategoryCode = subcategory.CodeName, SubCategory = subcategory.FullName, AnonymousEmployerName = vacancy.EmployerAnonymousName }; return(summary); } catch (Exception ex) { logService.Error($"Failed to map apprenticeship with Id: {vacancy?.VacancyId ?? 0}", ex); return(null); } }
public void QueueVacancyIfExpiring(ApprenticeshipSummary vacancySummary) { try { if (vacancySummary.ClosingDate < DateTime.Now.AddHours(_vacancyAboutToExpireNotificationHours)) { _logger.Debug("Queueing expiring vacancy"); var vacancyAboutToExpireMessage = new VacancyAboutToExpire { Id = vacancySummary.Id }; _messageBus.PublishMessage(vacancyAboutToExpireMessage); } } catch (Exception ex) { _logger.Warn("Failed queueing expiring vacancy {0}", ex, vacancySummary.Id); } }
public void ShouldQueueTheVacancyIfTheVacancyIsAboutToExpire() { const int aVacancyId = 5; const int vacancyAboutToExpireNotificationHours = 96; _configurationManagerMock.Setup(cmm => cmm.GetAppSetting <int>("VacancyAboutToExpireNotificationHours")) .Returns(vacancyAboutToExpireNotificationHours); var vacancyConsumer = GetGatewayVacancySummaryProcessor(); var vacancySummary = new ApprenticeshipSummary { Id = aVacancyId, ClosingDate = DateTime.Now.AddHours(vacancyAboutToExpireNotificationHours - 1) }; vacancyConsumer.QueueVacancyIfExpiring(vacancySummary); _busMock.Verify(x => x.PublishMessage(It.Is <VacancyAboutToExpire>(m => m.Id == aVacancyId))); _configurationManagerMock.VerifyAll(); }
public ApprenticeshipApplicationDetail() { Vacancy = new ApprenticeshipSummary(); }