Ejemplo n.º 1
0
        public SpecificationCalculationAnalysis(ICalcsResiliencePolicies policies,
                                                ISpecificationsApiClient specifications,
                                                ICalculationsRepository calculations,
                                                ICalculationAnalysis calculationAnalysis,
                                                IBuildProjectsService buildProjectsService,
                                                IDatasetReferenceService datasetReferenceService,
                                                IMapper mapper)
        {
            Guard.ArgumentNotNull(policies?.CalculationsRepository, nameof(policies.CalculationsRepository));
            Guard.ArgumentNotNull(policies?.SpecificationsApiClient, nameof(policies.SpecificationsApiClient));
            Guard.ArgumentNotNull(specifications, nameof(specifications));
            Guard.ArgumentNotNull(calculations, nameof(calculations));
            Guard.ArgumentNotNull(calculationAnalysis, nameof(calculationAnalysis));
            Guard.ArgumentNotNull(buildProjectsService, nameof(buildProjectsService));
            Guard.ArgumentNotNull(datasetReferenceService, nameof(datasetReferenceService));
            Guard.ArgumentNotNull(mapper, nameof(mapper));

            _specificationsResilience = policies.SpecificationsApiClient;
            _calculationsResilience   = policies.CalculationsRepository;
            _specifications           = specifications;
            _calculations             = calculations;
            _calculationAnalysis      = calculationAnalysis;
            _buildProjectsService     = buildProjectsService;
            _datasetReferenceService  = datasetReferenceService;
            _mapper = mapper;
        }
Ejemplo n.º 2
0
        public ApproveAllCalculationsService(
            ICalculationsRepository calculationsRepository,
            ICalcsResiliencePolicies resiliencePolicies,
            ISpecificationsApiClient specificationsApiClient,
            IResultsApiClient resultsApiClient,
            ISearchRepository <CalculationIndex> searchRepository,
            ICacheProvider cacheProvider,
            ILogger logger,
            IJobManagement jobManagement) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(resultsApiClient, nameof(resultsApiClient));
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(searchRepository, nameof(searchRepository));
            Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient));
            Guard.ArgumentNotNull(resiliencePolicies?.CacheProviderPolicy, nameof(resiliencePolicies.CacheProviderPolicy));
            Guard.ArgumentNotNull(resiliencePolicies?.ResultsApiClient, nameof(resiliencePolicies.ResultsApiClient));
            Guard.ArgumentNotNull(resiliencePolicies?.CalculationsRepository, nameof(resiliencePolicies.CalculationsRepository));
            Guard.ArgumentNotNull(logger, nameof(logger));

            _calculationsRepository = calculationsRepository;
            _logger = logger;
            _calculationRepositoryPolicy   = resiliencePolicies.CalculationsRepository;
            _specificationsApiClient       = specificationsApiClient;
            _specificationsApiClientPolicy = resiliencePolicies.SpecificationsApiClient;
            _resultsApiClient       = resultsApiClient;
            _resultsApiClientPolicy = resiliencePolicies.ResultsApiClient;
            _searchRepository       = searchRepository;
            _cacheProvider          = cacheProvider;
            _cachePolicy            = resiliencePolicies.CacheProviderPolicy;
        }
