public async Task PerformSearch_GivenResultsWithoutErrors_ReturnsExpected()
        {
            int numberOfItems = 25;

            SearchResults <PublishedProviderSearchItem> searchResults = GenerateSearchResults(numberOfItems);

            _publishingClient
            .Setup(x => x.SearchPublishedProvider(It.IsAny <SearchModel>()))
            .ReturnsAsync(new ApiResponse <SearchResults <PublishedProviderSearchItem> >(HttpStatusCode.OK, searchResults));

            var providerStats = new ProviderFundingStreamStatusResponse {
                ProviderApprovedCount = 0, TotalFunding = 1234, ProviderDraftCount = numberOfItems
            };

            _publishingClient
            .Setup(x => x.GetProviderStatusCounts(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ApiResponse <IEnumerable <ProviderFundingStreamStatusResponse> >(HttpStatusCode.OK, new []
            {
                providerStats
            }));

            FundingConfiguration config = new FundingConfiguration
            {
                ApprovalMode    = ApprovalMode.All,
                FundingStreamId = "stream",
                FundingPeriodId = "period",
                ProviderSource  = ProviderSource.CFS
            };

            _policiesApiClient
            .Setup(x => x.GetFundingConfiguration(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ApiResponse <FundingConfiguration>(HttpStatusCode.OK, config));

            _service = new PublishedProviderSearchService(_publishingClient.Object, _policiesApiClient.Object, _logger, _mapper);

            SearchRequestViewModel request = new SearchRequestViewModel {
                PageSize = 12
            };

            PublishProviderSearchResultViewModel result = await _service.PerformSearch(request);

            result.CanApprove.Should().BeTrue();
            result.Providers.Should().HaveCount(numberOfItems);
            result.TotalErrorResults.Should().Be(0);
            result.TotalProvidersToApprove.Should().Be(numberOfItems);
        }
        public async Task ReturnsThePublishedProviderStatusFromPublishedProviderRepository()
        {
            string fundingStreamId1 = NewRandomString();
            string fundingStreamId2 = NewRandomString();

            const string approvedStatus = "Approved";
            const string draftStatus    = "Draft";
            const string releasedStatus = "Released";
            const string updatedStatus  = "Updated";

            int fs1ApprovedCount = NewRandomNumber();
            int fs1DraftCount    = NewRandomNumber();
            int fs1ReleasedCount = NewRandomNumber();
            int fs1UpdatedCount  = NewRandomNumber();

            int fs2ApprovedCount = NewRandomNumber();
            int fs2DraftCount    = NewRandomNumber();
            int fs2ReleasedCount = NewRandomNumber();
            int fs2UpdatedCount  = NewRandomNumber();

            decimal fs1ApprovedTotalFunding = NewRandomNumber();
            decimal fs1DraftTotalFunding    = NewRandomNumber();
            decimal fs1ReleasedTotalFunding = NewRandomNumber();
            decimal fs1UpdatedTotalFunding  = NewRandomNumber();

            decimal fs2ApprovedTotalFunding = NewRandomNumber();
            decimal fs2DraftTotalFunding    = NewRandomNumber();
            decimal fs2ReleasedTotalFunding = NewRandomNumber();
            decimal fs2UpdatedTotalFunding  = NewRandomNumber();

            ProviderFundingStreamStatusResponse firstExpectedResponse = NewProviderFundingStreamStatusResponse(_ => _
                                                                                                               .WithFundingStreamId(fundingStreamId1)
                                                                                                               .WithProviderApprovedCount(fs1ApprovedCount)
                                                                                                               .WithProviderReleasedCount(fs1ReleasedCount)
                                                                                                               .WithProviderUpdatedCount(fs1UpdatedCount)
                                                                                                               .WithProviderDraftCount(fs1DraftCount)
                                                                                                               .WithTotalFunding(fs1ApprovedTotalFunding + fs1DraftTotalFunding + fs1ReleasedTotalFunding + fs1UpdatedTotalFunding));

            ProviderFundingStreamStatusResponse secondExpectedResponse = NewProviderFundingStreamStatusResponse(_ => _
                                                                                                                .WithFundingStreamId(fundingStreamId2)
                                                                                                                .WithProviderApprovedCount(fs2ApprovedCount)
                                                                                                                .WithProviderReleasedCount(fs2ReleasedCount)
                                                                                                                .WithProviderUpdatedCount(fs2UpdatedCount)
                                                                                                                .WithProviderDraftCount(fs2DraftCount)
                                                                                                                .WithTotalFunding(fs2ApprovedTotalFunding + fs2DraftTotalFunding + fs2ReleasedTotalFunding + fs2UpdatedTotalFunding));

            GivenThePublishedProvidersForTheSpecificationId(
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId1).WithCount(fs1ApprovedCount).WithStatus(approvedStatus).WithTotalFunding(fs1ApprovedTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId1).WithCount(fs1DraftCount).WithStatus(draftStatus).WithTotalFunding(fs1DraftTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId1).WithCount(fs1ReleasedCount).WithStatus(releasedStatus).WithTotalFunding(fs1ReleasedTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId1).WithCount(fs1UpdatedCount).WithStatus(updatedStatus).WithTotalFunding(fs1UpdatedTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId2).WithCount(fs2ApprovedCount).WithStatus(approvedStatus).WithTotalFunding(fs2ApprovedTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId2).WithCount(fs2DraftCount).WithStatus(draftStatus).WithTotalFunding(fs2DraftTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId2).WithCount(fs2ReleasedCount).WithStatus(releasedStatus).WithTotalFunding(fs2ReleasedTotalFunding)),
                NewPublishedProviderFundingStreamStatus(_ => _.WithFundingStreamId(fundingStreamId2).WithCount(fs2UpdatedCount).WithStatus(updatedStatus).WithTotalFunding(fs2UpdatedTotalFunding)));

            AndTheSpecificationSummaryIsRetrieved(NewSpecificationSummary(s =>
            {
                s.WithId(_specificationId);
                s.WithFundingStreamIds(new[] { fundingStreamId1, fundingStreamId2 });
            }));

            await WhenThePublishedProvidersStatusAreQueried();

            ThenTheResponseShouldBe <OkObjectResult>(_ =>
                                                     ((IEnumerable <ProviderFundingStreamStatusResponse>)_.Value).SequenceEqual(new[]
            {
                firstExpectedResponse,
                secondExpectedResponse
            }, new ProviderFundingStreamStatusResponseComparer()));
        }