Ejemplo n.º 1
0
        public async Task GenerateTotals_GivenValidTemplateMetadataContentsAndProvidersButMissingCalculations_EmptyGeneratedProviderResultsReturned()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ITemplateMetadataGenerator templateMetaDataGenerator = CreateTemplateGenerator(logger);

            TemplateMetadataContents contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Services.Publishing.UnitTests.Resources.exampleFundingLineTemplate1.json"));

            IMapper mapper = CreateMapper();

            FundingLineTotalAggregator fundingLineTotalAggregator = new FundingLineTotalAggregator(new Mock <IFundingLineRoundingSettings>().Object);

            TemplateMapping mapping = CreateTemplateMappings();

            PublishedProviderDataGenerator publishedProviderDataGenerator = new PublishedProviderDataGenerator(logger, fundingLineTotalAggregator, mapper);

            //Act
            Dictionary <string, ProviderCalculationResult> providerCalculationResults = new Dictionary <string, ProviderCalculationResult>();

            IDictionary <string, GeneratedProviderResult> generatedProviderResult = publishedProviderDataGenerator.Generate(contents, mapping, GetProviders(), providerCalculationResults);

            generatedProviderResult.Any()
            .Should()
            .BeFalse();
        }
        private IEnumerable <AggregateFundingLine> WhenTheSchema1_1FundingLinesAreAggregated()
        {
            ITemplateMetadataGenerator templateMetaDataGenerator = CreateSchema11TemplateGenerator();

            _contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Services.Publishing.UnitTests.Resources.exampleProviderTemplate1_Schema1_1.json"));

            return(_fundingValueAggregator.GetTotals(_contents, GetProviderVersions("_Schema1_1")));
        }
        public void GenerateTotals_GivenValidTemplateMetadataContentsAndCalculations_ReturnsFundingLines()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ITemplateMetadataGenerator templateMetaDataGenerator = CreateTemplateGenerator(logger);

            TemplateMetadataContents contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Services.Publishing.UnitTests.Resources.exampleFundingLineTemplate1.json"));

            Mock <IFundingLineRoundingSettings> rounding = new Mock <IFundingLineRoundingSettings>();

            rounding.Setup(_ => _.DecimalPlaces)
            .Returns(2);

            FundingLineTotalAggregator fundingLineTotalAggregator = new FundingLineTotalAggregator(rounding.Object);

            TemplateMapping mapping = CreateTemplateMappings();

            //Act
            GeneratorModels.FundingValue fundingValue = fundingLineTotalAggregator.GenerateTotals(contents, mapping.TemplateMappingItems.ToDictionary(_ => _.TemplateId), CreateCalculations(mapping).ToDictionary(_ => _.Id));

            IEnumerable <GeneratorModels.FundingLine> fundingLines = fundingValue.FundingLines.Flatten(_ => _.FundingLines);

            //Assert
            fundingLines.Single(_ => _.TemplateLineId == 1).Value
            .Should()
            .Be(16200.64M);

            fundingLines.Single(_ => _.TemplateLineId == 2).Value
            .Should()
            .Be(8000M);

            fundingLines.Single(_ => _.TemplateLineId == 3).Value
            .Should()
            .Be(3200M);

            fundingLines.Single(_ => _.TemplateLineId == 4).Value
            .Should()
            .Be(5000.64M);

            fundingLines.Single(_ => _.TemplateLineId == 5).Value
            .Should()
            .Be(null);

            fundingLines.Single(_ => _.TemplateLineId == 6).Value
            .Should()
            .Be(8000M);

            fundingLines.Single(_ => _.TemplateLineId == 7).Value
            .Should()
            .Be(500M);

            fundingLines.Single(_ => _.TemplateLineId == 8).Value
            .Should()
            .Be(1200M);
        }