Ejemplo n.º 3
0
        public async Task IsCalculationNameValid_WhenCalculationDoesNotExist_ThenReturnsOkResult()
        {
            // Arrange
            string specificationId = "spec1";

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(specificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, new SpecModel.SpecificationSummary {
                Id = specificationId
            }));

            ICalculationsRepository calculationsRepository = CreateCalculationsRepository();

            calculationsRepository
            .GetCalculationsBySpecificationId(Arg.Is(specificationId))
            .Returns(new List <Calculation>());

            CalculationService service = CreateCalculationService(specificationsApiClient: specificationsApiClient, calculationsRepository: calculationsRepository);

            // Act
            IActionResult result = await service.IsCalculationNameValid(specificationId, "calc1", null);

            // Assert
            result
            .Should()
            .BeOfType <OkResult>();
        }
        public ProviderVariationsApplication(IPublishingResiliencePolicies resiliencePolicies,
                                             ISpecificationsApiClient specificationsApiClient,
                                             IPoliciesApiClient policiesApiClient,
                                             ICacheProvider cacheProvider,
                                             IProfilingApiClient profilingApiClient,
                                             IReProfilingRequestBuilder reProfilingRequestBuilder,
                                             IReProfilingResponseMapper reProfilingResponseMapper)
        {
            Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies));
            Guard.ArgumentNotNull(resiliencePolicies.SpecificationsApiClient, "resiliencePolicies.SpecificationsApiClient");
            Guard.ArgumentNotNull(resiliencePolicies.PoliciesApiClient, "resiliencePolicies.PoliciesApiClient");
            Guard.ArgumentNotNull(resiliencePolicies.CacheProvider, "resiliencePolicies.CacheProvider");
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient));
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(profilingApiClient, nameof(profilingApiClient));
            Guard.ArgumentNotNull(reProfilingRequestBuilder, nameof(reProfilingRequestBuilder));
            Guard.ArgumentNotNull(reProfilingResponseMapper, nameof(reProfilingResponseMapper));

            SpecificationsApiClient   = specificationsApiClient;
            ResiliencePolicies        = resiliencePolicies;
            PoliciesApiClient         = policiesApiClient;
            CacheProvider             = cacheProvider;
            ProfilingApiClient        = profilingApiClient;
            ReProfilingRequestBuilder = reProfilingRequestBuilder;
            ReProfilingResponseMapper = reProfilingResponseMapper;
        }
        public SpecificationPublishingService(
            ISpecificationIdServiceRequestValidator specificationIdValidator,
            IPublishedProviderIdsServiceRequestValidator publishedProviderIdsValidator,
            IProviderService providerService,
            ISpecificationsApiClient specifications,
            IPublishingResiliencePolicies resiliencePolicies,
            ICacheProvider cacheProvider,
            ICreateRefreshFundingJobs refreshFundingJobs,
            ICreateApproveAllFundingJobs approveSpecificationFundingJobs,
            ICreateApproveBatchFundingJobs approveProviderFundingJobs,
            ISpecificationFundingStatusService specificationFundingStatusService,
            IFundingConfigurationService fundingConfigurationService,
            IPrerequisiteCheckerLocator prerequisiteCheckerLocator,
            IPublishedFundingRepository publishedFundingRepository)
            : base(specificationIdValidator, publishedProviderIdsValidator, specifications, resiliencePolicies, fundingConfigurationService)
        {
            Guard.ArgumentNotNull(refreshFundingJobs, nameof(refreshFundingJobs));
            Guard.ArgumentNotNull(approveSpecificationFundingJobs, nameof(approveSpecificationFundingJobs));
            Guard.ArgumentNotNull(approveProviderFundingJobs, nameof(approveProviderFundingJobs));
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(specificationFundingStatusService, nameof(specificationFundingStatusService));
            Guard.ArgumentNotNull(prerequisiteCheckerLocator, nameof(prerequisiteCheckerLocator));
            Guard.ArgumentNotNull(providerService, nameof(providerService));
            Guard.ArgumentNotNull(publishedFundingRepository, nameof(publishedFundingRepository));
            Guard.ArgumentNotNull(resiliencePolicies?.PublishedFundingRepository, "resiliencePolicies.PublishedFundingRepository");

            _refreshFundingJobs = refreshFundingJobs;
            _cacheProvider      = cacheProvider;
            _approveSpecificationFundingJobs   = approveSpecificationFundingJobs;
            _approveProviderFundingJobs        = approveProviderFundingJobs;
            _specificationFundingStatusService = specificationFundingStatusService;
            _prerequisiteCheckerLocator        = prerequisiteCheckerLocator;
            _publishedFundingRepository        = publishedFundingRepository;
            _providerService = providerService;
        }
Ejemplo n.º 6
0
        public DefinitionSpecificationRelationshipService(IDatasetRepository datasetRepository,
                                                          ILogger logger,
                                                          ISpecificationsApiClient specificationsApiClient,
                                                          IValidator <CreateDefinitionSpecificationRelationshipModel> relationshipModelValidator,
                                                          IMessengerService messengerService,
                                                          ICalcsRepository calcsRepository,
                                                          ICacheProvider cacheProvider,
                                                          IDatasetsResiliencePolicies datasetsResiliencePolicies,
                                                          IJobManagement jobManagement,
                                                          IDateTimeProvider dateTimeProvider)
        {
            Guard.ArgumentNotNull(dateTimeProvider, nameof(dateTimeProvider));
            Guard.ArgumentNotNull(datasetRepository, nameof(datasetRepository));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(relationshipModelValidator, nameof(relationshipModelValidator));
            Guard.ArgumentNotNull(messengerService, nameof(messengerService));
            Guard.ArgumentNotNull(calcsRepository, nameof(calcsRepository));
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(jobManagement, nameof(jobManagement));
            Guard.ArgumentNotNull(datasetsResiliencePolicies?.SpecificationsApiClient, nameof(datasetsResiliencePolicies.SpecificationsApiClient));

            _datasetRepository             = datasetRepository;
            _logger                        = logger;
            _specificationsApiClient       = specificationsApiClient;
            _relationshipModelValidator    = relationshipModelValidator;
            _messengerService              = messengerService;
            _calcsRepository               = calcsRepository;
            _cacheProvider                 = cacheProvider;
            _jobManagement                 = jobManagement;
            _dateTimeProvider              = dateTimeProvider;
            _specificationsApiClientPolicy = datasetsResiliencePolicies.SpecificationsApiClient;

            _typeIdentifierGenerator = new VisualBasicTypeIdentifierGenerator();
        }
        public QaSchemaService(IPoliciesApiClient policies,
                               ISpecificationsApiClient specificationsApiClient,
                               ITemplateMetadataResolver templateMetadataResolver,
                               ISqlSchemaGenerator schemaGenerator,
                               IQaRepository qaRepository,
                               IProfilingApiClient profilingClient,
                               ISqlNameGenerator sqlNames,
                               IPublishingResiliencePolicies resiliencePolicies)
        {
            Guard.ArgumentNotNull(policies, nameof(policies));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(templateMetadataResolver, nameof(templateMetadataResolver));
            Guard.ArgumentNotNull(schemaGenerator, nameof(schemaGenerator));
            Guard.ArgumentNotNull(qaRepository, nameof(qaRepository));
            Guard.ArgumentNotNull(profilingClient, nameof(profilingClient));
            Guard.ArgumentNotNull(sqlNames, nameof(sqlNames));

            _policies                 = policies;
            _specifications           = specificationsApiClient;
            _templateMetadataResolver = templateMetadataResolver;
            _schemaGenerator          = schemaGenerator;
            _qaRepository             = qaRepository;
            _profilingClient          = profilingClient;
            _sqlNames                 = sqlNames;
            _specificationResilience  = resiliencePolicies.SpecificationsApiClient;
            _policiesResilience       = resiliencePolicies.PoliciesApiClient;

            //TODO; extract all of the different table builders so that this can more easily tested
            //at the moment it needs a god test with too much setup to make much sense to anyone
        }
