public void Setup()
        {
            _publishedProviderId          = NewRandomString();
            _publishedProviderIds         = new[] { _publishedProviderId };
            _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>();
            _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));
            _mapper = Substitute.For <IMapper>();
            _publishedFundingDataService           = Substitute.For <IPublishedFundingDataService>();
            _policiesService                       = Substitute.For <IPoliciesService>();
            _organisationGroupGenerator            = Substitute.For <IOrganisationGroupGenerator>();
            _publishedFundingChangeDetectorService = Substitute.For <IPublishedFundingChangeDetectorService>();
            _publishedFundingDateService           = Substitute.For <IPublishedFundingDateService>();
            _publishedFundingDataService           = Substitute.For <IPublishedFundingDataService>();
            _publishedFundingVersionDataService    = Substitute.For <IPublishedFundingVersionDataService>();

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

            _publishIntegrityService = new PublishIntegrityCheckService(_jobManagement,
                                                                        _logger,
                                                                        _specificationService,
                                                                        _providerService,
                                                                        _publishedFundingContentsPersistanceService,
                                                                        _publishedProviderContentsPersistanceService,
                                                                        _publishingResiliencePolicies,
                                                                        _publishedFundingDataService,
                                                                        _policiesService,
                                                                        _calculationsApiClient,
                                                                        _publishedFundingService,
                                                                        _publishedProviderContentsGeneratorResolver,
                                                                        _publishedFundingVersionDataService
                                                                        );
        }
        public async Task OnGet_WhenCalculationExistdCalculationTypeIsFundingAndShouldNewEditCalculationPageBeEnabledIsTurnedOnAndResultFound_ThenCalculationDisplayTypeIsFundingSetsHasCalculationResultToTrue()
        {
            // Arrange
            ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>();
            ISpecsApiClient        specsClient = Substitute.For <ISpecsApiClient>();

            IMapper        mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle featureToggle = CreateFeatureToggle();

            featureToggle
            .IsNewEditCalculationPageEnabled()
            .Returns(true);

            string calculationId = "5";

            Calculation calcsCalculation = new Calculation()
            {
                Id = calculationId,
                CalculationSpecification = new Reference(calculationId, "Test Calculation Specification"),
                SpecificationId          = "54",
                SourceCode      = "Test Source Code",
                CalculationType = Clients.SpecsClient.Models.CalculationSpecificationType.Funding
            };

            Clients.SpecsClient.Models.CalculationCurrentVersion specsCalculation = new Clients.SpecsClient.Models.CalculationCurrentVersion()
            {
                Id          = calculationId,
                Name        = "Specs Calculation",
                Description = "Spec Description",
            };

            calcsClient
            .GetCalculationById(calculationId)
            .Returns(new ApiResponse <Calculation>(System.Net.HttpStatusCode.OK, calcsCalculation));

            specsClient
            .GetCalculationById(calcsCalculation.SpecificationId, calculationId)
            .Returns(new ApiResponse <Clients.SpecsClient.Models.CalculationCurrentVersion>(System.Net.HttpStatusCode.OK, specsCalculation));

            ApiResponse <bool> hasCalcsResponse = new ApiResponse <bool>(HttpStatusCode.OK, true);

            IResultsApiClient resultsApiClient = CreateResultsApiClient();

            resultsApiClient
            .HasCalculationResults(Arg.Is(calcsCalculation.Id))
            .Returns(hasCalcsResponse);

            EditCalculationPageModel pageModel = CreatePageModel(specsClient: specsClient, calcsClient: calcsClient, mapper: mapper, features: featureToggle, resultsApiClient: resultsApiClient);

            // Act
            IActionResult result = await pageModel.OnGet(calculationId);

            // Assert
            result.Should().NotBeNull();
            result.Should().BeOfType <PageResult>();

            pageModel.Calculation.Should().NotBeNull();
            pageModel.Calculation.Name.Should().Be(calcsCalculation.Name);
            pageModel.Calculation.Description.Should().Be(specsCalculation.Description);
            pageModel.SpecificationId.Should().Be(calcsCalculation.SpecificationId);
            pageModel.EditModel.SourceCode.Should().Be(calcsCalculation.SourceCode);
            pageModel.Calculation.CalculationType.Should().Be(CalculationSpecificationTypeViewModel.Funding);
            pageModel.CalculationHasResults.Should().BeTrue();

            string shouldShowGreyBackground = pageModel.ViewData["GreyBackground"].ToString();

            shouldShowGreyBackground
            .Should()
            .Be("True");
        }
