private void AndPublishedProviders()
        {
            Provider[] providers = new[] { NewProvider(),
                                           NewProvider(),
                                           NewProvider() };

            TemplateFundingLine templateFundingLine = _fundingLines[0];

            _publishedProviders = providers.Select(_ =>
                                                   NewPublishedProvider(pp => pp.WithCurrent(
                                                                            NewPublishedProviderVersion(ppv => ppv
                                                                                                        .WithProvider(_)
                                                                                                        .WithProviderId(_.ProviderId)
                                                                                                        .WithTotalFunding(9)
                                                                                                        .WithFundingLines(NewFundingLine(fl => fl.WithFundingLineCode(templateFundingLine.FundingLineCode)
                                                                                                                                         .WithTemplateLineId(templateFundingLine.TemplateLineId)
                                                                                                                                         .WithValue(9)))
                                                                                                        .WithFundingCalculations(NewFundingCalculation(fc => fc.WithTemplateCalculationId(_calculationTemplateIds[0].TemplateCalculationId)
                                                                                                                                                       .WithValue(_calculationTemplateIds[0].Value)),
                                                                                                                                 NewFundingCalculation(fc => fc.WithTemplateCalculationId(_calculationTemplateIds[1].TemplateCalculationId)
                                                                                                                                                       .WithValue(_calculationTemplateIds[1].Value)),
                                                                                                                                 NewFundingCalculation(fc => fc.WithTemplateCalculationId(_calculationTemplateIds[2].TemplateCalculationId)
                                                                                                                                                       .WithValue(_calculationTemplateIds[2].Value)))
                                                                                                        .WithPublishedProviderStatus(PublishedProviderStatus.Approved)
                                                                                                        .WithVariationReasons(new[] { VariationReason.AuthorityFieldUpdated })
                                                                                                        )))).ToList();

            _providerService
            .GetPublishedProviders(Arg.Is <Reference>(_ => _.Id == FundingStreamId),
                                   _specificationSummary)
            .Returns((_publishedProviders.ToDictionary(_ => _.Current.ProviderId),
                      _publishedProviders.ToDictionary(_ => _.Current.ProviderId)));
        }