Ejemplo n.º 8
0
        public async Task CreateAdditionalCalculation_GivenCreateJobReturnsNull_ReturnsInternalServerError()
        {
            //Arrange
            CalculationCreateModel model = CreateCalculationCreateModel();

            Reference author = CreateAuthor();

            ICalculationsRepository calculationsRepository = CreateCalculationsRepository();

            calculationsRepository
            .CreateDraftCalculation(Arg.Any <Calculation>())
            .Returns(HttpStatusCode.OK);

            IVersionRepository <CalculationVersion> versionRepository = CreateCalculationVersionRepository();

            ISearchRepository <CalculationIndex> searchRepository = CreateSearchRepository();

            IJobManagement jobManagement = CreateJobManagement();

            jobManagement
            .QueueJob(Arg.Any <JobCreateModel>())
            .Returns((Job)null);

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(SpecificationId))
            .Returns(new ApiResponse <SpecificationSummary>(
                         HttpStatusCode.OK,
                         new SpecificationSummary {
                Id = SpecificationId
            }
                         ));

            ILogger logger = CreateLogger();

            CalculationService calculationService = CreateCalculationService(
                calculationsRepository: calculationsRepository,
                calculationVersionRepository: versionRepository,
                searchRepository: searchRepository,
                jobManagement: jobManagement,
                logger: logger,
                specificationsApiClient: specificationsApiClient);

            //Act
            IActionResult result = await calculationService.CreateAdditionalCalculation(SpecificationId, model, author, CorrelationId);

            //Assert
            result
            .Should()
            .BeOfType <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be($"Failed to create job of type '{JobConstants.DefinitionNames.CreateInstructAllocationJob}' on specification '{SpecificationId}'");

            logger
            .Received(1)
            .Error(Arg.Is($"Failed to create job of type '{JobConstants.DefinitionNames.CreateInstructAllocationJob}' on specification '{SpecificationId}'"));
        }
        public async Task PerformSearch_FirstSearchResultReturnedCorrectly()
        {
            // Arrange
            ISpecificationsApiClient specsClient = Substitute.For <ISpecificationsApiClient>();
            ILogger logger = Substitute.For <ILogger>();
            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            ISpecificationSearchService SpecificationSearchService = new SpecificationSearchService(specsClient, mapper, logger);

            int numberOfItems = 25;

            PagedResult <SpecificationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems);

            specsClient
            .FindSpecifications(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            SpecificationSearchResultViewModel results = await SpecificationSearchService.PerformSearch(request);

            // Assert
            SpecificationSearchResultItemViewModel first = results.Specifications.First();

            first.Should().NotBeNull();
            first.Id.Should().Be("10");
            first.Name.Should().Be("Specification 1");
            first.Status.Should().Be("Draft");
            first.FundingPeriodName.Should().Be("Test Period");
            first.IsSelectedForFunding.Should().BeTrue();
        }
        public async Task PerformSearch_StartAndEndItemsNumbersDisplayedCorrectlyOnSecondPageOfItemsWithMorePagesAvailable()
        {
            // Arrange
            ISpecificationsApiClient specsClient = Substitute.For <ISpecificationsApiClient>();
            ILogger logger = Substitute.For <ILogger>();
            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            ISpecificationSearchService SpecificationSearchService = new SpecificationSearchService(specsClient, mapper, logger);

            int numberOfItems = 50;

            PagedResult <SpecificationSearchResultItem> itemResult = GeneratePagedResult(numberOfItems);

            itemResult.PageNumber = 2;
            itemResult.PageSize   = 50;
            itemResult.TotalItems = 175;

            specsClient
            .FindSpecifications(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel()
            {
                PageNumber = 2,
            };

            // Act
            SpecificationSearchResultViewModel results = await SpecificationSearchService.PerformSearch(request);

            // Assert
            results.StartItemNumber.Should().Be(51);
            results.EndItemNumber.Should().Be(100);
        }
Ejemplo n.º 11
0
        public async Task ValidateAsync_WhenSpecificationDoesNotContainFundingStreamValidIsFalse()
        {
            //Arrange
            CalculationCreateModel model = CreateModel();

            SpecModel.SpecificationSummary specificationSummary = new SpecModel.SpecificationSummary
            {
                FundingStreams = new[] { new Reference() }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(model.SpecificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specificationSummary));

            CalculationCreateModelValidator validator = CreateValidator(specificationsApiClient: specificationsApiClient);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result.Errors
            .Should()
            .Contain(_ => _.ErrorMessage == "The funding stream id provided is not associated with the provided specification.");
        }
Ejemplo n.º 12
0
        public async Task CreateAdditionalCalculation_GivenValidationFails_ReturnsBadRequest()
        {
            //Arrange
            string correlationId = "any-id";

            CalculationCreateModel model = new CalculationCreateModel();
            Reference author             = new Reference();

            ValidationResult validationResult = new ValidationResult(new[] {
                new ValidationFailure("prop1", "oh no an error!!!")
            });

            IValidator <CalculationCreateModel> validator = CreateCalculationCreateModelValidator(validationResult);

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(SpecificationId))
            .Returns(new ApiResponse <SpecificationSummary>(
                         HttpStatusCode.OK,
                         new SpecificationSummary {
                Id = SpecificationId
            }
                         ));

            CalculationService calculationService = CreateCalculationService(calculationCreateModelValidator: validator, specificationsApiClient: specificationsApiClient);

            //Act
            IActionResult result = await calculationService.CreateAdditionalCalculation(SpecificationId, model, author, correlationId);

            //Assert
            result
            .Should()
            .BeAssignableTo <BadRequestObjectResult>();
        }
