public void ShouldHonourFeatureSwitch(bool enabled) { // Arrange. _configurationService .Setup(mock => mock.Get <ProcessConfiguration>()) .Returns(new ProcessConfiguration { EnableVacancySiteMap = enabled }); var subscriber = new CreateVacancySiteMapRequestSubscriber( _logger.Object, _configurationService.Object, _siteMapVacancyProcessor.Object); var request = new CreateVacancySiteMapRequest { ApprenticeshipVacancyIndexName = "apprenticeships", TraineeshipVacancyIndexName = "vacancy" }; // Act. var state = subscriber.Consume(request); // Assert. state.Should().NotBeNull(); state.Should().Be(ServiceBusMessageStates.Complete); _siteMapVacancyProcessor.Verify(mock => mock.Process(request), Times.Exactly(enabled ? 1 : 0)); }
public ServiceBusMessageStates Consume(VacancySummaryUpdateComplete updateComplete) { _logger.Debug("Received vacancy summary update completed message."); var isApprenticeshipIndexCorrectlyCreated = _apprenticeshipVacancyIndexerService.IsIndexCorrectlyCreated(updateComplete.ScheduledRefreshDateTime); var apprenticeshipVacancyIndexName = default(string); if (isApprenticeshipIndexCorrectlyCreated) { _logger.Info("Swapping apprenticeship index alias after vacancy summary update completed"); apprenticeshipVacancyIndexName = _apprenticeshipVacancyIndexerService.SwapIndex(updateComplete.ScheduledRefreshDateTime); _logger.Info("Index apprenticeship swapped after vacancy summary update completed: '{0}'", apprenticeshipVacancyIndexName); } else { _logger.Error("The new apprenticeship index is not correctly created. Aborting swap."); } var isTraineeshipIndexCorrectlyCreated = _traineeVacancyIndexerService.IsIndexCorrectlyCreated(updateComplete.ScheduledRefreshDateTime); var traineeshipVacancyIndexName = default(string); if (isTraineeshipIndexCorrectlyCreated) { _logger.Info("Swapping traineeship index alias after vacancy summary update completed"); traineeshipVacancyIndexName = _traineeVacancyIndexerService.SwapIndex(updateComplete.ScheduledRefreshDateTime); _logger.Info("Index traineeship swapped after vacancy summary update completed: '{0}'", traineeshipVacancyIndexName); } else { _logger.Error("The new traineeship index is not correctly created. Aborting swap."); } if (isApprenticeshipIndexCorrectlyCreated && isTraineeshipIndexCorrectlyCreated) { var request = new CreateVacancySiteMapRequest { ApprenticeshipVacancyIndexName = apprenticeshipVacancyIndexName, TraineeshipVacancyIndexName = traineeshipVacancyIndexName }; _serviceBus.PublishMessage(request); } else { _logger.Warn("One or more indexes was not correctly created (see previously logged errors), vacancy site map will not be created."); } return(ServiceBusMessageStates.Complete); }
public void ShouldQueueCreateVacancySiteMapRequest() { // Arrange. const string apprenticeshipVacancyIndexName = "apprenticeships.2015-12-31-00"; const string traineeshipVacancyIndexName = "traineeships.2015-12-31-00"; var scheduledRefreshDateTime = DateTime.UtcNow; _mockApprenticeshipIndexer.Setup(mock => mock.IsIndexCorrectlyCreated(scheduledRefreshDateTime)).Returns(true); _mockApprenticeshipIndexer.Setup(mock => mock.SwapIndex(scheduledRefreshDateTime)).Returns(apprenticeshipVacancyIndexName); _mockTraineeshipIndexer.Setup(mock => mock.IsIndexCorrectlyCreated(scheduledRefreshDateTime)).Returns(true); _mockTraineeshipIndexer.Setup(mock => mock.SwapIndex(scheduledRefreshDateTime)).Returns(traineeshipVacancyIndexName); CreateVacancySiteMapRequest actualCreateVacancySiteMapRequest = null; _mockServiceBus.Setup(mock => mock .PublishMessage(It.IsAny <CreateVacancySiteMapRequest>())) .Callback((CreateVacancySiteMapRequest request) => actualCreateVacancySiteMapRequest = request); var subscriber = new VacancySummaryCompleteSubscriber( _mockLogService.Object, _mockServiceBus.Object, _mockApprenticeshipIndexer.Object, _mockTraineeshipIndexer.Object); // Act. var state = subscriber.Consume(new VacancySummaryUpdateComplete { ScheduledRefreshDateTime = scheduledRefreshDateTime }); // Assert. state.Should().NotBeNull(); state.Should().Be(ServiceBusMessageStates.Complete); _mockApprenticeshipIndexer.Verify(mock => mock.IsIndexCorrectlyCreated(scheduledRefreshDateTime), Times.Once); _mockApprenticeshipIndexer.Verify(mock => mock.SwapIndex(scheduledRefreshDateTime), Times.Once); _mockTraineeshipIndexer.Verify(mock => mock.IsIndexCorrectlyCreated(scheduledRefreshDateTime), Times.Once); _mockTraineeshipIndexer.Verify(mock => mock.SwapIndex(scheduledRefreshDateTime), Times.Once); _mockServiceBus.Verify(mock => mock.PublishMessage(It.IsAny <CreateVacancySiteMapRequest>()), Times.Once()); actualCreateVacancySiteMapRequest.ShouldBeEquivalentTo(new CreateVacancySiteMapRequest { ApprenticeshipVacancyIndexName = apprenticeshipVacancyIndexName, TraineeshipVacancyIndexName = traineeshipVacancyIndexName }); }
public void Process(CreateVacancySiteMapRequest request) { _logger.Info("Creating site map based on apprenticeship and traineeship indexes '{0}' and '{1}' respectively", request.ApprenticeshipVacancyIndexName, request.TraineeshipVacancyIndexName); var apprenticeshipVacancies = _apprenticeshipVacanciesProvider.GetAllVacancyIds(request.ApprenticeshipVacancyIndexName).ToList(); var traineeshipVacancies = _traineeshipVacanciesProvider.GetAllVacancyIds(request.TraineeshipVacancyIndexName).ToList(); var siteMapVacancies = new List <SiteMapVacancy>(); var lastModifiedDate = DateTime.UtcNow; siteMapVacancies.AddRange( apprenticeshipVacancies.Select(vacancyId => new SiteMapVacancy { VacancyId = vacancyId, VacancyType = VacancyType.Apprenticeship, LastModifiedDate = lastModifiedDate }) .Union( traineeshipVacancies.Select(vacancyId => new SiteMapVacancy { VacancyId = vacancyId, VacancyType = VacancyType.Traineeship, LastModifiedDate = lastModifiedDate }))); _logger.Info("Caching {0} apprenticeship + {1} traineeship vacancies", apprenticeshipVacancies.Count(), traineeshipVacancies.Count()); _siteMapVacancyProvider.SetVacancies(siteMapVacancies); _logger.Info("Created site map based on apprenticeship and traineeship indexes '{0}' and '{1}' respectively", request.ApprenticeshipVacancyIndexName, request.TraineeshipVacancyIndexName); }