Пример #1
0
        public void Register(string schemaVersion, ITemplateMetadataGenerator templateMetadataGenerator)
        {
            Guard.IsNullOrWhiteSpace(schemaVersion, nameof(schemaVersion));
            Guard.ArgumentNotNull(templateMetadataGenerator, nameof(templateMetadataGenerator));

            _supportedVersions.TryAdd(schemaVersion, templateMetadataGenerator);
        }
Пример #2
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();
        }
Пример #3
0
        public void TemplateMetadataResolver_GivenGeneratorRegisteredInCorrectly_NoGeneratorReturned()
        {
            //Arrange
            Exception exception = null;

            TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver();

            //Act
            templateMetadataResolver.Register("2.0", CreateTemplateGenerator(_schemaVersion));

            bool contains = templateMetadataResolver.Contains(_schemaVersion);

            try
            {
                ITemplateMetadataGenerator generator = templateMetadataResolver.GetService(_schemaVersion);
            }
            catch (Exception ex)
            {
                exception = ex;
            }

            //Assert
            contains
            .Should()
            .Be(false);

            exception.Message
            .Should()
            .Be($"Unable to find a registered resolver for schema version : {_schemaVersion}");
        }
        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);
        }
        public async Task <IActionResult> SaveFundingTemplate(string actionName, string controllerName, string template, string fundingStreamId, string fundingPeriodId, string templateVersion)
        {
            Guard.IsNullOrWhiteSpace(actionName, nameof(actionName));
            Guard.IsNullOrWhiteSpace(controllerName, nameof(controllerName));
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));
            Guard.IsNullOrWhiteSpace(templateVersion, nameof(templateVersion));

            //Already checked for null above when getting body
            if (template.Trim() == string.Empty)
            {
                return(new BadRequestObjectResult("Null or empty funding template was provided."));
            }

            FundingTemplateValidationResult validationResult = await _fundingTemplateValidationService.ValidateFundingTemplate(template, fundingStreamId, fundingPeriodId, templateVersion);

            if (!validationResult.IsValid)
            {
                return(validationResult.AsBadRequest());
            }

            ITemplateMetadataGenerator templateMetadataGenerator = _templateMetadataResolver.GetService(validationResult.SchemaVersion);

            ValidationResult validationGeneratorResult = templateMetadataGenerator.Validate(template);

            if (!validationGeneratorResult.IsValid)
            {
                return(validationGeneratorResult.PopulateModelState());
            }

            string blobName = GetBlobNameFor(validationResult.FundingStreamId, validationResult.FundingPeriodId, validationResult.TemplateVersion);

            try
            {
                byte[] templateFileBytes = Encoding.UTF8.GetBytes(template);

                await SaveFundingTemplateVersion(blobName, templateFileBytes);

                string cacheKey = $"{CacheKeys.FundingTemplatePrefix}{validationResult.FundingStreamId}-{validationResult.FundingPeriodId}-{validationResult.TemplateVersion}".ToLowerInvariant();
                await _cacheProviderPolicy.ExecuteAsync(() => _cacheProvider.RemoveAsync <string>(cacheKey));

                await _cacheProviderPolicy.ExecuteAsync(() => _cacheProvider.RemoveAsync <FundingTemplateContents>($"{CacheKeys.FundingTemplateContents}{validationResult.FundingStreamId}:{validationResult.FundingPeriodId}:{validationResult.TemplateVersion}".ToLowerInvariant()));

                await _cacheProviderPolicy.ExecuteAsync(() => _cacheProvider.RemoveAsync <TemplateMetadataContents>($"{CacheKeys.FundingTemplateContentMetadata}{validationResult.FundingStreamId}:{validationResult.FundingPeriodId}:{validationResult.TemplateVersion}".ToLowerInvariant()));

                await _cacheProviderPolicy.ExecuteAsync(() => _cacheProvider.RemoveAsync <TemplateMetadataDistinctContents>($"{CacheKeys.FundingTemplateContentMetadataDistinct}{validationResult.FundingStreamId}:{validationResult.FundingPeriodId}:{validationResult.TemplateVersion}".ToLowerInvariant()));

                return(new CreatedAtActionResult(actionName, controllerName, new { fundingStreamId = validationResult.FundingStreamId, fundingPeriodId = validationResult.FundingPeriodId, templateVersion = validationResult.TemplateVersion }, string.Empty));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, $"Failed to save funding template '{blobName}' to blob storage");

                return(new InternalServerErrorResult("Error occurred uploading funding template"));
            }
        }
        public void TemplateMetadataResolver_GivenGeneratorRegisteredInCorrectly_TryGetReturnsTrue()
        {
            //Arrange
            TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver();

            ITemplateMetadataGenerator registeredGenerator = CreateTemplateGenerator(_schemaVersion);

            //Act
            templateMetadataResolver.Register(_schemaVersion, registeredGenerator);

            bool contains = templateMetadataResolver.TryGetService(_schemaVersion, out ITemplateMetadataGenerator generator);

            //Assert
            contains
            .Should()
            .Be(true);

            AssertionExtensions.Should((object)generator)
            .Be(generator);
        }
        public void TemplateMetadataResolver_GivenGeneratorRegisteredCorrectly_ReturnsCorrectGenerator()
        {
            //Arrange
            TemplateMetadataResolver templateMetadataResolver = CreateTemplateResolver();

            //Act
            templateMetadataResolver.Register(_schemaVersion, CreateTemplateGenerator(_schemaVersion));

            bool contains = templateMetadataResolver.Contains(_schemaVersion);

            ITemplateMetadataGenerator generator = templateMetadataResolver.GetService(_schemaVersion);

            //Assert
            contains
            .Should()
            .Be(true);

            AssertionExtensions.Should((object)generator)
            .BeOfType <TemplateMetadataGenerator>();
        }
