public void FlattensTemplateCalculationsAndProviderMetaDataIntoRows(
            CalculateFunding.Models.Publishing.GroupingReason expectedGroupingReason)
        {
            IEnumerable <PublishedFundingOrganisationGrouping> publishedFundingOrganisationGroupings =
                NewPublishedFundingOrganisationGroupings(_ =>
                                                         _.WithPublishedFundingVersions(
                                                             NewPublishedFundingVersions(pfv =>
                                                                                         pfv.WithOrganisationGroupTypeCode(OrganisationGroupTypeCode.LocalAuthority)
                                                                                         .WithOrganisationGroupName("Enfield")
                                                                                         .WithOrganisationGroupIdentifierValue("Enfield Value")
                                                                                         .WithGroupReason(expectedGroupingReason)
                                                                                         .WithPublishedProviderStatus(PublishedFundingStatus.Released)
                                                                                         .WithMajor(1)
                                                                                         .WithAuthor(new Reference {
                Name = "system"
            })
                                                                                         .WithDate("2020-02-05T20:03:55")
                                                                                         .WithFundingLines(
                                                                                             NewFundingLines(fl =>
                                                                                                             fl.WithName("fundingLine1")
                                                                                                             .WithValue(123M),
                                                                                                             fl =>
                                                                                                             fl.WithName("fundingLine2")
                                                                                                             .WithValue(456M)))))
                                                         .WithOrganisationGroupResult(
                                                             NewOrganisationGroupResult(ogp =>
                                                                                        ogp.WithProviders(
                                                                                            _mapper.Map <IEnumerable <Common.ApiClient.Providers.Models.Provider> >(NewProviders(p =>
                                                                                                                                                                                 p.WithName("p1"),
                                                                                                                                                                                 p =>
                                                                                                                                                                                 p.WithName("p2")))))));

            dynamic[] expectedCsvRows =
            {
                new Dictionary <string, object>
                {
                    { "Grouping Reason",expectedGroupingReason.ToString()           },
                    { "Grouping Code",  "LocalAuthority"                            },
                    { "Grouping Identifier Value","Enfield Value"                             },
                    { "Grouping Name",  "Enfield"                                   },
                    { "Allocation Status","Released"                                  },
                    { "Allocation Major Version","1"                                         },
                    { "Allocation Author","system"                                    },
                    { "Allocation DateTime","2020-02-05T20:03:55"                       },
                    { "Provider Count",                                           2 },
                    { "fundingLine1",   123M.ToString(CultureInfo.InvariantCulture) }, //funding lines to be alpha numerically ordered on name
                    { "fundingLine2",   456M.ToString(CultureInfo.InvariantCulture) }
                }
            };

            ExpandoObject[] transformProviderResultsIntoCsvRows = _transformation.Transform(publishedFundingOrganisationGroupings).ToArray();

            transformProviderResultsIntoCsvRows
            .Should()
            .BeEquivalentTo(expectedCsvRows);
        }