Ejemplo n.º 13
0
        public ScopedProvidersService(ICacheProvider cacheProvider,
                                      IResultsApiClient resultsApiClient,
                                      ISpecificationsApiClient specificationsApiClient,
                                      IProviderVersionService providerVersionService,
                                      IScopedProvidersServiceSettings scopedProvidersServiceSettings,
                                      IFileSystemCache fileSystemCache,
                                      IJobManagement jobManagement,
                                      IProvidersResiliencePolicies providersResiliencePolicies,
                                      ILogger logger) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(resultsApiClient, nameof(resultsApiClient));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(providerVersionService, nameof(providerVersionService));
            Guard.ArgumentNotNull(scopedProvidersServiceSettings, nameof(scopedProvidersServiceSettings));
            Guard.ArgumentNotNull(fileSystemCache, nameof(fileSystemCache));
            Guard.ArgumentNotNull(jobManagement, nameof(jobManagement));
            Guard.ArgumentNotNull(providersResiliencePolicies?.SpecificationsApiClient, nameof(providersResiliencePolicies.SpecificationsApiClient));
            Guard.ArgumentNotNull(providersResiliencePolicies?.ResultsApiClient, nameof(providersResiliencePolicies.ResultsApiClient));
            Guard.ArgumentNotNull(providersResiliencePolicies?.CacheProvider, nameof(providersResiliencePolicies.CacheProvider));
            Guard.ArgumentNotNull(logger, nameof(logger));

            _cachePolicy                    = providersResiliencePolicies.CacheProvider;
            _specificationsPolicy           = providersResiliencePolicies.SpecificationsApiClient;
            _resultsPolicy                  = providersResiliencePolicies.ResultsApiClient;
            _cacheProvider                  = cacheProvider;
            _resultsApiClient               = resultsApiClient;
            _specificationsApiClient        = specificationsApiClient;
            _providerVersionService         = providerVersionService;
            _fileSystemCache                = fileSystemCache;
            _scopedProvidersServiceSettings = scopedProvidersServiceSettings;
            _jobManagement                  = jobManagement;
            _logger = logger;
        }
        public ProviderCalculationResultsReIndexerService(
            ILogger logger,
            ISearchRepository <ProviderCalculationResultsIndex> providerCalculationResultsSearchRepository,
            ISpecificationsApiClient specificationsApiClient,
            ICalculationResultsRepository resultsRepository,
            IResultsResiliencePolicies resiliencePolicies,
            IFeatureToggle featureToggle,
            IMessengerService messengerService)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(providerCalculationResultsSearchRepository, nameof(providerCalculationResultsSearchRepository));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(resultsRepository, nameof(resultsRepository));
            Guard.ArgumentNotNull(resiliencePolicies?.ResultsRepository, nameof(resiliencePolicies.ResultsRepository));
            Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient));
            Guard.ArgumentNotNull(resiliencePolicies?.ResultsSearchRepository, nameof(resiliencePolicies.ResultsSearchRepository));
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));
            Guard.ArgumentNotNull(messengerService, nameof(messengerService));

            _logger = logger;
            _providerCalculationResultsSearchRepository = providerCalculationResultsSearchRepository;
            _specificationsApiClient       = specificationsApiClient;
            _resultsRepository             = resultsRepository;
            _resultsRepositoryPolicy       = resiliencePolicies.ResultsRepository;
            _specificationsApiClientPolicy = resiliencePolicies.SpecificationsApiClient;
            _resultsSearchRepositoryPolicy = resiliencePolicies.ResultsSearchRepository;
            _featureToggle    = featureToggle;
            _messengerService = messengerService;
        }
        public FundingStreamPermissionService(
            IUserRepository userRepository,
            ISpecificationsApiClient specificationsApiClient,
            IVersionRepository <FundingStreamPermissionVersion> fundingStreamPermissionVersionRepository,
            ICacheProvider cacheProvider,
            IMapper mapper,
            ILogger logger,
            IUsersResiliencePolicies policies)
        {
            Guard.ArgumentNotNull(userRepository, nameof(userRepository));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(fundingStreamPermissionVersionRepository, nameof(fundingStreamPermissionVersionRepository));
            Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider));
            Guard.ArgumentNotNull(mapper, nameof(mapper));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(policies?.UserRepositoryPolicy, nameof(policies.UserRepositoryPolicy));
            Guard.ArgumentNotNull(policies?.SpecificationApiClient, nameof(policies.SpecificationApiClient));
            Guard.ArgumentNotNull(policies?.FundingStreamPermissionVersionRepositoryPolicy, nameof(policies.FundingStreamPermissionVersionRepositoryPolicy));
            Guard.ArgumentNotNull(policies?.CacheProviderPolicy, nameof(policies.CacheProviderPolicy));

            _userRepository          = userRepository;
            _specificationsApiClient = specificationsApiClient;
            _fundingStreamPermissionVersionRepository = fundingStreamPermissionVersionRepository;
            _cacheProvider = cacheProvider;
            _mapper        = mapper;
            _logger        = logger;

            _userRepositoryPolicy          = policies.UserRepositoryPolicy;
            _specificationsApiClientPolicy = policies.SpecificationApiClient;
            _fundingStreamPermissionVersionRepositoryPolicy = policies.FundingStreamPermissionVersionRepositoryPolicy;
            _cacheProviderPolicy = policies.CacheProviderPolicy;
        }
        public ProviderVersionUpdateCheckService(
            IPoliciesApiClient policiesApiClient,
            ILogger logger,
            IProvidersResiliencePolicies resiliencePolicies,
            IProviderVersionsMetadataRepository providerVersionMetadata,
            IFundingDataZoneApiClient fundingDataZoneApiClient,
            ISpecificationsApiClient specificationsApiClient,
            IMapper mapper)
        {
            Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies));
            Guard.ArgumentNotNull(resiliencePolicies.PoliciesApiClient, nameof(resiliencePolicies.PoliciesApiClient));
            Guard.ArgumentNotNull(resiliencePolicies.ProviderVersionMetadataRepository, nameof(resiliencePolicies.ProviderVersionMetadataRepository));
            Guard.ArgumentNotNull(resiliencePolicies.FundingDataZoneApiClient, nameof(resiliencePolicies.FundingDataZoneApiClient));
            Guard.ArgumentNotNull(resiliencePolicies.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient));
            Guard.ArgumentNotNull(providerVersionMetadata, nameof(providerVersionMetadata));
            Guard.ArgumentNotNull(fundingDataZoneApiClient, nameof(fundingDataZoneApiClient));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(mapper, nameof(mapper));

            _policiesApiClient        = policiesApiClient;
            _providerVersionMetadata  = providerVersionMetadata;
            _fundingDataZoneApiClient = fundingDataZoneApiClient;
            _specificationsApiClient  = specificationsApiClient;
            _mapper = mapper;
            _logger = logger;
            _policiesApiClientPolicy        = resiliencePolicies.PoliciesApiClient;
            _providerVersionMetadataPolicy  = resiliencePolicies.ProviderVersionMetadataRepository;
            _fundingDataZoneApiClientPolicy = resiliencePolicies.FundingDataZoneApiClient;
            _specificationsApiClientPolicy  = resiliencePolicies.SpecificationsApiClient;
        }
        public MigrationClients(IServiceProvider services)
        {
            ServiceProviderWrapper serviceProviderWrapper = new ServiceProviderWrapper(services);

            ICalculationsEtlResiliencePolicies policies = serviceProviderWrapper.GetService <ICalculationsEtlResiliencePolicies>();

            Guard.ArgumentNotNull(policies?.CalculationsApiClient, nameof(policies.CalculationsApiClient));
            Guard.ArgumentNotNull(policies?.SpecificationApiClient, nameof(policies.SpecificationApiClient));
            Guard.ArgumentNotNull(policies?.DataSetsApiClient, nameof(policies.DataSetsApiClient));

            _calculationsPolicy   = policies.CalculationsApiClient;
            _specificationsPolicy = policies.SpecificationApiClient;
            _dataSetsPolicy       = policies.DataSetsApiClient;

            ICalculationsApiClient   calculations   = serviceProviderWrapper.GetService <ICalculationsApiClient>();
            ISpecificationsApiClient specifications = serviceProviderWrapper.GetService <ISpecificationsApiClient>();
            IDatasetsApiClient       dataSets       = serviceProviderWrapper.GetService <IDatasetsApiClient>();

            Guard.ArgumentNotNull(calculations, nameof(ICalculationsApiClient));
            Guard.ArgumentNotNull(specifications, nameof(ISpecificationsApiClient));
            Guard.ArgumentNotNull(dataSets, nameof(IDatasetsApiClient));

            _calculations   = calculations;
            _specifications = specifications;
            _dataSets       = dataSets;
        }
