public async Task QueryMethodDelegatesToApiClientAndReturnsProvidersFromResponseContentProviderVersion()
        {
            ApiProvider firstExpectedProvider  = NewApiProvider();
            ApiProvider secondExpectedProvider = NewApiProvider();
            ApiProvider thirdExpectedProvider  = NewApiProvider();
            ApiProvider fourthExpectedProvider = NewApiProvider();
            ApiProvider fifthExpectedProvider  = NewApiProvider();

            string providerVersionId = NewRandomString();

            GivenTheApiResponseProviderVersionContainsTheProviders(providerVersionId,
                                                                   firstExpectedProvider,
                                                                   secondExpectedProvider,
                                                                   thirdExpectedProvider,
                                                                   fourthExpectedProvider,
                                                                   fifthExpectedProvider);

            IEnumerable <Provider> providers = await WhenTheProvidersAreQueriedByVersionId(providerVersionId);

            IEnumerable <Provider> expectedProviders = _mapper.Map <IEnumerable <Provider> >(new ApiProvider[] { firstExpectedProvider,
                                                                                                                 secondExpectedProvider,
                                                                                                                 thirdExpectedProvider,
                                                                                                                 fourthExpectedProvider,
                                                                                                                 fifthExpectedProvider });

            providers
            .Should()
            .BeEquivalentTo(expectedProviders);
        }
        public async Task WhenPublishedProvidersRequestedAndPublishedProvidersExistForSpecificationPublishedProvidersReturned()
        {
            Provider successor = NewProvider();
            IEnumerable <PublishedProvider> publishedProviders = new[] {
                NewPublishedProvider(_ => _.WithCurrent(NewPublishedProviderVersion(ppv => ppv.WithProvider(NewProvider())))),
                NewPublishedProvider(_ => _.WithCurrent(NewPublishedProviderVersion(ppv => ppv.WithProvider(NewProvider())))),
                NewPublishedProvider(_ => _.WithCurrent(NewPublishedProviderVersion(ppv => ppv.WithProvider(NewProvider(p => p.WithSuccessor(successor.ProviderId))))))
            };

            IEnumerable <ApiProvider> apiproviders = _mapper.Map <IEnumerable <ApiProvider> >(publishedProviders.Select(_ => _.Current.Provider));

            ApiProvider excludedProvider = _mapper.Map <ApiProvider>(NewProvider());

            apiproviders = apiproviders.Concat(new[] { excludedProvider });

            publishedProviders = publishedProviders.Concat(new[] { NewPublishedProvider(_ => _.WithCurrent(NewPublishedProviderVersion(ppv => ppv.WithProvider(successor)))) });

            string providerVersionId           = NewRandomString();
            string specificationId             = NewRandomString();
            SpecificationSummary specification = new SpecificationSummary {
                Id            = specificationId,
                FundingPeriod = new Reference {
                    Id = FundingPeriodId
                },
                ProviderVersionId = providerVersionId
            };

            GivenTheApiResponseProviderVersionContainsTheProviders(providerVersionId, apiproviders.ToArray());

            AndPublishedProvidersForFundingStreamAndFundingPeriod(publishedProviders);

            AndTheSecondApiResponseScopedProviderIdsContainsProviderIds(specificationId, apiproviders.Select(_ => _.ProviderId));

            _jobManagement
            .QueueJobAndWait(Arg.Any <Func <Task <bool> > >(), JobConstants.DefinitionNames.PopulateScopedProvidersJob, specificationId, Arg.Any <string>(), ServiceBusConstants.TopicNames.JobNotifications)
            .Returns(true);

            (IDictionary <string, PublishedProvider> PublishedProvidersForFundingStream,
             IDictionary <string, PublishedProvider> ScopedPublishedProviders) = await WhenPublishedProvidersAreReturned(specification);

            PublishedProvidersForFundingStream.Count()
            .Should()
            .Be(4);

            PublishedProvidersForFundingStream.Keys
            .Should()
            .BeEquivalentTo(publishedProviders.Select(_ => _.Current.ProviderId));

            ScopedPublishedProviders.Count()
            .Should()
            .Be(4);

            ScopedPublishedProviders.Keys
            .Should()
            .BeEquivalentTo(publishedProviders.Select(_ => _.Current.ProviderId));
        }