예제 #1
0
        public async Task UpdateFundingStructureLastModifiedGuardsAgainstInValidRequests()
        {
            UpdateFundingStructureLastModifiedRequest request = NewUpdateFundingStructureLastModifiedRequest();
            ValidationFailure failureOne       = NewValidationFailure();
            ValidationFailure failureTwo       = NewValidationFailure();
            ValidationResult  validationResult = NewValidationResult(_ => _.WithValidationFailures(failureOne, failureTwo));

            GivenTheValidationResult(request, validationResult);

            BadRequestObjectResult actionResult = await WhenTheFundingStructureLastModifiedIsUpdated(request) as BadRequestObjectResult;

            SerializableError serializableError = actionResult?.Value as SerializableError;

            serializableError
            .Should()
            .NotBeNull();

            serializableError[failureOne.PropertyName]
            .Should()
            .BeEquivalentTo(new[] { failureOne.ErrorMessage });

            serializableError[failureTwo.PropertyName]
            .Should()
            .BeEquivalentTo(new[] { failureTwo.ErrorMessage });

            await AndTheCacheWasNotUpdated();
        }
        public void GuardsAgainstMissingFundingPeriodId()
        {
            UpdateFundingStructureLastModifiedRequest request = NewOtherwiseValidRequest(_ => _.WithFundingPeriodId(null));

            ValidationResult validationResult = WhenTheRequestIsValidated(request);

            ThenTheValidationResultsContainsTheErrors(validationResult, ("FundingPeriodId", "'Funding Period Id' must not be empty."));
        }
        public void GuardsAgainstMissingLastModifiedDate()
        {
            UpdateFundingStructureLastModifiedRequest request = NewOtherwiseValidRequest(_ => _.WithLastModified(DateTimeOffset.MinValue));

            ValidationResult validationResult = WhenTheRequestIsValidated(request);

            ThenTheValidationResultsContainsTheErrors(validationResult, ("LastModified", "'Last Modified' must be greater than"));
        }
예제 #4
0
        public async Task UpdateFundingStructureLastModifiedSetsTheDateTimeOffsetValueInTheCache()
        {
            UpdateFundingStructureLastModifiedRequest request = NewUpdateFundingStructureLastModifiedRequest();

            GivenTheValidationResult(request, NewValidationResult());

            OkResult actionResult = await WhenTheFundingStructureLastModifiedIsUpdated(request) as OkResult;

            actionResult
            .Should()
            .NotBeNull();

            await AndTheLastUpdatedCacheWasUpdated($"{CacheKeys.FundingLineStructureTimestamp}{request.SpecificationId}:{request.FundingStreamId}:{request.FundingPeriodId}",
                                                   request.LastModified);
        }
        public async Task UpdateFundingStructureLastModified()
        {
            UpdateFundingStructureLastModifiedRequest request = new UpdateFundingStructureLastModifiedRequest
            {
                SpecificationId = NewRandomString()
            };

            GivenTheStatusCode("funding-structures/lastModified", HttpStatusCode.OK, HttpMethod.Post);

            NoValidatedContentApiResponse apiResponse = await _client.UpdateFundingStructureLastModified(request);

            apiResponse?
            .StatusCode
            .Should()
            .Be(HttpStatusCode.OK);

            AndTheRequestContentsShouldHaveBeen(request.AsJson());
        }
예제 #6
0
        public async Task <IActionResult> UpdateFundingStructureLastModified(UpdateFundingStructureLastModifiedRequest request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            // ReSharper disable once MethodHasAsyncOverload
            ValidationResult validationResult = _validator.Validate(request);

            if (!validationResult.IsValid)
            {
                return(validationResult.AsBadRequest());
            }

            string cacheKey = GetCacheKeyFundingStructure(request.SpecificationId,
                                                          request.FundingStreamId,
                                                          request.FundingPeriodId);

            await _cacheResilience.ExecuteAsync(() => _cacheProvider.SetAsync(cacheKey, request.LastModified));

            return(new OkResult());
        }
예제 #7
0
 private async Task <IActionResult> WhenTheFundingStructureLastModifiedIsUpdated(UpdateFundingStructureLastModifiedRequest request)
 => await _service.UpdateFundingStructureLastModified(request);
예제 #8
0
 private void GivenTheValidationResult(UpdateFundingStructureLastModifiedRequest request,
                                       ValidationResult validationResult)
 {
     _validator.Validate(request)
     .Returns(validationResult);
 }
 public async Task <IActionResult> UpdateFundingStructureLastModified([FromBody] UpdateFundingStructureLastModifiedRequest request)
 => await _fundingStructureService.UpdateFundingStructureLastModified(request);
 public Task <NoValidatedContentApiResponse> UpdateFundingStructureLastModified(UpdateFundingStructureLastModifiedRequest request)
 => Task.FromResult(new NoValidatedContentApiResponse(HttpStatusCode.OK));
 public Task <NoValidatedContentApiResponse> UpdateFundingStructureLastModified(UpdateFundingStructureLastModifiedRequest request)
 {
     throw new NotImplementedException();
 }
        public async Task <NoValidatedContentApiResponse> UpdateFundingStructureLastModified(UpdateFundingStructureLastModifiedRequest request)
        {
            Guard.ArgumentNotNull(request, nameof(request));

            return(await ValidatedPostAsync("funding-structures/lastModified", request));
        }