public When_i_update_template_description()
            {
                _command = new TemplateDescriptionUpdateCommand
                {
                    Description = "Lorem ipsum",
                    TemplateId  = Guid.NewGuid().ToString()
                };
                _originalAuthor = new Reference("111", "FirstTestUser");
                _editor         = new Reference("222", "SecondTestUser");

                SetupMocks();

                _service = new TemplateBuilderService(
                    _validatorFactory,
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    _versionRepository,
                    _templateRepository,
                    _searchRepository,
                    _policyRepository,
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _result = _service.UpdateTemplateDescription(_command, _editor).GetAwaiter().GetResult();
            }
            public When_i_publish_current_template()
            {
                _templateId  = Guid.NewGuid().ToString();
                _author      = new Reference("222", "SecondTestUser");
                _publishNote = "Test publish note";

                SetupMocks();

                _service = new TemplateBuilderService(
                    _validatorFactory,
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    _versionRepository,
                    _templateRepository,
                    Substitute.For <ISearchRepository <TemplateIndex> >(),
                    Substitute.For <IPolicyRepository>(),
                    _templateBlobService,
                    Substitute.For <ILogger>());

                TemplatePublishCommand command = new TemplatePublishCommand
                {
                    Author     = _author,
                    TemplateId = _templateId,
                    Note       = _publishNote
                };

                _result = _service.PublishTemplate(command).GetAwaiter().GetResult();
            }
            public When_i_clone_template_to_create_new_template()
            {
                _command = new TemplateCreateAsCloneCommand
                {
                    CloneFromTemplateId = Guid.NewGuid().ToString(),
                    Description         = "New Description",
                    FundingStreamId     = "NEW",
                    FundingPeriodId     = "20-21"
                };
                _author = new Reference("222", "CloningTestUser");

                SetupMocks();

                _service = new TemplateBuilderService(
                    _validatorFactory,
                    _templateValidationService,
                    _templateMetadataResolver,
                    _versionRepository,
                    _templateRepository,
                    _templateIndexer,
                    _policyRepository,
                    _templateBlobService,
                    Substitute.For <ILogger>());

                _result = _service.CreateTemplateAsClone(_command, _author).GetAwaiter().GetResult();
            }
            public When_i_create_initial_draft_template_without_content()
            {
                _command = new TemplateCreateCommand
                {
                    Description     = "Lorem ipsum",
                    FundingStreamId = "XXX",
                    FundingPeriodId = "12345",
                    SchemaVersion   = "9.9"
                };
                _author = new Reference("111", "TestUser");

                SetupMocks();

                _service = new TemplateBuilderService(
                    _validatorFactory,
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    _versionRepository,
                    _templateRepository,
                    _searchRepository,
                    _policyRepository,
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _result = _service.CreateTemplate(_command, _author).GetAwaiter().GetResult();
            }
コード例 #5
0
            public When_i_request_current_version_of_template()
            {
                _templateVersion = new TemplateVersion
                {
                    Name            = "Test Name",
                    TemplateId      = "123",
                    TemplateJson    = null,
                    Version         = 0,
                    SchemaVersion   = "1.1",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference("111", "FirstTestUser"),
                    FundingPeriodId = "12345"
                };
                _template = new Template
                {
                    TemplateId    = _templateVersion.TemplateId,
                    Name          = _templateVersion.Name,
                    Description   = "Description",
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _templateVersion
                };
                _templateRepository = Substitute.For <ITemplateRepository>();
                _templateRepository.GetTemplate(Arg.Is(_template.TemplateId)).Returns(_template);

                _service = new TemplateBuilderService(
                    Substitute.For <IIoCValidatorFactory>(),
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    Substitute.For <ITemplateVersionRepository>(),
                    _templateRepository,
                    Substitute.For <ISearchRepository <TemplateIndex> >(),
                    Substitute.For <IPolicyRepository>(),
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _result = _service.GetTemplate(_template.TemplateId).GetAwaiter().GetResult();
            }
コード例 #6
0
            public When_i_request_all_funding_stream_periods_not_in_use()
            {
                SetupMocks();

                _service = new TemplateBuilderService(
                    Substitute.For <IIoCValidatorFactory>(),
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    Substitute.For <ITemplateVersionRepository>(),
                    _templateRepository,
                    Substitute.For <ISearchRepository <TemplateIndex> >(),
                    _policyRepository,
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _result = _service.GetFundingStreamAndPeriodsWithoutTemplates().GetAwaiter().GetResult();
            }
コード例 #7
0
        //[Test]
        public void IntegrationTest()
        {
            const string templatePath            = @"..\..\Test Templates\Modeled Basic Template.odt";
            const string reportPath              = @"..\..\Generated Reports\Very Basic Report.odt";
            const string expectedReportPath      = @"..\..\Expected Report Outputs\Very Basic Report.odt";
            var          templateFactory         = new TemplateFactory();
            var          zipFactory              = new ZipFactory();
            var          readerFactory           = new StreamReaderWrapperFactory();
            var          zipHandlerService       = new ZipHandlerService(readerFactory);
            var          buildOdfMetadataService = new BuildOdfMetadataService();
            var          xmlNamespaceService     = new XmlNamespaceService();
            var          xDocumentParserService  = new XDocumentParserService();
            var          odfHandlerService       = new OdfHandlerService(zipFactory, zipHandlerService, buildOdfMetadataService,
                                                                         xmlNamespaceService, xDocumentParserService);

            var templateService = new TemplateBuilderService(templateFactory, odfHandlerService,
                                                             xmlNamespaceService, xDocumentParserService);
            var document = File.ReadAllBytes(templatePath);

            var template             = templateService.BuildTemplate(document);
            var razorTemplateService = new TemplateService();
            var compileService       = new CompileService(razorTemplateService);

            compileService.Compile(template, "Template 1");

            var reportService = new ReportGeneratorService(new ZipFactory(), razorTemplateService);

            using (var report = new FileStream(reportPath, FileMode.Create))
            {
                reportService.BuildReport(template, new BasicModel {
                    Name = "Fancypants McSnooterson"
                }, report);
            }
            var diffs = GetDifferences(expectedReportPath, reportPath);
            var thereAreDifferences = diffs.HasDifferences();

            Assert.That(!thereAreDifferences);
        }
            public When_i_update_template_content()
            {
                _command = new TemplateFundingLinesUpdateCommand
                {
                    TemplateId = Guid.NewGuid().ToString(),
                    TemplateFundingLinesJson = @"[{""templateLineId"":1,""type"":""Payment"",""name"":""Funding Line 1"",""fundingLineCode"":""DSG-001"",""fundingLines"":[],""calculations"":[]}]"
                };
                _author = new Reference("222", "SecondTestUser");

                SetupMocks();

                _service = new TemplateBuilderService(
                    _validatorFactory,
                    _templateValidationService,
                    _templateMetadataResolver,
                    _versionRepository,
                    _templateRepository,
                    _searchRepository,
                    _policyRepository,
                    _templateBlobService,
                    Substitute.For <ILogger>());

                _result = _service.UpdateTemplateContent(_command, _author).GetAwaiter().GetResult();
            }
            public When_i_request_draft_versions_of_templates_by_funding_stream_and_period()
            {
                _templateId = Guid.NewGuid().ToString();
                _templateVersionPrevious = new TemplateVersion
                {
                    Name            = "Test Name 1",
                    TemplateId      = _templateId,
                    Version         = 1,
                    MajorVersion    = 1,
                    MinorVersion    = 0,
                    SchemaVersion   = "1.1",
                    FundingPeriodId = "12345",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference
                    {
                        Id   = "111",
                        Name = "Test 111"
                    }
                };
                _templateVersionCurrent = new TemplateVersion
                {
                    Name            = "Test Name 2",
                    TemplateId      = _templateId,
                    Version         = 2,
                    MajorVersion    = 2,
                    MinorVersion    = 0,
                    SchemaVersion   = "1.1",
                    FundingPeriodId = "12345",
                    Status          = TemplateStatus.Draft,
                    Author          = new Reference
                    {
                        Id   = "222",
                        Name = "Test 222"
                    }
                };
                _template = new Template
                {
                    Name          = _templateVersionPrevious.Name,
                    TemplateId    = _templateId,
                    FundingPeriod = new FundingPeriod
                    {
                        Id   = "2021",
                        Name = "Test Period",
                        Type = FundingPeriodType.FY
                    },
                    FundingStream = new FundingStream
                    {
                        Id        = "XX",
                        ShortName = "XX",
                        Name      = "FundingSteam"
                    },
                    Current = _templateVersionCurrent
                };
                _templateRepository = Substitute.For <ITemplateRepository>();
                _templateRepository.GetTemplate(Arg.Is(_templateId)).Returns(_template);
                _templateVersionRepository = Substitute.For <ITemplateVersionRepository>();
                _templateVersionRepository.FindByFundingStreamAndPeriod(Arg.Any <FindTemplateVersionQuery>())
                .Returns(new [] { _templateVersionPrevious, _templateVersionCurrent });

                _service = new TemplateBuilderService(
                    Substitute.For <IIoCValidatorFactory>(),
                    Substitute.For <IFundingTemplateValidationService>(),
                    Substitute.For <ITemplateMetadataResolver>(),
                    _templateVersionRepository,
                    _templateRepository,
                    Substitute.For <ISearchRepository <TemplateIndex> >(),
                    Substitute.For <IPolicyRepository>(),
                    Substitute.For <ITemplateBlobService>(),
                    Substitute.For <ILogger>());

                _results = _service
                           .FindVersionsByFundingStreamAndPeriod(new FindTemplateVersionQuery
                {
                    FundingStreamId = "XXX",
                    FundingPeriodId = "2021",
                    Statuses        = new List <TemplateStatus> {
                        TemplateStatus.Draft
                    }
                })
                           .GetAwaiter()
                           .GetResult();
            }