Ejemplo n.º 18
0
        public ProviderSnapshotDataLoadService(ILogger logger,
                                               ISpecificationsApiClient specificationsApiClient,
                                               IProviderVersionService providerVersionService,
                                               IProvidersResiliencePolicies resiliencePolicies,
                                               IFundingDataZoneApiClient fundingDataZoneApiClient,
                                               IMapper mapper,
                                               IJobManagement jobManagement) : base(jobManagement, logger)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(providerVersionService, nameof(providerVersionService));
            Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient));
            Guard.ArgumentNotNull(resiliencePolicies?.FundingDataZoneApiClient, nameof(resiliencePolicies.FundingDataZoneApiClient));
            Guard.ArgumentNotNull(fundingDataZoneApiClient, nameof(fundingDataZoneApiClient));
            Guard.ArgumentNotNull(mapper, nameof(mapper));
            Guard.ArgumentNotNull(jobManagement, nameof(jobManagement));

            _logger = logger;
            _specificationsApiClient        = specificationsApiClient;
            _providerVersionService         = providerVersionService;
            _specificationsApiClientPolicy  = resiliencePolicies.SpecificationsApiClient;
            _fundingDataZoneApiClientPolicy = resiliencePolicies.FundingDataZoneApiClient;
            _fundingDataZoneApiClient       = fundingDataZoneApiClient;
            _mapper        = mapper;
            _jobManagement = jobManagement;
        }
        public void Initialize()
        {
            _calculationEngine                = Substitute.For <ICalculationEngine>();
            _providersApiClient               = Substitute.For <IProvidersApiClient>();
            _specificationsApiClient          = Substitute.For <ISpecificationsApiClient>();
            _providerSourceDatasetsRepository = Substitute.For <IProviderSourceDatasetsRepository>();
            _calculationAggregationService    = Substitute.For <ICalculationAggregationService>();
            _calculationsRepository           = Substitute.For <ICalculationsRepository>();
            _logger = Substitute.For <ILogger>();
            _mapper = CreateMapper();

            _calculatorResiliencePolicies = new CalculatorResiliencePolicies
            {
                SpecificationsApiClient = Policy.NoOpAsync(),
                ProvidersApiClient      = Policy.NoOpAsync(),
                CalculationsApiClient   = Policy.NoOpAsync()
            };

            _calculationEnginePreviewService = new CalculationEnginePreviewService(
                _calculationEngine,
                _providersApiClient,
                _mapper,
                _calculatorResiliencePolicies,
                _specificationsApiClient,
                _providerSourceDatasetsRepository,
                _calculationAggregationService,
                _calculationsRepository,
                _logger);
        }
