Example #1
0
        public async Task GetSpecificationsForFundingByPeriod_OnBadRequestStatusFromSpecApiClient_ThenReturnsBadRequestResponse()
        {
            // Arrange
            const string fundingPeriodId = "fundingPeriodId";
            const string fundingStreamId = "fundingStreamId";

            _specificationsApiClient
            .GetSelectedSpecificationsByFundingPeriodIdAndFundingStreamId(fundingPeriodId, fundingStreamId)
            .Returns(Task.FromResult(new ApiResponse <IEnumerable <SpecificationSummary> >(HttpStatusCode.ServiceUnavailable)));

            // Act
            IActionResult result = await _specificationController.GetSpecificationsSelectedForFundingByPeriodAndStream(fundingPeriodId, fundingStreamId);

            // Assert
            result.Should().BeOfType <StatusCodeResult>();
        }
        public async Task <IActionResult> GetSpecificationsSelectedForFundingByPeriodAndStream(string fundingPeriodId, string fundingStreamId)
        {
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));

            ApiResponse <IEnumerable <SpecificationSummary> > apiResponse = await _specificationsApiClient.GetSelectedSpecificationsByFundingPeriodIdAndFundingStreamId(fundingPeriodId, fundingStreamId);

            if (apiResponse.StatusCode == HttpStatusCode.OK)
            {
                return(Ok(apiResponse.Content.Where(s => s.IsSelectedForFunding).OrderBy(c => c.Name)));
            }

            if (apiResponse.StatusCode == HttpStatusCode.BadRequest)
            {
                return(new BadRequestResult());
            }

            return(new StatusCodeResult(500));
        }