예제 #2
0
        public void FlattensTemplateCalculationsAndProviderMetaDataIntoRows(
            CalculateFunding.Models.Publishing.GroupingReason expectedGroupingReason)
        {
            PublishedFundingVersion publishedFunding =
                NewPublishedFundingVersion(pfv =>
                                           pfv.WithOrganisationGroupTypeCode(OrganisationGroupTypeCode.LocalAuthority)
                                           .WithOrganisationGroupName("Enfield")
                                           .WithGroupReason(expectedGroupingReason)
                                           .WithProviderFundings(new [] { "one", "two" })
                                           .WithPublishedProviderStatus(PublishedFundingStatus.Released)
                                           .WithMajor(1)
                                           .WithAuthor(NewReference(rf => rf.WithName("system")))
                                           .WithDate("2020-02-05T20:03:55")
                                           .WithFundingLines(
                                               NewFundingLines(fl =>
                                                               fl.WithName("fundingLine1")
                                                               .WithValue(123M),
                                                               fl =>
                                                               fl.WithName("fundingLine2")
                                                               .WithValue(456M))));

            dynamic[] expectedCsvRows =
            {
                new Dictionary <string, object>
                {
                    { "Grouping Reason",expectedGroupingReason.ToString()           },
                    { "Grouping Code",  "LocalAuthority"                            },
                    { "Grouping Name",  "Enfield"                                   },
                    { "Allocation Status","Released"                                  },
                    { "Allocation Major Version","1"                                         },
                    { "Allocation Author","system"                                    },
                    { "Allocation DateTime","2020-02-05T20:03:55"                       },
                    { "Provider Count",                                           2 },
                    { "fundingLine1",   123M.ToString(CultureInfo.InvariantCulture) }, //funding lines to be alpha numerically ordered on name
                    { "fundingLine2",   456M.ToString(CultureInfo.InvariantCulture) }
                }
            };

            ExpandoObject[] transformProviderResultsIntoCsvRows = _transformation.Transform(new [] { publishedFunding }).ToArray();

            transformProviderResultsIntoCsvRows
            .Should()
            .BeEquivalentTo(expectedCsvRows);
        }
        public async Task GetLatestEarlierPublishedFundingVersionFromVersion()
        {
            string  fundingStreamId             = NewRandomString();
            string  fundingPeriodId             = NewRandomString();
            decimal version                     = NewRandomInteger();
            string  groupTypeIdentifier         = NewRandomString();
            string  groupTypeIdentifierValue    = NewRandomString();
            ModelsGroupingReason groupingReason = NewRandomGroupingReason();

            PublishedFundingVersion expectedLatestEarlierDocument = NewPublishedFundingVersion();

            GivenTheLatestEarlierDocument(@"SELECT
                              TOP 1 *
                        FROM publishedFundingVersion p
                        WHERE p.documentType = 'PublishedFundingVersion'
                        AND StringToNumber(CONCAT(Tostring(p.content.majorVersion), '.', Tostring(p.content.minorVersion))) < @version
                        AND p.content.fundingStreamId = @fundingStreamId
                        AND p.content.fundingPeriod.id = @fundingPeriodId
                        AND p.content.organisationGroupTypeIdentifier = @groupTypeIdentifier
                        AND p.content.organisationGroupIdentifierValue = @groupTypeIdentifierValue
                        AND p.content.groupingReason = @groupingReason
                        AND p.deleted = false
                        ORDER BY p.content.majorVersion DESC, p.content.minorVersion DESC",
                                          expectedLatestEarlierDocument,
                                          ("@fundingPeriodId", fundingPeriodId),
                                          ("@fundingStreamId", fundingStreamId),
                                          ("@version", version),
                                          ("@groupTypeIdentifier", groupTypeIdentifier),
                                          ("@groupTypeIdentifierValue", groupTypeIdentifierValue),
                                          ("@groupingReason", groupingReason.ToString()));

            PublishedFundingVersion actualLatestEarlierDocument = await _repository.GetLatestEarlierPublishedFundingVersionFromVersion(fundingStreamId,
                                                                                                                                       fundingPeriodId,
                                                                                                                                       version,
                                                                                                                                       groupTypeIdentifier,
                                                                                                                                       groupTypeIdentifierValue,
                                                                                                                                       groupingReason);

            actualLatestEarlierDocument
            .Should()
            .BeSameAs(expectedLatestEarlierDocument);
        }
        public async Task GetLatestEarlierPublishedFundingVersion()
        {
            string fundingStreamId              = NewRandomString();
            string fundingPeriodId              = NewRandomString();
            long   timeStamp                    = NewRandomTimeStamp();
            string groupTypeIdentifier          = NewRandomString();
            string groupTypeIdentifierValue     = NewRandomString();
            ModelsGroupingReason groupingReason = NewRandomGroupingReason();

            PublishedFundingVersion expectedLatestEarlierDocument = NewPublishedFundingVersion();

            GivenTheLatestEarlierDocument(@"SELECT
                              TOP 1 *
                        FROM publishedFundingVersion p
                        WHERE p.documentType = 'PublishedFundingVersion'
                        AND p._ts < @sinceTimeStamp                        
                        AND p.content.fundingStreamId = @fundingStreamId
                        AND p.content.fundingPeriod.id = @fundingPeriodId
                        AND p.content.organisationGroupTypeIdentifier = @groupTypeIdentifier
                        AND p.content.organisationGroupIdentifierValue = @groupTypeIdentifierValue
                        AND p.content.groupingReason = @groupingReason
                        AND p.deleted = false
                        ORDER BY p._ts DESC",
                                          expectedLatestEarlierDocument,
                                          ("@fundingPeriodId", fundingPeriodId),
                                          ("@fundingStreamId", fundingStreamId),
                                          ("@sinceTimeStamp", timeStamp),
                                          ("@groupTypeIdentifier", groupTypeIdentifier),
                                          ("@groupTypeIdentifierValue", groupTypeIdentifierValue),
                                          ("@groupingReason", groupingReason.ToString()));

            PublishedFundingVersion actualLatestEarlierDocument = await _repository.GetLatestEarlierPublishedFundingVersion(fundingStreamId,
                                                                                                                            fundingPeriodId,
                                                                                                                            timeStamp,
                                                                                                                            groupTypeIdentifier,
                                                                                                                            groupTypeIdentifierValue,
                                                                                                                            groupingReason);

            actualLatestEarlierDocument
            .Should()
            .BeSameAs(expectedLatestEarlierDocument);
        }
예제 #5
0
        public PublishedFundingVersionBuilder WithGroupReason(CalculateFunding.Models.Publishing.GroupingReason groupingReason)
        {
            _groupingReason = groupingReason;

            return(this);
        }