private async Task EditSpecifications( List <FundingConfiguration> fundingConfigurations, Dictionary <string, int> fundingStreamsLatestProviderSnapshotIds, IEnumerable <SpecificationSummary> specificationSummaries) { IEnumerable <FundingConfiguration> updateLatestFundingConfigurations = fundingConfigurations.Where(_ => _.UpdateCoreProviderVersion == UpdateCoreProviderVersion.ToLatest).ToList(); foreach (SpecificationSummary specificationSummary in specificationSummaries) { string fundingStreamId = specificationSummary.FundingStreams.FirstOrDefault().Id; if (updateLatestFundingConfigurations.Any(_ => _.FundingPeriodId == specificationSummary.FundingPeriod.Id && _.FundingStreamId == fundingStreamId)) { await _specificationsApiClientPolicy.ExecuteAsync(() => _specificationsApiClient.UpdateSpecification( specificationSummary.Id, new EditSpecificationModel { Name = specificationSummary.Name, Description = specificationSummary.Description, FundingStreamId = fundingStreamId, FundingPeriodId = specificationSummary.FundingPeriod.Id, ProviderVersionId = specificationSummary.ProviderVersionId, ProviderSnapshotId = fundingStreamsLatestProviderSnapshotIds[fundingStreamId], CoreProviderVersionUpdates = CoreProviderVersionUpdates.UseLatest })); } } }
public async Task UpdateSpecification_ReturnsBadRequestObjectResultWhenApiResponseIsBadRequest() { _specificationsApiClient.UpdateSpecification(Arg.Any <string>(), Arg.Any <EditSpecificationModel>()) .Returns(new ValidatedApiResponse <SpecificationSummary>(HttpStatusCode.BadRequest)); IActionResult actionResult = await _specificationController.UpdateSpecification(new EditSpecificationModel(), NewRandomString()); actionResult .Should() .BeOfType <BadRequestObjectResult>(); }
public async Task <IActionResult> UpdateSpecification([FromBody] EditSpecificationModel viewModel, [FromRoute] string specificationId) { ValidatedApiResponse <SpecificationSummary> result = await _specificationsApiClient.UpdateSpecification(specificationId, viewModel); if (result.IsBadRequest(out BadRequestObjectResult badRequest)) { return(badRequest); } if (result.StatusCode == HttpStatusCode.OK) { return(new OkResult()); } return(new BadRequestResult()); }