Ejemplo n.º 20
0
        public void Initialize()
        {
            _authorizationHelper     = Substitute.For <IAuthorizationHelper>();
            _specificationsApiClient = Substitute.For <ISpecificationsApiClient>();

            _specificationController = new SpecificationController(_specificationsApiClient, _authorizationHelper);
        }
Ejemplo n.º 21
0
        public void QueueCsvGenerationMessages_GivenNoSpecificationSummariesFound_ThrowsRetriableException()
        {
            //Arrange
            string errorMessage = "No specification summaries found to generate calculation results csv.";

            IEnumerable <SpecModel.SpecificationSummary> specificationSummaries = Enumerable.Empty <SpecModel.SpecificationSummary>();

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecModel.SpecificationSummary> >(HttpStatusCode.OK, specificationSummaries));

            ILogger logger = CreateLogger();

            ResultsService resultsService = CreateResultsService(logger, specificationsApiClient: specificationsApiClient);

            //Act
            Func <Task> test = async() => await resultsService.QueueCsvGenerationMessages();

            //Assert
            test
            .Should()
            .ThrowExactly <RetriableException>()
            .Which
            .Message
            .Should()
            .Be(errorMessage);

            logger
            .Received(1)
            .Error(errorMessage);
        }
Ejemplo n.º 22
0
        public async Task ValidateAsync_WhenSpecificationCanNotBeFound_ValidIsFalse()
        {
            //Arrange
            CalculationCreateModel model = CreateModel();

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(model.SpecificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, null));

            CalculationCreateModelValidator validator = CreateValidator(specificationsApiClient: specificationsApiClient);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result.Errors
            .Should()
            .Contain(_ => _.ErrorMessage == "Failed to find specification for provided specification id.");
        }