Пример #9
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);
        }
        public async Task SaveFundingTemplate_GivenValidTemplateButFailedToSaveToBlobStorage_ReturnsInternalServerError()
        {
            //Arrange
            const string template        = "a template";
            string       fundingStreamId = NewRandomString();
            string       templateVersion = NewRandomString();
            string       fundingPeriodId = NewRandomString();

            FundingTemplateValidationResult validationResult = new FundingTemplateValidationResult
            {
                TemplateVersion = "1.8",
                FundingStreamId = "PES",
                SchemaVersion   = "1.0",
                FundingPeriodId = "AY-2020"
            };

            string blobName = $"{validationResult.FundingStreamId}/{validationResult.FundingPeriodId}/{validationResult.TemplateVersion}.json";

            IFundingTemplateValidationService fundingTemplateValidationService = CreateFundingTemplateValidationService();

            fundingTemplateValidationService
            .ValidateFundingTemplate(Arg.Is(template), Arg.Is(fundingStreamId), Arg.Is(fundingPeriodId), Arg.Is(templateVersion))
            .Returns(validationResult);

            IFundingTemplateRepository fundingTemplateRepository = CreateFundingTemplateRepository();

            fundingTemplateRepository
            .When(x => x.SaveFundingTemplateVersion(Arg.Is(blobName), Arg.Any <byte[]>()))
            .Do(x => { throw new Exception(); });

            ILogger logger = CreateLogger();

            ITemplateMetadataGenerator templateMetadataGenerator = CreateMetadataGenerator();

            templateMetadataGenerator.Validate(Arg.Is <string>(template))
            .Returns(new FluentValidation.Results.ValidationResult());

            ITemplateMetadataResolver templateMetadataResolver = CreateMetadataResolver("1.0", templateMetadataGenerator);

            FundingTemplateService fundingTemplateService = CreateFundingTemplateService(
                logger,
                fundingTemplateValidationService: fundingTemplateValidationService,
                fundingTemplateRepository: fundingTemplateRepository,
                templateMetadataResolver: templateMetadataResolver);

            //Act
            IActionResult result = await fundingTemplateService.SaveFundingTemplate(createdAtActionName, createdAtControllerName, template, fundingStreamId, fundingPeriodId, templateVersion);

            //Assert
            result
            .Should()
            .BeAssignableTo <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be("Error occurred uploading funding template");

            logger
            .Received(1)
            .Error(Arg.Any <NonRetriableException>(), Arg.Is($"Failed to save funding template '{blobName}' to blob storage"));
        }
