コード例 #1
0
        public async Task Returns400IfPrereqChecksFailsForGetRefreshFundingJobPrereqErrors()
        {
            string errorMessage = "calc error";

            ApiSpecificationSummary specificationSummary = NewApiSpecificationSummary(_ => _.WithId(SpecificationId));

            GivenTheApiResponseDetailsForTheSuppliedId(specificationSummary);

            AndGetPreReqCheckerLocatorReturnsRefreshPreReqChecker();
            AndPrereqChecksFails(specificationSummary, errors: new[] { errorMessage });

            await WhenGetRefreshFundingJobPrereqErrors();

            ThenTheResponseShouldBe <BadRequestObjectResult>();

            BadRequestObjectResult objectResult = ActionResult as BadRequestObjectResult;

            objectResult.Should().NotBeNull();
            objectResult.Value.Should().BeOfType <SerializableError>();

            SerializableError errors = objectResult.Value as SerializableError;

            errors.Should().NotBeNull();
            errors.Count.Should().Be(1);

            errors.FirstOrDefault().Value.Should().BeOfType <string[]>();

            string[] errorArray = errors.FirstOrDefault().Value as string[];

            errorArray.Should().NotBeNull();
            errorArray.Length.Should().Be(1);

            errorArray.FirstOrDefault().Should().Be(errorMessage);
        }
        public async Task ValidateSpecificationForRefresh_ReturnsBadRequest_ForBadRequestApiResponses()
        {
            string errorMessage         = "Error";
            IEnumerable <string> errors = new[] { errorMessage };

            ValidatedApiResponse <IEnumerable <string> > apiResponse
                = new ValidatedApiResponse <IEnumerable <string> >(HttpStatusCode.BadRequest)
                {
                ModelState = new Dictionary <string, IEnumerable <string> > {
                    { "", errors }
                }
                };

            _publishingApiClient
            .ValidateSpecificationForRefresh(Arg.Is(ValidSpecificationId))
            .Returns(apiResponse);

            IActionResult result = await _publishController.ValidateSpecificationForRefresh(ValidSpecificationId);

            result.Should().BeOfType <BadRequestObjectResult>();

            BadRequestObjectResult okObjectResult = result as BadRequestObjectResult;

            okObjectResult.Should().NotBeNull();
            okObjectResult.Value.Should().NotBeNull();
            okObjectResult.Value.Should().BeOfType <Dictionary <string, IEnumerable <string> > >();

            Dictionary <string, IEnumerable <string> > content = okObjectResult.Value as Dictionary <string, IEnumerable <string> >;

            content.Should().NotBeNull();
            content.FirstOrDefault().Should().NotBeNull();
            content.FirstOrDefault().Value.Count().Should().Be(1);
            content.FirstOrDefault().Value.FirstOrDefault().Should().Be(errorMessage);
        }
コード例 #3
0
        public void ErrorAs_Null_ShouldFail()
        {
            ActionResult result         = new BadRequestObjectResult(null as object);
            var          failureMessage = FailureMessageHelper.ExpectedContextTypeXButFoundNull(
                "BadRequestObjectResult.Error", typeof(object));

            Action a = () => result.Should().BeBadRequestObjectResult().ErrorAs <object>();

            a.Should().Throw <Exception>().WithMessage(failureMessage);
        }
        public async Task QueueBatchUploadValidationReturnsBadRequestIfRequestFailsValidation()
        {
            BatchUploadValidationRequest request          = NewBatchUploadValidationRequest();
            ValidationResult             validationResult = NewValidationResult(_ => _.WithValidationFailures(NewValidationFailure(),
                                                                                                              NewValidationFailure()));

            GivenTheValidationResultForTheRequest(request, validationResult);

            BadRequestObjectResult badRequest = await WhenTheBatchUploadValidationIsQueued(request, null, null) as BadRequestObjectResult;

            badRequest
            .Should()
            .NotBeNull();
        }
        public async Task AssignProfilePatternKeyReturnsBadRequestIfFundingConfigurationIsNotEnableedUserEditableRuleBasedProfiles()
        {
            string fundingLineCode = NewRandomString();
            string key             = NewRandomString();

            PublishedProvider publishedProvider = NewPublishedProvider(_ => _.WithCurrent(
                                                                           NewPublishedProviderVersion(ppv => ppv.WithProfilePatternKeys(
                                                                                                           NewProfilePatternKey(ppk => ppk.WithFundingLineCode(fundingLineCode).WithKey(key))))));

            GivenThePublishedProvider(publishedProvider);

            GivenTheFundingConfiguration(false);
            ProfilePatternKey      profilePatternKey = NewProfilePatternKey();
            BadRequestObjectResult result            = await WhenProfilePatternKeyIsAssigned(_fundingStreamId, _fundingPeriodId, _providerId, profilePatternKey) as BadRequestObjectResult;

            result
            .Should()
            .NotBeNull();

            result
            .Value
            .Should()
            .Be($"User not allowed to edit rule based profiles for funding stream - '{_fundingStreamId}' and funding period - '{_fundingPeriodId}'");
        }