Example #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();
        }
Example #2
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);
        }