private void GivenTheProfilePreview(ProfilePreviewRequestViewModel requestViewModel,
                                     IEnumerable <ProfileTotal> profileTotals)
 => _publishingApiClient.Setup(_ => _.PreviewProfileChange(It.Is <ProfilePreviewRequest>(req =>
                                                                                         req.ConfigurationType == requestViewModel.ConfigurationType.AsMatchingEnum <CalculateFunding.Common.ApiClient.Publishing.Models.ProfileConfigurationType>() &&
                                                                                         req.ProviderId == requestViewModel.ProviderId &&
                                                                                         req.FundingLineCode == requestViewModel.FundingLineCode &&
                                                                                         req.FundingPeriodId == requestViewModel.FundingPeriodId &&
                                                                                         req.FundingStreamId == requestViewModel.FundingStreamId &&
                                                                                         req.ProfilePatternKey == requestViewModel.ProfilePatternKey &&
                                                                                         req.SpecificationId == requestViewModel.SpecificationId)))
 .ReturnsAsync(new ApiResponse <IEnumerable <ProfileTotal> >(HttpStatusCode.OK, profileTotals));
        public async Task PreviewProfileChange_DelegatesToPublishingApiAndReturnsResult(ProfileConfigurationTypeViewModel configurationType)
        {
            ProfilePreviewRequestViewModel requestViewModel = new ProfilePreviewRequestViewModel
            {
                ConfigurationType = configurationType,
                ProviderId        = NewRandomString(),
                SpecificationId   = NewRandomString(),
                FundingLineCode   = NewRandomString(),
                FundingPeriodId   = NewRandomString(),
                FundingStreamId   = NewRandomString(),
                ProfilePatternKey = NewRandomString()
            };

            IEnumerable <ProfileTotal> profileTotals = ArraySegment <ProfileTotal> .Empty;

            GivenTheProfilePreview(requestViewModel, profileTotals);

            OkObjectResult result = await WhenTheProfileChangeIsPreviewed(requestViewModel) as OkObjectResult;

            result?
            .Value
            .Should()
            .BeSameAs(profileTotals);
        }
        public async Task <IActionResult> PreviewProfileChange([FromBody] ProfilePreviewRequestViewModel requestViewModel)
        {
            Guard.ArgumentNotNull(requestViewModel, nameof(requestViewModel));

            ApiResponse <IEnumerable <ProfileTotal> > profilePreview = await _publishingApiClient.PreviewProfileChange(new ProfilePreviewRequest
            {
                ConfigurationType = requestViewModel.ConfigurationType.AsMatchingEnum <Common.ApiClient.Publishing.Models.ProfileConfigurationType>(),
                ProviderId        = requestViewModel.ProviderId,
                SpecificationId   = requestViewModel.SpecificationId,
                FundingLineCode   = requestViewModel.FundingLineCode,
                FundingPeriodId   = requestViewModel.FundingPeriodId,
                FundingStreamId   = requestViewModel.FundingStreamId,
                ProfilePatternKey = requestViewModel.ProfilePatternKey
            });

            IActionResult errorResult = profilePreview.IsSuccessOrReturnFailureResult(nameof(FundingStreamPeriodProfilePattern));

            if (errorResult != null)
            {
                return(errorResult);
            }

            return(Ok(profilePreview.Content));
        }
 private async Task <IActionResult> WhenTheProfileChangeIsPreviewed(ProfilePreviewRequestViewModel request)
 => await _profilingController.PreviewProfileChange(request);