예제 #2
0
        private static FundingStructureItem RecursivelyAddFundingLines(IEnumerable <FundingLine> fundingLines,
                                                                       List <TemplateMappingItem> templateMappingItems,
                                                                       List <CalculationMetadata> calculationMetadata,
                                                                       int level,
                                                                       FundingLine fundingLine,
                                                                       List <string> calculationIdsWithError)
        {
            level++;

            List <FundingStructureItem> innerFundingStructureItems = new List <FundingStructureItem>();

            // If funding line has calculations, recursively add them to list of inner FundingStructureItems
            if (fundingLine.Calculations != null && fundingLine.Calculations.Any())
            {
                foreach (TemplateCalculation calculation in fundingLine.Calculations)
                {
                    innerFundingStructureItems.Add(
                        RecursivelyMapCalculationsToFundingStructureItem(
                            calculation,
                            level,
                            templateMappingItems,
                            calculationMetadata,
                            calculationIdsWithError));
                }
            }

            // If funding line has more funding lines, recursively add them to list of inner FundingStructureItems
            if (fundingLine.FundingLines != null && fundingLine.FundingLines.Any())
            {
                foreach (FundingLine line in fundingLines)
                {
                    innerFundingStructureItems.Add(RecursivelyAddFundingLines(
                                                       line.FundingLines,
                                                       templateMappingItems,
                                                       calculationMetadata,
                                                       level,
                                                       line,
                                                       calculationIdsWithError));
                }
            }

            string status =
                innerFundingStructureItems.FirstOrDefault(f => f.CalculationPublishStatus == "Error") != null
                    ? "Error"
                    : null;

            // Add FundingStructureItem
            FundingStructureItem fundingStructureItem = MapToFundingStructureItem(
                level,
                fundingLine.Name,
                fundingLine.FundingLineCode,
                fundingLine.TemplateLineId,
                FundingStructureType.FundingLine,
                null,
                null,
                status,
                innerFundingStructureItems.Any() ? innerFundingStructureItems : null);

            return(fundingStructureItem);
        }
        private SchemaJsonFundingLine BuildSchemaJsonFundingLines(IEnumerable <FundingLine> fundingLines,
                                                                  TemplateFundingLine templateFundingLine)
        {
            FundingLine publishedFundingLine = fundingLines.FirstOrDefault(_ => _.TemplateLineId == templateFundingLine.TemplateLineId);

            return(new SchemaJsonFundingLine
            {
                Name = templateFundingLine.Name,
                FundingLineCode = templateFundingLine.FundingLineCode,
                Value = publishedFundingLine.Value.DecimalAsObject(),
                TemplateLineId = templateFundingLine.TemplateLineId,
                Type = templateFundingLine.Type.ToString(),
                DistributionPeriods = publishedFundingLine.DistributionPeriods?.Where(_ => _ != null).Select(distributionPeriod => new
                {
                    Value = distributionPeriod.Value.DecimalAsObject(),
                    distributionPeriod.DistributionPeriodId,
                    ProfilePeriods = distributionPeriod.ProfilePeriods?.Where(_ => _ != null).Select(profilePeriod => new
                    {
                        Type = profilePeriod.Type.ToString(),
                        profilePeriod.TypeValue,
                        profilePeriod.Year,
                        profilePeriod.Occurrence,
                        ProfiledValue = profilePeriod.ProfiledValue.DecimalAsObject(),
                        profilePeriod.DistributionPeriodId
                    }).ToArray()
                }).ToArray() ?? new dynamic[0]
            });
        }
        private void AndTheTemplateContentsCalculation(TemplateMappingItem mappingItem,
                                                       TemplateMetadataContents templateMetadataContents,
                                                       TemplateCalculation calculation)
        {
            calculation.TemplateCalculationId = mappingItem.TemplateId;

            FundingLine fundingLine = templateMetadataContents.RootFundingLines.First();

            fundingLine.Calculations = fundingLine.Calculations.Concat(new[]
            {
                calculation
            });
        }
 private dynamic ToFundingLine(TemplateFundingLine fundingLine, IEnumerable <FundingLine> fundingLineValues, TemplateMapping templateMapping, IEnumerable <FundingCalculation> calculationResults, IEnumerable <FundingReferenceData> referenceData, string providerId)
 {
     return(new
     {
         fundingLine.Name,
         fundingLine.FundingLineCode,
         Value = fundingLineValues.Where(x => x.TemplateLineId == fundingLine.TemplateLineId)?.Single().Value.DecimalAsObject(),
         fundingLine.TemplateLineId,
         Type = fundingLine.Type.ToString(),
         Calculations = fundingLine.Calculations?.Select(x => ToCalculation(x, templateMapping, calculationResults, referenceData, providerId)),
         FundingLines = fundingLine.FundingLines?.Select(x => ToFundingLine(x, fundingLineValues, templateMapping, calculationResults, referenceData, providerId)),
         fundingLineValues.Where(x => x.TemplateLineId == fundingLine.TemplateLineId)?.Single().DistributionPeriods
     });
 }
예제 #6
0
        private dynamic ToFundingLine(TemplateFundingLine fundingLine,
                                      IEnumerable <FundingLine> fundingLineValues)
        {
            FundingLine fundingLineValue = fundingLineValues.First(_ =>
                                                                   _.TemplateLineId == fundingLine.TemplateLineId);

            return(new
            {
                fundingLine.Name,
                fundingLine.FundingLineCode,
                Value = fundingLineValue.Value.DecimalAsObject(),
                fundingLine.TemplateLineId,
                Type = fundingLine.Type.ToString(),
                fundingLineValue.DistributionPeriods
            });
        }
예제 #7
0
        private static bool ContainsCalculation(TemplateFundingLine fundingLine,
                                                uint templateId)
        {
            foreach (TemplateCalculation calculation in fundingLine.Calculations ?? ArraySegment <TemplateCalculation> .Empty)
            {
                if (ContainsCalculation(calculation, templateId))
                {
                    return(true);
                }
            }

            foreach (TemplateFundingLine childFundingLine in fundingLine.FundingLines ?? ArraySegment <TemplateFundingLine> .Empty)
            {
                if (ContainsCalculation(childFundingLine, templateId))
                {
                    return(true);
                }
            }

            return(false);
        }