Пример #13
0
 public Orchestrator(ITemplateMetadataGenerator metadataGenerator, IArchitectureValidator architectureValidator)
 {
     _metadataGenerator     = metadataGenerator;
     _architectureValidator = architectureValidator;
 }
            private void SetupMocks()
            {
                _validatorFactory = Substitute.For <IIoCValidatorFactory>();
                _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult());
                _templateRepository   = Substitute.For <ITemplateRepository>();
                _templateVersionFirst = new TemplateVersion
                {
                    Name            = "XXX 20-21",
                    TemplateId      = _command.TemplateId,
                    TemplateJson    = null,
                    Version         = 1,
                    MinorVersion    = 1,
                    MajorVersion    = 0,
                    SchemaVersion   = "1.1",
                    FundingStreamId = "XX",
                    FundingPeriodId = "20-21",
                    Status          = TemplateStatus.Published,
                    Author          = new Reference("111", "FirstTestUser")
                };
                _templateBeforeUpdate = new Template
                {
                    Name          = "Template Name",
                    Description   = "Description",
                    TemplateId    = _command.TemplateId,
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "20-21",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _templateVersionFirst
                };

                _templateMetadataGenerator = Substitute.For <ITemplateMetadataGenerator>();
                _templateMetadataGenerator.Validate(Arg.Any <string>()).Returns(new ValidationResult());
                _templateMetadataResolver = Substitute.For <ITemplateMetadataResolver>();
                _templateMetadataResolver.GetService(Arg.Any <string>()).Returns(_templateMetadataGenerator);
                _templateValidationService = Substitute.For <IFundingTemplateValidationService>();
                _templateValidationService.ValidateFundingTemplate(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), null).Returns(new FundingTemplateValidationResult {
                });
                _templateRepository.GetTemplate(Arg.Is(_command.TemplateId)).Returns(_templateBeforeUpdate);
                _templateRepository.Update(Arg.Do <Template>(x => _savedTemplate = x)).Returns(HttpStatusCode.OK);

                _versionRepository = Substitute.For <ITemplateVersionRepository>();
                _versionRepository.SaveVersion(Arg.Do <TemplateVersion>(x => _savedTemplateVersion = x)).Returns(HttpStatusCode.OK);

                _searchRepository = Substitute.For <ISearchRepository <TemplateIndex> >();
                _searchRepository.Index(Arg.Any <IEnumerable <TemplateIndex> >()).Returns(Enumerable.Empty <IndexError>());

                _policyRepository = Substitute.For <IPolicyRepository>();
                _policyRepository.GetFundingPeriodById(Arg.Any <string>()).Returns(new FundingPeriod
                {
                    Id   = "2021",
                    Name = "Test Period",
                    Type = FundingPeriodType.FY
                });
                _policyRepository.GetFundingStreamById(Arg.Any <string>()).Returns(new FundingStream
                {
                    Id        = "XX",
                    ShortName = "XX",
                    Name      = "FundingSteam"
                });
                _templateBlobService = Substitute.For <ITemplateBlobService>();
                _templateBlobService.PublishTemplate(Arg.Any <Template>()).Returns(CommandResult.Success());
            }
            private void SetupMocks()
            {
                _validatorFactory = Substitute.For <IIoCValidatorFactory>();
                _validatorFactory.Validate(Arg.Any <object>()).Returns(new ValidationResult());
                _templateRepository    = Substitute.For <ITemplateRepository>();
                _sourceTemplateVersion = new TemplateVersion
                {
                    Name            = "Old Test Name",
                    TemplateId      = _command.CloneFromTemplateId,
                    TemplateJson    = "{ \"Lorem\": \"ipsum\" }",
                    Version         = 12,
                    FundingPeriodId = "19-20",
                    FundingStreamId = "OLD",
                    MinorVersion    = 1,
                    MajorVersion    = 0,
                    SchemaVersion   = "1.1",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference("111", "FirstTestUser")
                };
                _sourceTemplate = new Template
                {
                    Name          = _sourceTemplateVersion.Name,
                    Description   = "Old description",
                    TemplateId    = _command.CloneFromTemplateId,
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _sourceTemplateVersion
                };

                _templateMetadataGenerator = Substitute.For <ITemplateMetadataGenerator>();
                _templateMetadataGenerator.Validate(Arg.Any <string>()).Returns(new ValidationResult());
                _templateMetadataResolver = Substitute.For <ITemplateMetadataResolver>();
                _templateMetadataResolver.GetService(Arg.Any <string>()).Returns(_templateMetadataGenerator);
                _templateValidationService = Substitute.For <IFundingTemplateValidationService>();
                _templateValidationService.ValidateFundingTemplate(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), null).Returns(new FundingTemplateValidationResult {
                });
                _templateRepository.GetTemplate(Arg.Is(_command.CloneFromTemplateId)).Returns(_sourceTemplate);
                _templateRepository.GetAllTemplates().Returns(new[] { _sourceTemplate });
                _templateRepository.CreateDraft(Arg.Any <Template>()).Returns(HttpStatusCode.OK);

                _versionRepository = Substitute.For <ITemplateVersionRepository>();
                _versionRepository.SaveVersion(Arg.Any <TemplateVersion>()).Returns(HttpStatusCode.OK);

                _policyRepository = Substitute.For <IPolicyRepository>();
                _policyRepository.GetFundingPeriods().Returns(new[] {
                    new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    new FundingPeriod
                    {
                        Id   = _command.FundingPeriodId,
                        Name = "Test Funding Period 2"
                    }
                });
                _policyRepository.GetFundingStreams().Returns(new[] {
                    new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    new FundingStream
                    {
                        Id        = _command.FundingStreamId,
                        Name      = "Funding Stream 2",
                        ShortName = "Stream 2"
                    }
                });
                _policyRepository.GetFundingConfigurations().Returns(new[] { new FundingConfiguration
                                                                             {
                                                                                 FundingStreamId = _command.FundingStreamId,
                                                                                 FundingPeriodId = _command.FundingPeriodId
                                                                             } });

                _templateIndexer = Substitute.For <ISearchRepository <TemplateIndex> >();

                _templateBlobService = Substitute.For <ITemplateBlobService>();
                _templateBlobService.PublishTemplate(Arg.Any <Template>()).Returns(CommandResult.Success());
            }
Пример #16
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);
        }
        private static ITemplateMetadataResolver CreateMetadataResolver(string schemaVersion = "1.0", ITemplateMetadataGenerator tempateMetadataGenerator = null)
        {
            TemplateMetadataResolver resolver = new TemplateMetadataResolver();

            switch (schemaVersion)
            {
            case "1.0":
            {
                resolver.Register(schemaVersion, tempateMetadataGenerator ?? new TemplateMetadataSchema10.TemplateMetadataGenerator(CreateLogger()));
                break;
            }
            }

            return(resolver);
        }
Пример #18
0
        public bool TryGetService(string schemaVersion, out ITemplateMetadataGenerator templateMetadataGenerator)
        {
            Guard.IsNullOrWhiteSpace(schemaVersion, nameof(schemaVersion));

            return(_supportedVersions.TryGetValue(schemaVersion, out templateMetadataGenerator));
        }