public async Task ReturnsErrorMessageWhenTrustIdMisatch()
        {
            // Arrange
            string specificationId   = NewRandomString();
            string providerVersionId = NewRandomString();
            string fundingStreamId   = NewRandomString();
            string fundingPeriodId   = NewRandomString();

            string providerId1            = NewRandomString();
            int    majorVersion1          = NewRandomInt();
            int    minorVersion1          = NewRandomInt();
            string providerId2            = NewRandomString();
            int    majorVersion2          = NewRandomInt();
            int    minorVersion2          = NewRandomInt();
            string identifierValue1       = NewRandomString();
            string identifierValue2       = NewRandomString();
            string fundingConfigurationId = NewRandomString();

            Generators.OrganisationGroup.Enums.OrganisationGroupTypeIdentifier groupTypeIdentifier = Generators.OrganisationGroup.Enums.OrganisationGroupTypeIdentifier.UKPRN;

            string errorMessage = $"TrustIds {groupTypeIdentifier}-{identifierValue2} not matched.";

            SpecificationSummary specificationSummary = NewSpecificationSummary(_ => _
                                                                                .WithId(specificationId)
                                                                                .WithProviderVersionId(providerVersionId)
                                                                                .WithPublishStatus(PublishStatus.Approved));
            IEnumerable <PublishedProvider> publishedProviders = new[]
            {
                NewPublishedProvider(_ => _
                                     .WithCurrent(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                              .WithFundingPeriodId(fundingPeriodId)))
                                     .WithReleased(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                               .WithFundingPeriodId(fundingPeriodId)
                                                                               .WithProviderId(providerId1)
                                                                               .WithMajorVersion(majorVersion1)
                                                                               .WithMinorVersion(minorVersion1)))),
                NewPublishedProvider(_ => _
                                     .WithCurrent(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                              .WithFundingPeriodId(fundingPeriodId)))
                                     .WithReleased(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                               .WithFundingPeriodId(fundingPeriodId)
                                                                               .WithProviderId(providerId2)
                                                                               .WithMajorVersion(majorVersion2)
                                                                               .WithMinorVersion(minorVersion2))))
            };

            IEnumerable <Provider> providers = new[]
            {
                NewProvider(_ => _.WithProviderId(providerId1)),
                NewProvider(_ => _.WithProviderId(providerId2))
            };

            IEnumerable <OrganisationGroupResult> organisationGroupResults = new[]
            {
                NewOrganisationGroupResult(_ => _
                                           .WithIdentifiers(new []
                {
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(identifierValue1)),
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(NewRandomString()))
                })),
                NewOrganisationGroupResult(_ => _
                                           .WithIdentifiers(new []
                {
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(identifierValue2)),
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(NewRandomString()))
                }))
            };

            IEnumerable <PublishedFunding> publishedFundings = new[]
            {
                NewPublishedFunding(_ => _
                                    .WithCurrent(NewPublishedFundingVersion(fv => fv.WithProviderFundings(new []
                {
                    $"{fundingStreamId}-{fundingPeriodId}-{providerId1}-{majorVersion1}_{minorVersion1}",
                    $"{fundingStreamId}-{fundingPeriodId}-{providerId2}-{majorVersion2}_{minorVersion2}"
                })
                                                                            .WithGroupReason(CalculateFunding.Models.Publishing.GroupingReason.Payment)
                                                                            .WithOrganisationGroupIdentifierValue(identifierValue1)
                                                                            .WithOrganisationGroupTypeIdentifier(groupTypeIdentifier)))),
                NewPublishedFunding(_ => _
                                    .WithCurrent(NewPublishedFundingVersion(fv => fv.WithProviderFundings(new [] { $"{fundingStreamId}-{fundingPeriodId}-{providerId1}-{majorVersion1}_{minorVersion1}", NewRandomString() })
                                                                            .WithGroupReason(CalculateFunding.Models.Publishing.GroupingReason.Payment)
                                                                            .WithOrganisationGroupIdentifierValue(identifierValue2)
                                                                            .WithOrganisationGroupTypeIdentifier(groupTypeIdentifier))))
            };

            // Act
            await WhenThePreRequisitesAreChecked(specificationSummary, publishedProviders, providers);

            // Assert
            publishedProviders
            .All(_ => _.Current.HasErrors);
        }
        public async Task ReturnsErrorMessageWhenTrustIdMisatch()
        {
            // Arrange
            string specificationId   = NewRandomString();
            string providerVersionId = NewRandomString();
            string fundingStreamId   = NewRandomString();
            string fundingPeriodId   = NewRandomString();

            string providerId1            = NewRandomString();
            int    majorVersion1          = NewRandomInt();
            int    minorVersion1          = NewRandomInt();
            string providerId2            = NewRandomString();
            int    majorVersion2          = NewRandomInt();
            int    minorVersion2          = NewRandomInt();
            string identifierValue1       = NewRandomString();
            string identifierValue2       = NewRandomString();
            string fundingConfigurationId = NewRandomString();

            Generators.OrganisationGroup.Enums.OrganisationGroupTypeIdentifier groupTypeIdentifier = Generators.OrganisationGroup.Enums.OrganisationGroupTypeIdentifier.UKPRN;

            string summaryErrorMessage  = "TrustId  not matched";
            string detailedErrorMessage = $"TrustId {groupTypeIdentifier}-{identifierValue2} not matched.";

            SpecificationSummary specificationSummary = NewSpecificationSummary(_ => _.WithId(specificationId).WithProviderVersionId(providerVersionId));
            PublishedProvider    publishedProvider    = NewPublishedProvider(_ => _
                                                                             .WithCurrent(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                                                                      .WithFundingPeriodId(fundingPeriodId)))
                                                                             .WithReleased(NewPublishedProviderVersion(pv => pv.WithFundingStreamId(fundingStreamId)
                                                                                                                       .WithFundingPeriodId(fundingPeriodId)
                                                                                                                       .WithProviderId(providerId2)
                                                                                                                       .WithMajorVersion(majorVersion2)
                                                                                                                       .WithMinorVersion(minorVersion2))));

            IEnumerable <Provider> providers = new[]
            {
                NewProvider(_ => _.WithProviderId(providerId1)),
                NewProvider(_ => _.WithProviderId(providerId2))
            };

            IEnumerable <OrganisationGroupResult> organisationGroupResults = new[]
            {
                NewOrganisationGroupResult(_ => _
                                           .WithIdentifiers(new []
                {
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(identifierValue1)),
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(NewRandomString()))
                })),
                NewOrganisationGroupResult(_ => _
                                           .WithIdentifiers(new []
                {
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(identifierValue2)),
                    NewOrganisationIdentifier(i => i.WithType(groupTypeIdentifier).WithValue(NewRandomString()))
                }))
            };

            IEnumerable <PublishedFunding> publishedFundings = new[]
            {
                NewPublishedFunding(_ => _
                                    .WithCurrent(NewPublishedFundingVersion(fv => fv.WithProviderFundings(new []
                {
                    $"{fundingStreamId}-{fundingPeriodId}-{providerId1}-{majorVersion1}_{minorVersion1}",
                    $"{fundingStreamId}-{fundingPeriodId}-{providerId2}-{majorVersion2}_{minorVersion2}"
                })
                                                                            .WithGroupReason(CalculateFunding.Models.Publishing.GroupingReason.Payment)
                                                                            .WithOrganisationGroupIdentifierValue(identifierValue1)
                                                                            .WithOrganisationGroupTypeIdentifier(groupTypeIdentifier)))),
                NewPublishedFunding(_ => _
                                    .WithCurrent(NewPublishedFundingVersion(fv => fv.WithProviderFundings(new [] { $"{fundingStreamId}-{fundingPeriodId}-{providerId1}-{majorVersion1}_{minorVersion1}", NewRandomString() })
                                                                            .WithGroupReason(CalculateFunding.Models.Publishing.GroupingReason.Payment)
                                                                            .WithOrganisationGroupIdentifierValue(identifierValue2)
                                                                            .WithOrganisationGroupTypeIdentifier(groupTypeIdentifier))))
            };

            FundingConfiguration fundingConfiguration = NewFundingConfiguration(_ => _.WithId(fundingConfigurationId));

            GivenTheCurrentPublishedFundingForTheSpecification(specificationId, publishedFundings);
            GivenTheOrganisationGroupsForTheFundingConfiguration(fundingConfiguration, providers, providerVersionId, organisationGroupResults);

            // Act
            await WhenErrorsAreDetectedOnThePublishedProvider(publishedProvider, providers, specificationId, providerVersionId, fundingConfiguration, publishedFundings);

            publishedProvider.Current
            .Errors
            .Should()
            .NotBeNullOrEmpty();

            publishedProvider
            .Current
            .Errors
            .First()
            .DetailedErrorMessage
            .Should()
            .Be(detailedErrorMessage);

            publishedProvider
            .Current
            .Errors
            .First()
            .SummaryErrorMessage
            .Should()
            .Be(summaryErrorMessage);
        }