Exemple #3
0
        public RefreshService(IPublishedProviderStatusUpdateService publishedProviderStatusUpdateService,
                              IPublishedFundingDataService publishedFundingDataService,
                              IPublishingResiliencePolicies publishingResiliencePolicies,
                              ISpecificationService specificationService,
                              IProviderService providerService,
                              ICalculationResultsService calculationResultsService,
                              IPublishedProviderDataGenerator publishedProviderDataGenerator,
                              IPublishedProviderDataPopulator publishedProviderDataPopulator,
                              ILogger logger,
                              ICalculationsApiClient calculationsApiClient,
                              IPrerequisiteCheckerLocator prerequisiteCheckerLocator,
                              IPublishProviderExclusionCheck providerExclusionCheck,
                              IFundingLineValueOverride fundingLineValueOverride,
                              IJobManagement jobManagement,
                              IPublishedProviderIndexerService publishedProviderIndexerService,
                              IVariationService variationService,
                              ITransactionFactory transactionFactory,
                              IPublishedProviderVersionService publishedProviderVersionService,
                              IPoliciesService policiesService,
                              IGeneratePublishedFundingCsvJobsCreationLocator generateCsvJobsLocator,
                              IReApplyCustomProfiles reApplyCustomProfiles,
                              IPublishingEngineOptions publishingEngineOptions,
                              IPublishedProviderErrorDetection detection,
                              IBatchProfilingService batchProfilingService) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(generateCsvJobsLocator, nameof(generateCsvJobsLocator));
            Guard.ArgumentNotNull(publishedProviderStatusUpdateService, nameof(publishedProviderStatusUpdateService));
            Guard.ArgumentNotNull(publishedFundingDataService, nameof(publishedFundingDataService));
            Guard.ArgumentNotNull(publishingResiliencePolicies, nameof(publishingResiliencePolicies));
            Guard.ArgumentNotNull(specificationService, nameof(specificationService));
            Guard.ArgumentNotNull(providerService, nameof(providerService));
            Guard.ArgumentNotNull(calculationResultsService, nameof(calculationResultsService));
            Guard.ArgumentNotNull(publishedProviderDataGenerator, nameof(publishedProviderDataGenerator));
            Guard.ArgumentNotNull(publishedProviderDataPopulator, nameof(publishedProviderDataPopulator));
            Guard.ArgumentNotNull(calculationsApiClient, nameof(calculationsApiClient));
            Guard.ArgumentNotNull(providerExclusionCheck, nameof(providerExclusionCheck));
            Guard.ArgumentNotNull(fundingLineValueOverride, nameof(fundingLineValueOverride));
            Guard.ArgumentNotNull(jobManagement, nameof(jobManagement));
            Guard.ArgumentNotNull(publishedProviderIndexerService, nameof(publishedProviderIndexerService));
            Guard.ArgumentNotNull(variationService, nameof(variationService));
            Guard.ArgumentNotNull(transactionFactory, nameof(transactionFactory));
            Guard.ArgumentNotNull(publishedProviderVersionService, nameof(publishedProviderVersionService));
            Guard.ArgumentNotNull(policiesService, nameof(policiesService));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(prerequisiteCheckerLocator, nameof(prerequisiteCheckerLocator));
            Guard.ArgumentNotNull(reApplyCustomProfiles, nameof(reApplyCustomProfiles));
            Guard.ArgumentNotNull(detection, nameof(detection));
            Guard.ArgumentNotNull(publishingResiliencePolicies.CalculationsApiClient, nameof(publishingResiliencePolicies.CalculationsApiClient));
            Guard.ArgumentNotNull(publishingResiliencePolicies.PublishedFundingRepository, nameof(publishingResiliencePolicies.PublishedFundingRepository));
            Guard.ArgumentNotNull(publishingEngineOptions, nameof(publishingEngineOptions));
            Guard.ArgumentNotNull(batchProfilingService, nameof(batchProfilingService));

            _publishedProviderStatusUpdateService = publishedProviderStatusUpdateService;
            _publishedFundingDataService          = publishedFundingDataService;
            _specificationService           = specificationService;
            _providerService                = providerService;
            _calculationResultsService      = calculationResultsService;
            _publishedProviderDataGenerator = publishedProviderDataGenerator;
            _publishedProviderDataPopulator = publishedProviderDataPopulator;
            _logger = logger;
            _calculationsApiClient      = calculationsApiClient;
            _prerequisiteCheckerLocator = prerequisiteCheckerLocator;
            _providerExclusionCheck     = providerExclusionCheck;
            _fundingLineValueOverride   = fundingLineValueOverride;
            _variationService           = variationService;
            _generateCsvJobsLocator     = generateCsvJobsLocator;
            _reApplyCustomProfiles      = reApplyCustomProfiles;
            _detection                       = detection;
            _batchProfilingService           = batchProfilingService;
            _publishedProviderIndexerService = publishedProviderIndexerService;

            _publishingResiliencePolicy  = publishingResiliencePolicies.PublishedFundingRepository;
            _calculationsApiClientPolicy = publishingResiliencePolicies.CalculationsApiClient;
            _jobManagement      = jobManagement;
            _transactionFactory = transactionFactory;
            _publishedProviderVersionService = publishedProviderVersionService;
            _policiesService         = policiesService;
            _publishingEngineOptions = publishingEngineOptions;
        }