Ejemplo n.º 23
0
        public void TestScenarioResultsService_PerformSearch_WhenRowCountsApiCallContentIsNull_ThenExceptionThrown()
        {
            // Arrange
            IScenarioSearchService   searchService       = CreateScenarioSearchService();
            ISpecificationsApiClient specsApiClient      = CreateSpecsApiClient();
            ITestEngineApiClient     testEngineApiClient = CreateTestEngineApiClient();
            ILogger logger = CreateLogger();

            TestScenarioResultRequestViewModel resultRequestViewModel = new TestScenarioResultRequestViewModel()
            {
                SearchTerm      = "",
                PageNumber      = 1,
                FundingPeriodId = null,
                SpecificationId = null,
            };

            TestScenarioResultsService testScenarioResultsService = CreateService(searchService, specsApiClient, testEngineApiClient, logger: logger);

            searchService.PerformSearch(Arg.Any <SearchRequestViewModel>())
            .Returns(new ScenarioSearchResultViewModel()
            {
                Scenarios = new List <ScenarioSearchResultItemViewModel>()
                {
                    new ScenarioSearchResultItemViewModel()
                    {
                        Id   = "s1",
                        Name = "S1",
                    },
                    new ScenarioSearchResultItemViewModel()
                    {
                        Id   = "s2",
                        Name = "S2",
                    },
                }
            });

            List <SpecificationSummary> specifications = CreateSpecifications();

            specsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.OK, specifications));

            testEngineApiClient
            .GetTestResultCounts(Arg.Any <TestScenarioResultCountsRequestModel>())
            .Returns(new ApiResponse <IEnumerable <TestScenarioResultCounts> >(HttpStatusCode.OK, null));

            // Act
            Func <Task> action = async() => await testScenarioResultsService.PerformSearch(resultRequestViewModel);

            // Assert
            action.
            Should()
            .ThrowExactly <InvalidOperationException>()
            .WithMessage("Row counts api request failed with null content");

            logger
            .Received(1)
            .Warning(Arg.Is("Row counts api request failed with null content"));
        }
        public DatasetRelationshipsSearchService(ISpecificationsApiClient specsClient, ILogger logger)
        {
            Guard.ArgumentNotNull(specsClient, nameof(specsClient));
            Guard.ArgumentNotNull(logger, nameof(logger));

            _specsClient = specsClient;
            _logger      = logger;
        }
Ejemplo n.º 25
0
        public PublishedFundingDateService(ISpecificationsApiClient specificationsApiClient, IPublishingResiliencePolicies resiliencePolicies)
        {
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsRepositoryPolicy, nameof(resiliencePolicies.SpecificationsRepositoryPolicy));

            _specificationsApiClient = specificationsApiClient;
            _specificationsApiPolicy = resiliencePolicies.SpecificationsRepositoryPolicy;
        }
        public SpecificationController(ISpecificationsApiClient specificationsApiClient, IAuthorizationHelper authorizationHelper)
        {
            Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient));
            Guard.ArgumentNotNull(authorizationHelper, nameof(authorizationHelper));

            _specificationsApiClient = specificationsApiClient;
            _authorizationHelper     = authorizationHelper;
        }