Ejemplo n.º 4
0
        private async Task <TemplateMetadataContents> GetTemplateMetadataContents(string specificationId,
                                                                                  string fundingStreamId)
        {
            ApiResponse <SpecificationSummary> specificationResponse = await _specificationResilience.ExecuteAsync(()
                                                                                                                   => _specifications.GetSpecificationSummaryById(specificationId));

            SpecificationSummary specification = specificationResponse.Content;

            string templateVersion = specification.TemplateIds[fundingStreamId];

            ApiResponse <FundingTemplateContents> templateContentsRequest = await _policiesResilience.ExecuteAsync(()
                                                                                                                   => _policies.GetFundingTemplate(fundingStreamId, specification.FundingPeriod.Id, templateVersion));

            FundingTemplateContents fundingTemplateContents = templateContentsRequest.Content;

            string schemaVersion = fundingTemplateContents.SchemaVersion ?? fundingTemplateContents.Metadata?.SchemaVersion;

            ITemplateMetadataGenerator templateContents = _templateMetadataResolver.GetService(schemaVersion);

            return(templateContents.GetMetadata(fundingTemplateContents.TemplateFileContents));
        }
        public void GetTotals_GivenValidPublishedProviderVersions_ReturnsFundingLines()
        {
            //Arrange
            ITemplateMetadataGenerator templateMetaDataGenerator = CreateSchema10TemplateGenerator();

            _contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Services.Publishing.UnitTests.Resources.exampleProviderTemplate1_Schema1_0.json"));

            //Act
            IEnumerable <AggregateFundingLine> fundingLines = _fundingValueAggregator.GetTotals(_contents, GetProviderVersions());

            //Assert
            fundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 1).First().Value
            .Should()
            .Be(6000.975M);

            fundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 1).First().Calculations.Where(x => x.TemplateCalculationId == 156).First().Calculations.Where(x => x.TemplateCalculationId == 152).First().Value
            .Should()
            .Be(4590000.975M);

            fundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 1).First().Calculations.Where(x => x.TemplateCalculationId == 156).First().Calculations.Where(x => x.TemplateCalculationId == 157 && x.Value != null).IsNullOrEmpty()
            .Should()
            .BeTrue();

            fundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 126).First().Value
            .Should()
            .Be(127000.325M);

            fundingLines.First().FundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 1).First().Value
            .Should()
            .Be(6000.975M);

            fundingLines.First().FundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 1).First().Calculations.Where(x => x.TemplateCalculationId == 156).First().Calculations.Where(x => x.TemplateCalculationId == 152).First().Value
            .Should()
            .Be(4590000.975M);

            fundingLines.First().FundingLines.First().Calculations.Where(x => x.TemplateCalculationId == 126).First().Value
            .Should()
            .Be(127000.325M);
        }
        public void GenerateContents_GivenValidPublishedProviderVersion_ReturnsValidJson()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ITemplateMetadataGenerator templateMetaDataGenerator = CreateTemplateGenerator(logger);

            TemplateMetadataContents contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Generators.Schema10.UnitTests.Resources.exampleProviderTemplate1.json"));

            PublishedProviderContentsGenerator publishedProviderContentsGenerator = new PublishedProviderContentsGenerator();

            //Act
            string publishedcontents = publishedProviderContentsGenerator.GenerateContents(GetProviderVersion(), contents, GetTemplateMapping());

            //Assert
            string expectedOutput = GetResourceString("CalculateFunding.Generators.Schema10.UnitTests.Resources.exampleProviderOutput1.json").Prettify();

            publishedcontents
            .Prettify()
            .Should()
            .Be(expectedOutput);
        }
Ejemplo n.º 7
0
        public async Task GenerateTotals_GivenValidTemplateMetadataContentsCalculationsAndProviders_ReturnsFundingLines()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ITemplateMetadataGenerator templateMetaDataGenerator = CreateTemplateGenerator(logger);

            TemplateMetadataContents contents = templateMetaDataGenerator.GetMetadata(GetResourceString("CalculateFunding.Services.Publishing.UnitTests.Resources.exampleFundingLineTemplate1.json"));

            IMapper mapper = CreateMapper();

            Mock <IFundingLineRoundingSettings> rounding = new Mock <IFundingLineRoundingSettings>();

            rounding.Setup(_ => _.DecimalPlaces)
            .Returns(2);

            FundingLineTotalAggregator fundingLineTotalAggregator = new FundingLineTotalAggregator(rounding.Object);

            TemplateMapping mapping = CreateTemplateMappings();

            PublishedProviderDataGenerator publishedProviderDataGenerator = new PublishedProviderDataGenerator(logger, fundingLineTotalAggregator, mapper);

            //Act
            IDictionary <string, GeneratedProviderResult> generatedProviderResult = publishedProviderDataGenerator.Generate(contents, mapping, GetProviders(), CreateCalculations(mapping));

            //Assert
            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 1).Value
            .Should()
            .Be(16200.64M);     //the 5000.635 figure should be midpoint rounded away from zero to 5000.64

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 1).Value
            .Should()
            .Be(1.704M);     //should be no rounding as is not Cash calc (is pupil number)

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 2).Value
            .Should()
            .Be(8000M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 2).Value
            .Should()
            .Be(500M);

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 3).Value
            .Should()
            .Be(3200M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 3).Value
            .Should()
            .Be(1200M);

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 4).Value
            .Should()
            .Be(5000.64M);

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 5).Value
            .Should()
            .Be(null);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 5).Value
            .Should()
            .Be(5000.64M);    //mid point rounded away from zero to next pence

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 6).Value
            .Should()
            .Be(8000M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 6).Value
            .Should()
            .Be(80M);

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 7).Value
            .Should()
            .Be(500M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 7).Value
            .Should()
            .Be(20M);

            generatedProviderResult["1234"].FundingLines.Single(_ => _.TemplateLineId == 8).Value
            .Should()
            .Be(1200M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 8).Value
            .Should()
            .Be(8000M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 9).Value
            .Should()
            .Be(300M);

            generatedProviderResult["1234"].Calculations.Single(_ => _.TemplateCalculationId == 10).Value
            .Should()
            .Be(1500M);
        }