Exemple #4
0
        public async Task PerformSearch_FirstSearchResultWithFacets_EnsuresFacetsLoadedCorrectly()
        {
            // Arrange
            ICalculationsApiClient calcsClient = Substitute.For <ICalculationsApiClient>();
            ILogger        logger        = Substitute.For <ILogger>();
            IMapper        mapper        = MappingHelper.CreateFrontEndMapper();
            IFeatureToggle featureToggle = CreateFeatureToggle();

            ICalculationSearchService calculationSearchService = new CalculationSearchService(calcsClient, mapper, logger, featureToggle);

            int numberOfItems = 25;

            IEnumerable <SearchFacet> facets = new[]
            {
                new SearchFacet
                {
                    Name        = "facet 1",
                    FacetValues = new[]
                    {
                        new SearchFacetValue {
                            Name = "f1", Count = 5
                        }
                    }
                },
                new SearchFacet
                {
                    Name        = "facet 2",
                    FacetValues = new[]
                    {
                        new SearchFacetValue {
                            Name = "f2", Count = 11
                        },
                        new SearchFacetValue {
                            Name = "f3", Count = 1
                        }
                    }
                }
            };

            PagedResult <CalculationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems, facets);

            calcsClient
            .FindCalculations(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            CalculationSearchResultViewModel results = await calculationSearchService.PerformSearch(request);

            // Assert
            CalculationSearchResultItemViewModel first = results.Calculations.First();

            first.Should().NotBeNull();
            first.Id.Should().Be("10");
            first.SpecificationName.Should().Be("Spec Name");
            first.Status.Should().Be("Unknown");
            first.FundingPeriodName.Should().Be("Test Period");
            first.Name.Should().Be("Calculation 1");

            results.Facets.Count().Should().Be(2);
            results.Facets.First().Name.Should().Be("facet 1");
            results.Facets.First().FacetValues.Count().Should().Be(1);
            results.Facets.First().FacetValues.First().Name.Should().Be("f1");
            results.Facets.First().FacetValues.First().Count.Should().Be(5);
            results.Facets.Last().Name.Should().Be("facet 2");
            results.Facets.Last().FacetValues.Count().Should().Be(2);
            results.Facets.Last().FacetValues.First().Name.Should().Be("f2");
            results.Facets.Last().FacetValues.First().Count.Should().Be(11);
            results.Facets.Last().FacetValues.Last().Name.Should().Be("f3");
            results.Facets.Last().FacetValues.Last().Count.Should().Be(1);
        }
        public CalcsRepository(ICalculationsApiClient apiClient)
        {
            Guard.ArgumentNotNull(apiClient, nameof(apiClient));

            _apiClient = apiClient;
        }
Exemple #6
0
        public SpecGenerator(ISpecsApiClient specsApiClient, IDatasetsApiClient datasetsApiClient, ICalculationsApiClient calcsApiClient, ILogger logger)
        {
            Guard.ArgumentNotNull(specsApiClient, nameof(specsApiClient));
            Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient));
            Guard.ArgumentNotNull(calcsApiClient, nameof(calcsApiClient));
            Guard.ArgumentNotNull(logger, nameof(logger));

            _specsClient    = specsApiClient;
            _datasetsClient = datasetsApiClient;
            _calcsClient    = calcsApiClient;
            _logger         = logger;
        }
        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;
        }