public void Initialize() { _mapper = new MapperConfiguration(_ => { _.AddProfile <ExternalServiceMappingProfile>(); }).CreateMapper(); _publishedProviderVersion = NewRandomString(); _providerId = NewRandomString(); _providerVersionId = NewRandomString(); _publishedFundingRepository = Substitute.For <IPublishedFundingRepository>(); _providersApiClient = Substitute.For <IProvidersApiClient>(); _logger = Substitute.For <ILogger>(); _cacheSettings = Substitute.For <IExternalApiFileSystemCacheSettings>(); _fileSystemCache = Substitute.For <IFileSystemCache>(); _publishedProviderRetrievalService = new PublishedProviderRetrievalService( _publishedFundingRepository, PublishingResilienceTestHelper.GenerateTestPolicies(), _providersApiClient, _logger, _mapper, _cacheSettings, _fileSystemCache); }
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); }
public ProviderController(IProvidersApiClient providersApiClient, IResultsApiClient resultsApiClient, IFundingDataZoneApiClient fundingDataZoneApiClient) { _providersApiClient = providersApiClient; _resultsApiClient = resultsApiClient; _fundingDataZoneApiClient = fundingDataZoneApiClient; }
public PublishedProviderRetrievalService( IPublishedFundingRepository publishedFundingRepository, IPublishingResiliencePolicies publishingResiliencePolicies, IProvidersApiClient providersApiClient, ILogger logger, IMapper mapper, IExternalApiFileSystemCacheSettings cacheSettings, IFileSystemCache fileSystemCache) { Guard.ArgumentNotNull(publishedFundingRepository, nameof(publishedFundingRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(publishingResiliencePolicies, nameof(publishingResiliencePolicies)); Guard.ArgumentNotNull(publishingResiliencePolicies.PublishedFundingRepository, nameof(publishingResiliencePolicies.PublishedFundingRepository)); Guard.ArgumentNotNull(publishingResiliencePolicies.ProvidersApiClient, nameof(publishingResiliencePolicies.ProvidersApiClient)); Guard.ArgumentNotNull(cacheSettings, nameof(cacheSettings)); Guard.ArgumentNotNull(fileSystemCache, nameof(fileSystemCache)); _publishedFundingRepository = publishedFundingRepository; _providersApiClient = providersApiClient; _logger = logger; _mapper = mapper; _cacheSettings = cacheSettings; _fileSystemCache = fileSystemCache; _publishedFundingRepositoryPolicy = publishingResiliencePolicies.PublishedFundingRepository; _providersApiClientPolicy = publishingResiliencePolicies.ProvidersApiClient; }
public void Validate_GivenProviderVersionIdDoesntExist_ValidIsFalse() { //Arrange SpecificationEditModel model = CreateModel(); model.SpecificationId = "specId"; IProvidersApiClient providersApiClient = CreateProviderApiClient(HttpStatusCode.NotFound); SpecificationEditModelValidator validator = CreateValidator(providersApiClient: providersApiClient); //Act ValidationResult result = validator.Validate(model); //Assert result .IsValid .Should() .BeFalse(); result .Errors.Select(x => x.PropertyName == "ProviderVersionId" && x.ErrorMessage == "Provider version id selected does not exist") .Count() .Should() .Be(1); }
public TestResultsService(ITestResultsRepository testResultsRepository, ISearchRepository <TestScenarioResultIndex> searchRepository, IMapper mapper, ILogger logger, ITelemetry telemetry, ITestRunnerResiliencePolicies policies, IProvidersApiClient providersApiClient, IJobManagement jobManagement) : base(jobManagement, logger) { Guard.ArgumentNotNull(searchRepository, nameof(searchRepository)); Guard.ArgumentNotNull(testResultsRepository, nameof(testResultsRepository)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(telemetry, nameof(telemetry)); Guard.ArgumentNotNull(policies?.TestResultsRepository, nameof(policies.TestResultsRepository)); Guard.ArgumentNotNull(policies?.TestResultsSearchRepository, nameof(policies.TestResultsSearchRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); _testResultsRepository = testResultsRepository; _searchRepository = searchRepository; _mapper = mapper; _logger = logger; _telemetry = telemetry; _testResultsPolicy = policies.TestResultsRepository; _testResultsSearchPolicy = policies.TestResultsSearchRepository; _providersApiClient = providersApiClient; }
public ProvidersStepContext(IProviderService service, IProvidersApiClient client, IBlobClient blobClient) { _blobClient = blobClient; Service = service; Client = client; }
public FundingLineDetailsController(IPublishingApiClient publishingApiClient, IProvidersApiClient providersApiClient, ISpecificationsApiClient specificationsApiClient, IPoliciesApiClient policiesApiClient, IAuthorizationHelper authorizationHelper) { _publishingApiClient = publishingApiClient; _providersApiClient = providersApiClient; _specificationsApiClient = specificationsApiClient; _policiesApiClient = policiesApiClient; _authorizationHelper = authorizationHelper; }
public ProviderDocumentGenerator(IPublishedProviderContentsGenerator publishedProviderContentsGenerator, IPublishedFundingContentsGenerator publishedFundingContentsGenerator, IProvidersApiClient providersApiClient, IOrganisationGroupResiliencePolicies organisationGroupResiliencePolicies, ILogger logger) { _publishedProviderContentsGenerator = publishedProviderContentsGenerator; _publishedFundingContentsGenerator = publishedFundingContentsGenerator; _logger = logger; organisationGroupTargetProviderLookup = new OrganisationGroupTargetProviderLookup(providersApiClient, organisationGroupResiliencePolicies); }
private static SpecificationCreateModelValidator CreateValidator(ISpecificationsRepository repository = null, IProvidersApiClient providersApiClient = null, IPoliciesApiClient policiesApiClient = null ) { return(new SpecificationCreateModelValidator(repository ?? CreateSpecificationsRepository(), providersApiClient ?? CreateProviderApiClient(), policiesApiClient ?? CreatePoliciesApiClient(), SpecificationsResilienceTestHelper.GenerateTestPolicies())); }
public PublishedProviderStepContext(IProviderService service, IProvidersApiClient client, ISearchRepository <PublishedProviderIndex> searchRepository, IBlobClient blobClient) { _searchRepository = searchRepository; _blobClient = blobClient; Service = service; Client = client; }
public OrganisationGroupTargetProviderLookup(IProvidersApiClient providersApiClient, IOrganisationGroupResiliencePolicies resiliencePolicies) { Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); _providersApiClient = providersApiClient; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; _additionalIdentifierKeys = GenerateAdditionalKeys(); _providers = new Dictionary <string, Dictionary <string, Provider> >(); }
private static IProvidersApiClient CreateProviderApiClient(HttpStatusCode statusCode = HttpStatusCode.NoContent) { IProvidersApiClient providerApiClient = Substitute.For <IProvidersApiClient>(); providerApiClient .DoesProviderVersionExist(Arg.Any <string>()) .Returns(statusCode); return(providerApiClient); }
private static IProvidersApiClient CreateProviderApiClient(HttpStatusCode statusCode = HttpStatusCode.NotFound) { IProvidersApiClient providerApiClient = Substitute.For <IProvidersApiClient>(); providerApiClient .DoesProviderVersionExist(ProviderVersionId) .Returns(statusCode); return(providerApiClient); }
public ProviderSearchService(IProvidersApiClient providersApiClient, IMapper mapper, ILogger logger) { Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(logger, nameof(logger)); _providersApiClient = providersApiClient; _mapper = mapper; _logger = logger; }
public void Setup() { _providersApiClient = Substitute.For <IProvidersApiClient>(); _organisationGroupTargetProviderLookup = new OrganisationGroupTargetProviderLookup(_providersApiClient, new OrganisationGroupResiliencePolicies { ProvidersApiClient = Policy.NoOpAsync() }); _providerVersionId = "test-providers"; _providersApiClient .GetProvidersByVersion(Arg.Is(_providerVersionId)) .Returns(GetProviderVersion()); }
public void Setup() { _providersApiClient = Substitute.For <IProvidersApiClient>(); _organisationGroupTargetProviderLookup = new OrganisationGroupTargetProviderLookup(_providersApiClient, new OrganisationGroupResiliencePolicies { ProvidersApiClient = Policy.NoOpAsync() }); _providerVersionId = "test-providers"; _scopedProviders = GenerateScopedProviders(); AndCoreProviderListExistsWithStandardProviders(); }
public AssignSpecificationProviderVersionModelValidator( ISpecificationsRepository specificationsRepository, IProvidersApiClient providersApiClient, ISpecificationsResiliencePolicies resiliencePolicies) { Guard.ArgumentNotNull(specificationsRepository, nameof(specificationsRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.ProvidersApiClient, nameof(resiliencePolicies.ProvidersApiClient)); _specificationsRepository = specificationsRepository; _providersApiClient = providersApiClient; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; RuleFor(model => model.SpecificationId) .NotEmpty() .WithMessage("Null or Empty SpecificationId provided") .CustomAsync(async(name, context, cancellationToken) => { AssignSpecificationProviderVersionModel model = context.ParentContext.InstanceToValidate as AssignSpecificationProviderVersionModel; if (!string.IsNullOrWhiteSpace(model.SpecificationId)) { Specification specification = await _specificationsRepository.GetSpecificationById(model.SpecificationId); if (specification == null) { context.AddFailure(nameof(model.SpecificationId), $"Specification not found for SpecificationId - {model.SpecificationId}"); } else if (specification.Current.ProviderSource != ProviderSource.FDZ) { context.AddFailure($"Specification ProviderSource is not set to FDZ"); } } }); RuleFor(model => model.ProviderVersionId) .NotEmpty() .WithMessage("Null or Empty ProviderVersionId provided") .CustomAsync(async(name, context, cancellationToken) => { AssignSpecificationProviderVersionModel model = context.ParentContext.InstanceToValidate as AssignSpecificationProviderVersionModel; if (!string.IsNullOrWhiteSpace(model.ProviderVersionId)) { HttpStatusCode providerVersionStatusCode = await _providersApiClientPolicy.ExecuteAsync(() => _providersApiClient.DoesProviderVersionExist(model.ProviderVersionId)); if (providerVersionStatusCode == HttpStatusCode.NotFound) { context.AddFailure(nameof(model.ProviderVersionId), $"Provider version id specified does not exist"); } } }); }
private SpecificationsService CreateService( IMapper mapper = null, ISpecificationsRepository specificationsRepository = null, IPoliciesApiClient policiesApiClient = null, ILogger logs = null, IValidator <SpecificationCreateModel> specificationCreateModelvalidator = null, IMessengerService messengerService = null, ISearchRepository <SpecificationIndex> searchRepository = null, IValidator <AssignDefinitionRelationshipMessage> assignDefinitionRelationshipMessageValidator = null, ICacheProvider cacheProvider = null, IValidator <SpecificationEditModel> specificationEditModelValidator = null, IResultsRepository resultsRepository = null, IVersionRepository <Models.Specs.SpecificationVersion> specificationVersionRepository = null, IQueueCreateSpecificationJobActions queueCreateSpecificationJobActions = null, IQueueEditSpecificationJobActions queueEditSpecificationJobActions = null, IQueueDeleteSpecificationJobActions queueDeleteSpecificationJobActions = null, IFeatureToggle featureToggle = null, ICalculationsApiClient calcsApiClient = null, IProvidersApiClient providersApiClient = null, IValidator <AssignSpecificationProviderVersionModel> assignSpecificationProviderVersionModelValidator = null) { return(new SpecificationsService( mapper ?? CreateMapper(), specificationsRepository ?? CreateSpecificationsRepository(), policiesApiClient ?? CreatePoliciesApiClient(), logs ?? CreateLogger(), specificationCreateModelvalidator ?? CreateSpecificationValidator(), messengerService ?? CreateMessengerService(), searchRepository ?? CreateSearchRepository(), assignDefinitionRelationshipMessageValidator ?? CreateAssignDefinitionRelationshipMessageValidator(), cacheProvider ?? CreateCacheProvider(), specificationEditModelValidator ?? CreateEditSpecificationValidator(), resultsRepository ?? CreateResultsRepository(), specificationVersionRepository ?? CreateVersionRepository(), SpecificationsResilienceTestHelper.GenerateTestPolicies(), queueCreateSpecificationJobActions ?? Substitute.For <IQueueCreateSpecificationJobActions>(), queueEditSpecificationJobActions ?? CreateQueueEditSpecificationJobActions(), queueDeleteSpecificationJobActions ?? Substitute.For <IQueueDeleteSpecificationJobActions>(), calcsApiClient ?? CreateCalcsApiClient(), featureToggle ?? Substitute.For <IFeatureToggle>(), providersApiClient ?? Substitute.For <IProvidersApiClient>(), _specificationIndexer, _resultsApiClient, _templateVersionChangedHandler, assignSpecificationProviderVersionModelValidator ?? CreateAssignSpecificationProviderVersionModelValidator(), CreateJobManagement())); }
protected DatasetService CreateDatasetService( IBlobClient blobClient = null, ILogger logger = null, IDatasetRepository datasetRepository = null, IValidator <CreateNewDatasetModel> createNewDatasetModelValidator = null, IValidator <DatasetVersionUpdateModel> datasetVersionUpdateModelValidator = null, IMapper mapper = null, IValidator <DatasetMetadataModel> datasetMetadataModelValidator = null, ISearchRepository <DatasetIndex> searchRepository = null, ISearchRepository <DatasetVersionIndex> datasetVersionIndex = null, IValidator <GetDatasetBlobModel> getDatasetBlobModelValidator = null, ICacheProvider cacheProvider = null, ICalcsRepository calcsRepository = null, IValidator <ExcelPackage> datasetWorksheetValidator = null, IValidator <DatasetUploadValidationModel> datasetUploadValidator = null, IProvidersApiClient providersApiClient = null, IJobManagement jobManagement = null, IProviderSourceDatasetRepository providerSourceDatasetRepository = null, ISpecificationsApiClient specificationsApiClient = null, IPolicyRepository policyRepository = null, IDatasetDataMergeService datasetDataMergeService = null) { return(new DatasetService( blobClient ?? CreateBlobClient(), logger ?? CreateLogger(), datasetRepository ?? CreateDatasetsRepository(), createNewDatasetModelValidator ?? CreateNewDatasetModelValidator(), datasetVersionUpdateModelValidator ?? CreateDatasetVersionUpdateModelValidator(), mapper ?? CreateMapper(), datasetMetadataModelValidator ?? CreateDatasetMetadataModelValidator(), searchRepository ?? CreateSearchRepository(), getDatasetBlobModelValidator ?? CreateGetDatasetBlobModelValidator(), cacheProvider ?? CreateCacheProvider(), datasetWorksheetValidator ?? CreateDataWorksheetValidator(), datasetUploadValidator ?? CreateDatasetUploadValidator(), DatasetsResilienceTestHelper.GenerateTestPolicies(), datasetVersionIndex ?? CreateDatasetVersionRepository(), providersApiClient ?? CreateProvidersApiClient(), jobManagement ?? CreateJobManagement(), providerSourceDatasetRepository ?? CreateProviderSourceDatasetRepository(), specificationsApiClient ?? CreateSpecificationsApiClient(), policyRepository ?? CreatePolicyRepository(), datasetDataMergeService ?? CreateDatasetDataMergeService())); }
private TestResultsService CreateTestResultsService( ITestResultsRepository testResultsRepository = null, ISearchRepository <TestScenarioResultIndex> searchRepository = null, IMapper mapper = null, ILogger logger = null, ITelemetry telemetry = null, ResiliencePolicies policies = null, IProvidersApiClient providersApiClient = null) { return(new TestResultsService( testResultsRepository ?? CreateTestResultsRepository(), searchRepository ?? CreateSearchRespository(), mapper ?? CreateMapper(), logger ?? CreateLogger(), telemetry ?? CreateTelemetry(), policies ?? TestRunnerResilienceTestHelper.GenerateTestPolicies(), providersApiClient ?? CreateProviderApiClient(), CreateJobManagement())); }
protected static ProcessDatasetService CreateProcessDatasetService( IBlobClient blobClient = null, IMessengerService messengerService = null, ILogger logger = null, IDatasetRepository datasetRepository = null, IExcelDatasetReader excelDatasetReader = null, ICacheProvider cacheProvider = null, ICalcsRepository calcsRepository = null, IProvidersApiClient providersApiClient = null, ISpecificationsApiClient specificationsApiClient = null, IProviderSourceDatasetsRepository providerResultsRepository = null, ITelemetry telemetry = null, IDatasetsResiliencePolicies datasetsResiliencePolicies = null, IDatasetsAggregationsRepository datasetsAggregationsRepository = null, IFeatureToggle featureToggle = null, IMapper mapper = null, IJobManagement jobManagement = null, IProviderSourceDatasetVersionKeyProvider versionKeyProvider = null, IJobsApiClient jobsApiClient = null, IVersionBulkRepository <ProviderSourceDatasetVersion> versionBulkRepository = null, IProviderSourceDatasetBulkRepository providerSourceDatasetBulkRepository = null) { return(new ProcessDatasetService( datasetRepository ?? CreateDatasetsRepository(), excelDatasetReader ?? CreateExcelDatasetReader(), cacheProvider ?? CreateCacheProvider(), calcsRepository ?? CreateCalcsRepository(), blobClient ?? CreateBlobClient(), messengerService ?? CreateMessengerService(), providerResultsRepository ?? CreateProviderResultsRepository(), providersApiClient ?? CreateProvidersApiClient(), specificationsApiClient ?? CreateSpecificationsApiClient(), logger ?? CreateLogger(), datasetsResiliencePolicies ?? DatasetsResilienceTestHelper.GenerateTestPolicies(), datasetsAggregationsRepository ?? CreateDatasetsAggregationsRepository(), featureToggle ?? CreateFeatureToggle(), mapper ?? CreateMapper(), jobManagement ?? CreateJobManagement(), versionKeyProvider ?? CreateDatasetVersionKeyProvider(), versionBulkRepository ?? new Mock <IVersionBulkRepository <ProviderSourceDatasetVersion> >().Object, providerSourceDatasetBulkRepository ?? new Mock <IProviderSourceDatasetBulkRepository>().Object)); }
public async Task Validate_GivenProviderVersionNotFoundForProviderVersionId_ValidIsFalse() { //Arrange AssignSpecificationProviderVersionModel model = CreateModel(SpecificationId, ProviderVersionId); IProvidersApiClient providersApiClient = CreateProviderApiClient(); AssignSpecificationProviderVersionModelValidator validator = CreateValidator(providersApiClient: providersApiClient); //Act ValidationResult result = await validator.ValidateAsync(model); //Assert result .IsValid .Should() .BeFalse(); result .Errors.Where(x => x.PropertyName == "ProviderVersionId" && x.ErrorMessage == "Provider version id specified does not exist") .Count() .Should() .Be(1); }
public void SetUp() { _providers = Substitute.For <IProvidersApiClient>(); _policiesService = Substitute.For <IPoliciesService>(); _publishedFundingDataService = Substitute.For <IPublishedFundingDataService>(); _jobManagement = Substitute.For <IJobManagement>(); _logger = Substitute.For <ILogger>(); _mapper = new MapperConfiguration(_ => { _.AddProfile <PublishingServiceMappingProfile>(); }).CreateMapper(); _providerService = new ProviderService(_providers, _policiesService, _publishedFundingDataService, new ResiliencePolicies { ProvidersApiClient = Policy.NoOpAsync() }, _mapper, _jobManagement, _logger); }
public async Task Validate_GivenSpecificationWithProviderSourceFDZAndProviderVersionExists_ValidIsTrue() { //Arrange AssignSpecificationProviderVersionModel model = CreateModel(SpecificationId, ProviderVersionId); ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository(true, ProviderSource.FDZ); IProvidersApiClient providersApiClient = CreateProviderApiClient(HttpStatusCode.OK); AssignSpecificationProviderVersionModelValidator validator = CreateValidator(specificationsRepository, providersApiClient); //Act ValidationResult result = await validator.ValidateAsync(model); //Assert result .IsValid .Should() .BeTrue(); result .Errors .Count() .Should() .Be(0); }
public CalculationEnginePreviewService( ICalculationEngine calculationEngine, IProvidersApiClient providersApiClient, IMapper mapper, ICalculatorResiliencePolicies resiliencePolicies, ISpecificationsApiClient specificationsApiClient, IProviderSourceDatasetsRepository providerSourceDatasetsRepository, ICalculationAggregationService calculationAggregationService, ICalculationsRepository calculationsRepository, ILogger logger) { Guard.ArgumentNotNull(calculationEngine, nameof(calculationEngine)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(providerSourceDatasetsRepository, nameof(providerSourceDatasetsRepository)); Guard.ArgumentNotNull(calculationAggregationService, nameof(calculationAggregationService)); Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository)); Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); Guard.ArgumentNotNull(resiliencePolicies.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient)); Guard.ArgumentNotNull(resiliencePolicies.ProvidersApiClient, nameof(resiliencePolicies.ProvidersApiClient)); Guard.ArgumentNotNull(resiliencePolicies.CalculationsApiClient, nameof(resiliencePolicies.CalculationsApiClient)); _calculationEngine = calculationEngine; _providersApiClient = providersApiClient; _mapper = mapper; _specificationsApiClient = specificationsApiClient; _providerSourceDatasetsRepository = providerSourceDatasetsRepository; _calculationAggregationService = calculationAggregationService; _specificationsApiPolicy = resiliencePolicies.SpecificationsApiClient; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; _calculationsApiClientPolicy = resiliencePolicies.CalculationsApiClient; _calculationsRepository = calculationsRepository; _logger = logger; }
public ProviderService(IProvidersApiClient providersApiClient, IPoliciesService policiesService, IPublishedFundingDataService publishedFundingDataService, IPublishingResiliencePolicies resiliencePolicies, IMapper mapper, IJobManagement jobManagement, ILogger logger) { Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(policiesService, nameof(policiesService)); Guard.ArgumentNotNull(publishedFundingDataService, nameof(publishedFundingDataService)); Guard.ArgumentNotNull(resiliencePolicies?.ProvidersApiClient, nameof(resiliencePolicies.ProvidersApiClient)); Guard.ArgumentNotNull(jobManagement, nameof(jobManagement)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(logger, nameof(logger)); _providersApiClient = providersApiClient; _policiesService = policiesService; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; _publishedFundingDataService = publishedFundingDataService; _jobManagement = jobManagement; _logger = logger; _mapper = mapper; }
public BuildProjectsService( ILogger logger, ITelemetry telemetry, IProvidersApiClient providersApiClient, ICacheProvider cacheProvider, ICalculationsRepository calculationsRepository, IFeatureToggle featureToggle, ICalcsResiliencePolicies resiliencePolicies, EngineSettings engineSettings, ISourceCodeService sourceCodeService, IDatasetsApiClient datasetsApiClient, IBuildProjectsRepository buildProjectsRepository, ICalculationEngineRunningChecker calculationEngineRunningChecker, IJobManagement jobManagement, IGraphRepository graphRepository, IMapper mapper, ISpecificationsApiClient specificationsApiClient, IPoliciesApiClient policiesApiClient, ISourceFileRepository sourceFileRepository) : base(jobManagement, logger) { Guard.ArgumentNotNull(logger, nameof(logger)); Guard.ArgumentNotNull(telemetry, nameof(telemetry)); Guard.ArgumentNotNull(cacheProvider, nameof(cacheProvider)); Guard.ArgumentNotNull(calculationsRepository, nameof(calculationsRepository)); Guard.ArgumentNotNull(featureToggle, nameof(featureToggle)); Guard.ArgumentNotNull(resiliencePolicies, nameof(resiliencePolicies)); Guard.ArgumentNotNull(engineSettings, nameof(engineSettings)); Guard.ArgumentNotNull(sourceCodeService, nameof(sourceCodeService)); Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient)); Guard.ArgumentNotNull(buildProjectsRepository, nameof(buildProjectsRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(calculationEngineRunningChecker, nameof(calculationEngineRunningChecker)); Guard.ArgumentNotNull(jobManagement, nameof(jobManagement)); Guard.ArgumentNotNull(graphRepository, nameof(graphRepository)); Guard.ArgumentNotNull(resiliencePolicies?.DatasetsApiClient, nameof(resiliencePolicies.DatasetsApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.ProvidersApiClient, nameof(resiliencePolicies.ProvidersApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.BuildProjectRepositoryPolicy, nameof(resiliencePolicies.BuildProjectRepositoryPolicy)); Guard.ArgumentNotNull(resiliencePolicies?.CalculationsRepository, nameof(resiliencePolicies.CalculationsRepository)); Guard.ArgumentNotNull(mapper, nameof(mapper)); Guard.ArgumentNotNull(specificationsApiClient, nameof(specificationsApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.SpecificationsApiClient, nameof(resiliencePolicies.SpecificationsApiClient)); Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.PoliciesApiClient, nameof(resiliencePolicies.PoliciesApiClient)); Guard.ArgumentNotNull(sourceFileRepository, nameof(sourceFileRepository)); _logger = logger; _telemetry = telemetry; _providersApiClient = providersApiClient; _providersApiClientPolicy = resiliencePolicies.ProvidersApiClient; _cacheProvider = cacheProvider; _calculationsRepository = calculationsRepository; _calculationsRepositoryPolicy = resiliencePolicies.CalculationsRepository; _featureToggle = featureToggle; _engineSettings = engineSettings; _sourceCodeService = sourceCodeService; _datasetsApiClient = datasetsApiClient; _jobManagement = jobManagement; _graphRepository = graphRepository; _datasetsApiClientPolicy = resiliencePolicies.DatasetsApiClient; _buildProjectsRepository = buildProjectsRepository; _buildProjectsRepositoryPolicy = resiliencePolicies.BuildProjectRepositoryPolicy; _calculationEngineRunningChecker = calculationEngineRunningChecker; _mapper = mapper; _specificationsApiClient = specificationsApiClient; _specificationsApiClientPolicy = resiliencePolicies.SpecificationsApiClient; _policiesApiClient = policiesApiClient; _policiesApiClientPolicy = resiliencePolicies.PoliciesApiClient; _sourceFileRepository = sourceFileRepository; _typeIdentifierGenerator = new VisualBasicTypeIdentifierGenerator(); }
public SpecificationCreateModelValidator(ISpecificationsRepository specificationsRepository, IProvidersApiClient providersApiClient, IPoliciesApiClient policiesApiClient, ISpecificationsResiliencePolicies resiliencePolicies) { Guard.ArgumentNotNull(specificationsRepository, nameof(specificationsRepository)); Guard.ArgumentNotNull(providersApiClient, nameof(providersApiClient)); Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.PoliciesApiClient, nameof(resiliencePolicies.PoliciesApiClient)); _specificationsRepository = specificationsRepository; _providersApiClient = providersApiClient; _policiesApiClient = policiesApiClient; _policiesApiClientPolicy = resiliencePolicies.PoliciesApiClient; RuleFor(model => model.FundingPeriodId) .NotEmpty() .WithMessage("Null or empty academic year id provided") .Custom((name, context) => { SpecificationCreateModel specModel = context.ParentContext.InstanceToValidate as SpecificationCreateModel; if (!string.IsNullOrWhiteSpace(specModel.FundingPeriodId)) { ApiResponse <PolicyModels.FundingPeriod> fundingPeriodResponse = _policiesApiClientPolicy.ExecuteAsync(() => _policiesApiClient.GetFundingPeriodById(specModel.FundingPeriodId)).GetAwaiter().GetResult(); if (fundingPeriodResponse?.StatusCode != HttpStatusCode.OK || fundingPeriodResponse?.Content == null) { context.AddFailure("Funding period not found"); } } }); RuleFor(model => model.ProviderVersionId) .Custom((name, context) => { SpecificationCreateModel specModel = context.ParentContext.InstanceToValidate as SpecificationCreateModel; ApiResponse <PolicyModels.FundingConfig.FundingConfiguration> fundingConfigResponse = _policiesApiClientPolicy.ExecuteAsync(() => _policiesApiClient.GetFundingConfiguration(specModel.FundingStreamIds.FirstOrDefault(), specModel.FundingPeriodId)).GetAwaiter().GetResult(); if (fundingConfigResponse?.StatusCode != HttpStatusCode.OK || fundingConfigResponse?.Content == null) { context.AddFailure("Funding config not found"); return; } switch (fundingConfigResponse.Content.ProviderSource) { case ProviderSource.CFS: { if (string.IsNullOrWhiteSpace(specModel.ProviderVersionId)) { context.AddFailure($"Null or empty provider version id"); } if (_providersApiClient.DoesProviderVersionExist(specModel.ProviderVersionId).Result == System.Net.HttpStatusCode.NotFound) { context.AddFailure($"Provider version id selected does not exist"); } if (specModel.CoreProviderVersionUpdates != CoreProviderVersionUpdates.Manual) { context.AddFailure($"CoreProviderVersionUpdates - {specModel.CoreProviderVersionUpdates} is not valid for provider source - {fundingConfigResponse.Content.ProviderSource}"); } break; } case ProviderSource.FDZ: { if (!specModel.ProviderSnapshotId.HasValue) { context.AddFailure($"Null or empty provider snapshot id"); } break; } } }); RuleFor(model => model.FundingStreamIds) .NotNull() .NotEmpty() .WithMessage("You must select at least one funding stream") .Custom((name, context) => { SpecificationCreateModel specModel = context.ParentContext.InstanceToValidate as SpecificationCreateModel; foreach (string fundingStreamId in specModel.FundingStreamIds) { if (string.IsNullOrWhiteSpace(fundingStreamId)) { context.AddFailure($"A null or empty string funding stream ID was provided"); } } }); RuleFor(model => model.Name) .NotEmpty() .WithMessage("You must give a unique specification name") .Custom((name, context) => { SpecificationCreateModel specModel = context.ParentContext.InstanceToValidate as SpecificationCreateModel; Specification specification = _specificationsRepository.GetSpecificationByQuery(m => m.Content.Name.ToLower() == specModel.Name.Trim().ToLower()).Result; if (specification != null) { context.AddFailure($"You must give a unique specification name"); } }); }