Ejemplo n.º 27
0
        public async Task QueueCsvGenerationMessages_GivenSpecificationSummariesFoundAndHasNewResults_CreatesNewMessage()
        {
            //Arrange
            IEnumerable <SpecModel.SpecificationSummary> specificationSummaries = new[]
            {
                new SpecModel.SpecificationSummary {
                    Id = specificationId
                }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaries()
            .Returns(new ApiResponse <IEnumerable <SpecModel.SpecificationSummary> >(HttpStatusCode.OK, specificationSummaries));

            ICalculationResultsRepository calculationResultsRepository = CreateResultsRepository();

            calculationResultsRepository
            .CheckHasNewResultsForSpecificationIdAndTime(
                Arg.Is(specificationId),
                Arg.Any <DateTimeOffset>())
            .Returns(true);

            ILogger logger = CreateLogger();

            IJobManagement jobManagement = CreateJobManagement();

            IBlobClient blobClient = CreateBlobClient();

            blobClient
            .DoesBlobExistAsync($"{CalculationResultsReportFilePrefix}-{specificationId}", CalcsResultsContainerName)
            .Returns(true);

            ResultsService resultsService = CreateResultsService(
                logger,
                specificationsApiClient: specificationsApiClient,
                resultsRepository: calculationResultsRepository,
                jobManagement: jobManagement,
                blobClient: blobClient);

            //Act
            await resultsService.QueueCsvGenerationMessages();

            //Assert
            await
            jobManagement
            .Received(1)
            .QueueJob(
                Arg.Is <JobCreateModel>(_ =>
                                        _.JobDefinitionId == JobConstants.DefinitionNames.GenerateCalcCsvResultsJob &&
                                        _.Properties["specification-id"] == specificationId));

            logger
            .Received()
            .Information($"Found new calculation results for specification id '{specificationId}'");
        }
 public FundingLineDetailsController(IPublishingApiClient publishingApiClient, IProvidersApiClient providersApiClient,
                                     ISpecificationsApiClient specificationsApiClient, IPoliciesApiClient policiesApiClient, IAuthorizationHelper authorizationHelper)
 {
     _publishingApiClient     = publishingApiClient;
     _providersApiClient      = providersApiClient;
     _specificationsApiClient = specificationsApiClient;
     _policiesApiClient       = policiesApiClient;
     _authorizationHelper     = authorizationHelper;
 }
Ejemplo n.º 29
0
        public async Task ValidateAsync_WhenSourceCodeDoesNotCompile__ValidIsFalse()
        {
            //Arrange
            CalculationCreateModel model = CreateModel();

            model.CalculationType = CalculationType.Additional;

            ICalculationsRepository calculationsRepository = CreateCalculationRepository();

            calculationsRepository
            .GetCalculationsBySpecificationIdAndCalculationName(Arg.Is(model.SpecificationId), Arg.Is(model.Name))
            .Returns((Calculation)null);

            SpecModel.SpecificationSummary specificationSummary = new SpecModel.SpecificationSummary
            {
                Name           = "spec name",
                FundingStreams = new[] { new Reference(model.FundingStreamId, "funding stream name") }
            };

            ISpecificationsApiClient specificationsApiClient = CreateSpecificationsApiClient();

            specificationsApiClient
            .GetSpecificationSummaryById(Arg.Is(model.SpecificationId))
            .Returns(new Common.ApiClient.Models.ApiResponse <SpecModel.SpecificationSummary>(HttpStatusCode.OK, specificationSummary));

            PreviewResponse previewResponse = new PreviewResponse
            {
                CompilerOutput = new Build
                {
                    CompilerMessages = new List <CompilerMessage>
                    {
                        new CompilerMessage {
                            Message = "Failed"
                        }
                    }
                }
            };

            IPreviewService previewService = CreatePreviewService(previewResponse);

            CalculationCreateModelValidator validator = CreateValidator(
                calculationsRepository, previewService: previewService, specificationsApiClient: specificationsApiClient);

            //Act
            ValidationResult result = await validator.ValidateAsync(model);

            //Assert
            result
            .IsValid
            .Should()
            .BeFalse();

            result.Errors
            .Should()
            .Contain(_ => _.ErrorMessage == "There are errors in the source code provided");
        }
        public async Task PerformSearch_FirstSearchResultWithFacets_ReturnedCorrectly()
        {
            // Arrange
            ISpecificationsApiClient specsClient = Substitute.For <ISpecificationsApiClient>();
            ILogger logger = Substitute.For <ILogger>();
            IMapper mapper = MappingHelper.CreateFrontEndMapper();

            ISpecificationSearchService SpecificationSearchService = new SpecificationSearchService(specsClient, mapper, logger);

            int numberOfItems = 25;

            IEnumerable <SearchFacet> facets = new[]
            {
                new SearchFacet(), new SearchFacet()
            };

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

            specsClient
            .FindSpecifications(Arg.Any <SearchFilterRequest>())
            .Returns(itemResult);

            SearchRequestViewModel request = new SearchRequestViewModel();

            // Act
            SpecificationSearchResultViewModel results = await SpecificationSearchService.PerformSearch(request);

            // Assert
            SpecificationSearchResultItemViewModel first = results.Specifications.First();

            first
            .Should()
            .NotBeNull();

            first
            .Should()
            .BeEquivalentTo(new SpecificationSearchResultItemViewModel()
            {
                Id   = "10",
                Name = "Specification 1",
                FundingPeriodName    = "Test Period",
                FundingPeriodId      = "FundingPeriodID",
                Status               = "Draft",
                Description          = "Description",
                FundingStreamIds     = new[] { "fs1", "fs2" },
                FundingStreamNames   = new[] { "Funding Stream 1", "Funding Stream 2" },
                LastUpdatedDate      = new DateTime(2018, 12, 5, 12, 5, 6),
                IsSelectedForFunding = true
            });

            results
            .Facets
            .Count()
            .Should()
            .Be(2);
        }