private void GivenTheFundingCount(PublishedProviderFundingCount fundingCount,
                                   IEnumerable <string> publishedProviderIds,
                                   string specificationId,
                                   params PublishedProviderStatus[] statuses)
 {
     _fundingCountProcessor.GetFundingCount(Arg.Is(publishedProviderIds),
                                            Arg.Is(specificationId),
                                            Arg.Is <PublishedProviderStatus[]>(sts => sts.SequenceEqual(statuses)))
     .Returns(fundingCount);
 }
예제 #2
0
        private async Task <IActionResult> GetProviderBatchCountForStatuses(PublishedProviderIdsRequest providerIds,
                                                                            string specificationId,
                                                                            params PublishedProviderStatus[] statuses)
        {
            PublishedProviderFundingCount fundingCount = await _fundingCountProcessor.GetFundingCount(providerIds.PublishedProviderIds,
                                                                                                      specificationId,
                                                                                                      statuses);

            return(new ObjectResult(fundingCount));
        }
        public async Task GetProviderBatchCountForRelease()
        {
            IEnumerable <string> publishedProviderIds = ArraySegment <string> .Empty;
            string specificationId = NewRandomString();

            PublishedProviderFundingCount expectedFundingCount = NewPublishedProviderFundingCount();

            GivenTheFundingCount(expectedFundingCount, publishedProviderIds, specificationId, PublishedProviderStatus.Approved);

            OkObjectResult result = await WhenTheBatchCountForApprovalIsQueried(publishedProviderIds, specificationId) as OkObjectResult;

            result
            ?.Value
            .Should()
            .BeSameAs(expectedFundingCount);
        }
        public async Task SumsCountAndTotalFundingFromTheCountsFromEachPublishedProviderIdBatch()
        {
            string[] pageOne              = NewRandomPublishedProviderIdsPage().ToArray();
            string[] pageTwo              = NewRandomPublishedProviderIdsPage().ToArray();
            string[] pageThree            = NewRandomPublishedProviderIdsPage().ToArray();
            string[] publishedProviderIds = Join(pageOne, pageTwo, pageThree);

            string specificationId  = NewRandomString();
            string fundingStreamId1 = NewRandomString();
            string fundingStreamId2 = NewRandomString();
            string providerType1    = NewRandomString();
            string providerSubType1 = NewRandomString();
            string providerSubType2 = NewRandomString();
            string laCode1          = NewRandomString();
            string laCode2          = NewRandomString();

            decimal totalFunding1 = NewRandomNumber();
            decimal totalFunding2 = NewRandomNumber();
            decimal totalFunding3 = NewRandomNumber();

            PublishedProviderStatus[] statuses = AsArray(NewRandomStatus(), NewRandomStatus());

            PublishedProviderFunding fundingOne = NewPublishedProviderFunding(_ => _.WithSpecificationId(specificationId)
                                                                              .WithPublishedProviderId(pageOne.First())
                                                                              .WithFundingStreamId(fundingStreamId1)
                                                                              .WithProviderType(providerType1)
                                                                              .WithProviderSubType(providerSubType1)
                                                                              .WithTotalFunding(totalFunding1)
                                                                              .WithLaCode(laCode1));
            PublishedProviderFunding fundingTwo = NewPublishedProviderFunding(_ => _.WithSpecificationId(specificationId)
                                                                              .WithPublishedProviderId(pageTwo.Last())
                                                                              .WithFundingStreamId(fundingStreamId2)
                                                                              .WithProviderType(providerType1)
                                                                              .WithProviderSubType(providerSubType2)
                                                                              .WithTotalFunding(totalFunding2)
                                                                              .WithLaCode(laCode2));
            PublishedProviderFunding fundingThree = NewPublishedProviderFunding(_ => _.WithSpecificationId(specificationId)
                                                                                .WithPublishedProviderId(pageThree.Skip(1).First())
                                                                                .WithFundingStreamId(fundingStreamId1)
                                                                                .WithProviderType(providerType1)
                                                                                .WithProviderSubType(providerSubType1)
                                                                                .WithTotalFunding(totalFunding3)
                                                                                .WithLaCode(laCode1));

            PublishedProviderFunding[] fundings = AsArray(fundingOne, fundingTwo, fundingThree);

            PublishedProviderFundingCount expectedTotalCount = new PublishedProviderFundingCount
            {
                Count        = fundings.Count(),
                TotalFunding = fundings.Sum(_ => _.TotalFunding)
            };

            GivenThePublishedProvidersFunding(pageOne, specificationId, statuses, new[] { fundingOne });
            AndThePublishedProviderFundingCount(pageTwo, specificationId, statuses, new[] { fundingTwo });
            AndThePublishedProviderFundingCount(pageThree, specificationId, statuses, new[] { fundingThree });

            PublishedProviderFundingCount actualFundingCount = await WhenTheTotalFundingCountIsProcessed(publishedProviderIds, specificationId, statuses);

            actualFundingCount
            .Count
            .Should()
            .Be(fundings.Length);

            actualFundingCount
            .ProviderTypesCount
            .Should()
            .Be(2);

            actualFundingCount
            .ProviderTypes
            .Should()
            .BeEquivalentTo(new[]
            {
                new ProviderTypeSubType()
                {
                    ProviderType = providerType1, ProviderSubType = providerSubType1
                },
                new ProviderTypeSubType()
                {
                    ProviderType = providerType1, ProviderSubType = providerSubType2
                }
            });

            actualFundingCount
            .LocalAuthoritiesCount
            .Should()
            .Be(2);

            actualFundingCount
            .LocalAuthorities
            .Should()
            .BeEquivalentTo(new[] { laCode1, laCode2 });

            actualFundingCount
            .FundingStreamsFundings
            .Should()
            .BeEquivalentTo(new[]
            {
                new PublishedProivderFundingStreamFunding()
                {
                    FundingStreamId = fundingStreamId1, TotalFunding = totalFunding1 + totalFunding3
                },
                new PublishedProivderFundingStreamFunding()
                {
                    FundingStreamId = fundingStreamId2, TotalFunding = totalFunding2
                }
            });

            actualFundingCount
            .TotalFunding
            .Should()
            .Be(totalFunding1 + totalFunding2 + totalFunding3);
        }