public async Task <IActionResult> GetProviderVersionMetadata(string providerVersionId) { Guard.IsNullOrWhiteSpace(providerVersionId, nameof(providerVersionId)); string cacheKey = $"{CacheKeys.ProviderVersionMetadata}:{providerVersionId}"; ProviderVersionMetadataDto result = await _cachePolicy.ExecuteAsync(() => _cacheProvider.GetAsync <ProviderVersionMetadataDto>(cacheKey)); if (result == null) { ProviderVersionMetadata providerVersionMetadata = await _providerVersionMetadataRepositoryPolicy.ExecuteAsync(() => _providerVersionMetadataRepository.GetProviderVersionMetadata(providerVersionId)); if (providerVersionMetadata != null) { result = _mapper.Map <ProviderVersionMetadataDto>(providerVersionMetadata); await _cachePolicy.ExecuteAsync(() => _cacheProvider.SetAsync(cacheKey, result)); } } if (result == null) { return(new NotFoundResult()); } return(new OkObjectResult(result)); }
public async Task <(bool Success, IActionResult ActionResult)> UploadProviderVersion(string providerVersionId, ProviderVersionViewModel providerVersionModel) { Guard.IsNullOrWhiteSpace(providerVersionId, nameof(providerVersionId)); Guard.ArgumentNotNull(providerVersionModel, nameof(providerVersionModel)); IActionResult validationResult = await UploadProviderVersionValidate(providerVersionModel, providerVersionId); if (validationResult != null) { return(false, validationResult); } ProviderVersion providerVersion = _mapper.Map <ProviderVersion>(providerVersionModel); providerVersion.Id = $"providerVersion-{providerVersionId}"; await UploadProviderVersionBlob(providerVersionId, providerVersion); providerVersion.Providers = null; ProviderVersionMetadata providerVersionMetadata = providerVersion; HttpStatusCode result = await _providerVersionMetadataRepositoryPolicy.ExecuteAsync(() => _providerVersionMetadataRepository.CreateProviderVersion(providerVersionMetadata)); if (result.IsSuccess()) { await _providersSearchPolicy.ExecuteAsync(() => _searchRepository.RunIndexer()); } return(true, null); }
public async Task CreateProviderVersionDelegatesToCosmos() { ProviderVersionMetadata providerVersion = NewProviderVersionMetadata(); HttpStatusCode expectedStatusCode = NewRandomStatusCode(); GivenTheStatusCodeForTheCreate(providerVersion, expectedStatusCode); HttpStatusCode actualStatusCode = await WhenTheProviderVersionIsCreated(providerVersion); actualStatusCode .Should() .Be(expectedStatusCode); }
public SetFundingStreamCurrentProviderVersionRequestValidator(IProviderVersionsMetadataRepository providerVersions, IPoliciesApiClient policiesApiClient, IProvidersResiliencePolicies resiliencePolicies) { Guard.ArgumentNotNull(providerVersions, nameof(providerVersions)); Guard.ArgumentNotNull(policiesApiClient, nameof(policiesApiClient)); Guard.ArgumentNotNull(resiliencePolicies?.ProviderVersionMetadataRepository, nameof(resiliencePolicies.ProviderVersionMetadataRepository)); Guard.ArgumentNotNull(resiliencePolicies?.PoliciesApiClient, nameof(resiliencePolicies.PoliciesApiClient)); RuleFor(_ => _.FundingStreamId) .Cascade(CascadeMode.StopOnFirstFailure) .NotEmpty() .CustomAsync(async(fundingStreamId, context, cancellationToken) => { ApiResponse <FundingStream> response = await resiliencePolicies.PoliciesApiClient.ExecuteAsync(() => policiesApiClient.GetFundingStreamById(fundingStreamId)); if (response?.Content == null) { context.AddFailure(new ValidationFailure("FundingStreamId", $"No funding stream located with Id {fundingStreamId}")); } }); RuleFor(_ => _.ProviderVersionId) .Cascade(CascadeMode.StopOnFirstFailure) .NotEmpty() .CustomAsync(async(providerVersionId, context, cancellationToken) => { ProviderVersionMetadata response = await resiliencePolicies.ProviderVersionMetadataRepository.ExecuteAsync(() => providerVersions.GetProviderVersionMetadata(providerVersionId)); if (response == null) { context.AddFailure(new ValidationFailure("ProviderVersionId", $"No provider version located with Id {providerVersionId}")); } }); }
public async Task GetProviderVersionsReturnsAllProviderVersionMetadataInTheSuppliedFundingStream() { string fundingStream = NewRandomString(); ProviderVersionMetadata providerVersionOne = NewProviderVersionMetadata(_ => _.WithFundingStream(fundingStream)); ProviderVersionMetadata providerVersionTwo = NewProviderVersionMetadata(_ => _.WithFundingStream(fundingStream)); ProviderVersionMetadata providerVersionThree = NewProviderVersionMetadata(); ProviderVersionMetadata providerVersionFour = NewProviderVersionMetadata(_ => _.WithFundingStream(fundingStream)); ProviderVersionMetadata providerVersionFive = NewProviderVersionMetadata(); GivenTheCosmosContents(providerVersionOne, providerVersionTwo, providerVersionThree, providerVersionFour, providerVersionFive); IEnumerable <ProviderVersionMetadata> actualProviderVersions = await WhenTheProviderVersionsAreQueried(fundingStream); actualProviderVersions .Should() .BeEquivalentTo(providerVersionOne, providerVersionTwo, providerVersionFour); }
private async Task <HttpStatusCode> WhenTheProviderVersionIsCreated(ProviderVersionMetadata providerVersion) => await _repository.CreateProviderVersion(providerVersion);
public async Task <HttpStatusCode> CreateProviderVersion(ProviderVersionMetadata providerVersion) { Guard.ArgumentNotNull(providerVersion, nameof(providerVersion)); return(await _cosmos.CreateAsync(providerVersion)); }