public PublishIntegrityCheckService(IJobManagement jobManagement,
                                            ILogger logger,
                                            ISpecificationService specificationService,
                                            IProviderService providerService,
                                            IPublishedFundingContentsPersistanceService publishedFundingContentsPersistanceService,
                                            IPublishedProviderContentPersistanceService publishedProviderContentsPersistanceService,
                                            IPublishingResiliencePolicies publishingResiliencePolicies,
                                            IPublishedFundingDataService publishedFundingDataService,
                                            IPoliciesService policiesService,
                                            ICalculationsApiClient calculationsApiClient,
                                            IPublishedFundingService publishedFundingService,
                                            IPublishedProviderContentsGeneratorResolver publishedProviderContentsGeneratorResolver,
                                            IPublishedFundingVersionDataService publishedFundingVersionDataService) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(specificationService, nameof(specificationService));
            Guard.ArgumentNotNull(publishedFundingContentsPersistanceService, nameof(publishedFundingContentsPersistanceService));
            Guard.ArgumentNotNull(publishedProviderContentsPersistanceService, nameof(publishedProviderContentsPersistanceService));
            Guard.ArgumentNotNull(providerService, nameof(providerService));
            Guard.ArgumentNotNull(publishedFundingDataService, nameof(publishedFundingDataService));
            Guard.ArgumentNotNull(publishingResiliencePolicies.PublishedFundingRepository, nameof(publishingResiliencePolicies.PublishedFundingRepository));
            Guard.ArgumentNotNull(policiesService, nameof(policiesService));
            Guard.ArgumentNotNull(calculationsApiClient, nameof(calculationsApiClient));
            Guard.ArgumentNotNull(publishingResiliencePolicies.CalculationsApiClient, nameof(publishingResiliencePolicies.CalculationsApiClient));
            Guard.ArgumentNotNull(publishedFundingService, nameof(publishedFundingService));
            Guard.ArgumentNotNull(publishedProviderContentsGeneratorResolver, nameof(publishedProviderContentsGeneratorResolver));
            Guard.ArgumentNotNull(publishedFundingVersionDataService, nameof(publishedFundingVersionDataService));

            _logger = logger;
            _calculationsApiClient       = calculationsApiClient;
            _calculationsApiClientPolicy = publishingResiliencePolicies.CalculationsApiClient;
            _specificationService        = specificationService;
            _publishedFundingContentsPersistanceService  = publishedFundingContentsPersistanceService;
            _publishedProviderContentsPersistanceService = publishedProviderContentsPersistanceService;
            _providerService             = providerService;
            _publishedFundingDataService = publishedFundingDataService;
            _publishingResiliencePolicy  = publishingResiliencePolicies.PublishedFundingRepository;
            _policiesService             = policiesService;
            _publishedProviderContentsGeneratorResolver = publishedProviderContentsGeneratorResolver;
            _publishedFundingVersionDataService         = publishedFundingVersionDataService;
        }
        public void Setup()
        {
            _publishedProviderId  = NewRandomString();
            _publishedProviderIds = new[] { _publishedProviderId };

            _publishedFundingStatusUpdateService = Substitute.For <IPublishedFundingStatusUpdateService>();
            _publishingResiliencePolicies        = new ResiliencePolicies
            {
                PublishedFundingRepository           = Policy.NoOpAsync(),
                CalculationsApiClient                = Policy.NoOpAsync(),
                SpecificationsApiClient              = Policy.NoOpAsync(),
                SpecificationsRepositoryPolicy       = Policy.NoOpAsync(),
                PublishedIndexSearchResiliencePolicy = Policy.NoOpAsync()
            };
            _specificationsApiClient           = Substitute.For <ISpecificationsApiClient>();
            _specificationService              = new SpecificationService(_specificationsApiClient, _publishingResiliencePolicies);
            _specificationFundingStatusService = Substitute.For <ISpecificationFundingStatusService>();
            _jobsRunning = Substitute.For <IJobsRunning>();
            _logger      = Substitute.For <ILogger>();
            _publishedFundingChangeDetectorService       = Substitute.For <IPublishedFundingChangeDetectorService>();
            _publishedFundingGenerator                   = Substitute.For <IPublishedFundingGenerator>();
            _publishedProviderContentsGeneratorResolver  = Substitute.For <IPublishedProviderContentsGeneratorResolver>();
            _publishedFundingContentsPersistanceService  = Substitute.For <IPublishedFundingContentsPersistanceService>();
            _publishedProviderContentsPersistanceService = Substitute.For <IPublishedProviderContentPersistanceService>();
            _publishedProviderStatusUpdateService        = Substitute.For <IPublishedProviderStatusUpdateService>();
            _publishedFundingSearchRepository            = Substitute.For <ISearchRepository <PublishedFundingIndex> >();
            _calculationsApiClient      = Substitute.For <ICalculationsApiClient>();
            _providerService            = Substitute.For <IProviderService>();
            _jobManagement              = Substitute.For <IJobManagement>();
            _prerequisiteCheckerLocator = Substitute.For <IPrerequisiteCheckerLocator>();
            _prerequisiteCheckerLocator.GetPreReqChecker(PrerequisiteCheckerType.ReleaseAllProviders)
            .Returns(new PublishAllPrerequisiteChecker(_specificationFundingStatusService, _jobsRunning, _jobManagement, _logger));
            _prerequisiteCheckerLocator.GetPreReqChecker(PrerequisiteCheckerType.ReleaseBatchProviders)
            .Returns(new PublishBatchPrerequisiteChecker(_specificationFundingStatusService, _jobsRunning, _jobManagement, _logger));
            _generateCsvJobsLocator = Substitute.For <IGeneratePublishedFundingCsvJobsCreationLocator>();
            _mapper             = Substitute.For <IMapper>();
            _transactionFactory = new TransactionFactory(_logger, new TransactionResiliencePolicies {
                TransactionPolicy = Policy.NoOpAsync()
            });
            _publishedProviderVersionService = Substitute.For <IPublishedProviderVersionService>();
            _publishedFundingDataService     = Substitute.For <IPublishedFundingDataService>();
            _policiesService                       = Substitute.For <IPoliciesService>();
            _organisationGroupGenerator            = Substitute.For <IOrganisationGroupGenerator>();
            _publishedFundingChangeDetectorService = Substitute.For <IPublishedFundingChangeDetectorService>();
            _publishedFundingDateService           = Substitute.For <IPublishedFundingDateService>();
            _publishedFundingDataService           = Substitute.For <IPublishedFundingDataService>();
            _createPublishIntegrityJob             = Substitute.For <ICreatePublishIntegrityJob>();

            _publishedFundingService = new PublishedFundingService(_publishedFundingDataService,
                                                                   _publishingResiliencePolicies,
                                                                   _policiesService,
                                                                   _organisationGroupGenerator,
                                                                   _publishedFundingChangeDetectorService,
                                                                   _publishedFundingDateService,
                                                                   _mapper,
                                                                   _logger);

            _publishService = new PublishService(_publishedFundingStatusUpdateService,
                                                 _publishingResiliencePolicies,
                                                 _specificationService,
                                                 _prerequisiteCheckerLocator,
                                                 _publishedFundingChangeDetectorService,
                                                 _publishedFundingGenerator,
                                                 _publishedProviderContentsGeneratorResolver,
                                                 _publishedFundingContentsPersistanceService,
                                                 _publishedProviderContentsPersistanceService,
                                                 _publishedProviderStatusUpdateService,
                                                 _providerService,
                                                 _publishedFundingSearchRepository,
                                                 _calculationsApiClient,
                                                 _logger,
                                                 _jobManagement,
                                                 _generateCsvJobsLocator,
                                                 _transactionFactory,
                                                 _publishedProviderVersionService,
                                                 _publishedFundingService,
                                                 _publishedFundingDataService,
                                                 _policiesService,
                                                 _createPublishIntegrityJob
                                                 );
        }
        public PublishService(IPublishedFundingStatusUpdateService publishedFundingStatusUpdateService,
                              IPublishingResiliencePolicies publishingResiliencePolicies,
                              ISpecificationService specificationService,
                              IPrerequisiteCheckerLocator prerequisiteCheckerLocator,
                              IPublishedFundingChangeDetectorService publishedFundingChangeDetectorService,
                              IPublishedFundingGenerator publishedFundingGenerator,
                              IPublishedProviderContentsGeneratorResolver publishedProviderContentsGeneratorResolver,
                              IPublishedFundingContentsPersistanceService publishedFundingContentsPersistanceService,
                              IPublishedProviderContentPersistanceService publishedProviderContentsPersistanceService,
                              IPublishedProviderStatusUpdateService publishedProviderStatusUpdateService,
                              IProviderService providerService,
                              ISearchRepository <PublishedFundingIndex> publishedFundingSearchRepository,
                              ICalculationsApiClient calculationsApiClient,
                              ILogger logger,
                              IJobManagement jobManagement,
                              IGeneratePublishedFundingCsvJobsCreationLocator generateCsvJobsLocator,
                              ITransactionFactory transactionFactory,
                              IPublishedProviderVersionService publishedProviderVersionService,
                              IPublishedFundingService publishedFundingService,
                              IPublishedFundingDataService publishedFundingDataService,
                              IPoliciesService policiesService,
                              ICreatePublishIntegrityJob createPublishIntegrityJob) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(generateCsvJobsLocator, nameof(generateCsvJobsLocator));
            Guard.ArgumentNotNull(publishedFundingStatusUpdateService, nameof(publishedFundingStatusUpdateService));
            Guard.ArgumentNotNull(publishingResiliencePolicies, nameof(publishingResiliencePolicies));
            Guard.ArgumentNotNull(specificationService, nameof(specificationService));
            Guard.ArgumentNotNull(prerequisiteCheckerLocator, nameof(prerequisiteCheckerLocator));
            Guard.ArgumentNotNull(publishedFundingChangeDetectorService, nameof(publishedFundingChangeDetectorService));
            Guard.ArgumentNotNull(publishedFundingGenerator, nameof(publishedFundingGenerator));
            Guard.ArgumentNotNull(publishedFundingGenerator, nameof(publishedProviderContentsGeneratorResolver));
            Guard.ArgumentNotNull(publishedFundingContentsPersistanceService, nameof(publishedFundingContentsPersistanceService));
            Guard.ArgumentNotNull(publishedProviderContentsPersistanceService, nameof(publishedProviderContentsPersistanceService));
            Guard.ArgumentNotNull(publishedProviderStatusUpdateService, nameof(publishedProviderStatusUpdateService));
            Guard.ArgumentNotNull(publishedFundingSearchRepository, nameof(publishedFundingSearchRepository));
            Guard.ArgumentNotNull(providerService, nameof(providerService));
            Guard.ArgumentNotNull(publishedFundingService, nameof(publishedFundingService));
            Guard.ArgumentNotNull(calculationsApiClient, nameof(calculationsApiClient));
            Guard.ArgumentNotNull(publishingResiliencePolicies.CalculationsApiClient, nameof(publishingResiliencePolicies.CalculationsApiClient));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(jobManagement, nameof(jobManagement));
            Guard.ArgumentNotNull(publishingResiliencePolicies.PublishedIndexSearchResiliencePolicy, nameof(publishingResiliencePolicies.PublishedIndexSearchResiliencePolicy));
            Guard.ArgumentNotNull(transactionFactory, nameof(transactionFactory));
            Guard.ArgumentNotNull(publishedProviderVersionService, nameof(publishedProviderVersionService));
            Guard.ArgumentNotNull(publishedFundingDataService, nameof(publishedFundingDataService));
            Guard.ArgumentNotNull(policiesService, nameof(policiesService));
            Guard.ArgumentNotNull(createPublishIntegrityJob, nameof(createPublishIntegrityJob));

            _publishedFundingStatusUpdateService = publishedFundingStatusUpdateService;
            _publishedFundingDataService         = publishedFundingDataService;
            _specificationService       = specificationService;
            _prerequisiteCheckerLocator = prerequisiteCheckerLocator;
            _publishedFundingGenerator  = publishedFundingGenerator;
            _publishedProviderContentsGeneratorResolver  = publishedProviderContentsGeneratorResolver;
            _publishedFundingContentsPersistanceService  = publishedFundingContentsPersistanceService;
            _publishedProviderContentsPersistanceService = publishedProviderContentsPersistanceService;
            _publishedProviderStatusUpdateService        = publishedProviderStatusUpdateService;
            _publishedFundingSearchRepository            = publishedFundingSearchRepository;
            _logger = logger;
            _calculationsApiClient       = calculationsApiClient;
            _calculationsApiClientPolicy = publishingResiliencePolicies.CalculationsApiClient;
            _generateCsvJobsLocator      = generateCsvJobsLocator;
            _jobManagement = jobManagement;
            _publishedIndexSearchResiliencePolicy = publishingResiliencePolicies.PublishedIndexSearchResiliencePolicy;
            _transactionFactory = transactionFactory;
            _publishedProviderVersionService = publishedProviderVersionService;
            _providerService           = providerService;
            _publishedFundingService   = publishedFundingService;
            _policiesService           = policiesService;
            _createPublishIntegrityJob = createPublishIntegrityJob;
        }