Exemplo n.º 1
0
        public async Task ReturnsPublishedFundingTemplatesForGivenFundingStreamAndPeriod()
        {
            DateTime expectedPublishDate = new RandomDateTime();

            IEnumerable <PolicyApiClientModel.PublishedFundingTemplate> publishedFundingTemplates =
                new List <PolicyApiClientModel.PublishedFundingTemplate>
            {
                new PolicyApiClientModel.PublishedFundingTemplate()
                {
                    AuthorName      = "AuthName",
                    AuthorId        = "AuthId",
                    PublishDate     = expectedPublishDate,
                    PublishNote     = "SomeComments",
                    SchemaVersion   = "1.2",
                    TemplateVersion = "2.3"
                }
            };

            GivenApiPublishedFundingTemplates(_fundingStreamId, _fundingPeriodId, publishedFundingTemplates);

            OkObjectResult result = await WhenGetPublishedFundingTemplates(_fundingStreamId, _fundingPeriodId) as OkObjectResult;

            result
            .Should()
            .NotBeNull();

            PublishedFundingTemplate template = result.Value.As <IEnumerable <PublishedFundingTemplate> >().FirstOrDefault();

            template
            .Should()
            .NotBeNull();

            template
            .Should()
            .BeEquivalentTo(new PublishedFundingTemplate
            {
                AuthorName    = "AuthName",
                PublishNote   = "SomeComments",
                MinorVersion  = "3",
                MajorVersion  = "2",
                PublishDate   = expectedPublishDate,
                SchemaVersion = "1.2"
            });
        }
        public async Task GetFundingTemplates_GivenTemplateIsInBlob_Metatdata_In_TemplateBuilder_Collection_ReturnsOkObjectResultWithAMetadata()
        {
            //Arrange
            const string fundingStreamId = "PES";
            const string fundingPeriodId = "AY-2020";

            string blobNamePrefix = $"{fundingStreamId}/{ fundingPeriodId}/";

            IEnumerable <TemplateSummaryResponse> templateVersions = new[]
            {
                new TemplateSummaryResponse()
                {
                    FundingPeriodId = fundingPeriodId,
                    FundingStreamId = fundingStreamId,
                    MajorVersion    = 1,
                    MinorVersion    = 1,
                    Status          = TemplateStatus.Published,
                    AuthorId        = "Auth-Id",
                    AuthorName      = "Auth-Name",
                    Comments        = "SomeComments",
                    SchemaVersion   = "1.1"
                },
                new TemplateSummaryResponse()
                {
                    FundingPeriodId = fundingPeriodId,
                    FundingStreamId = fundingStreamId,
                    MajorVersion    = 1,
                    MinorVersion    = 0,
                    Status          = TemplateStatus.Published,
                    AuthorId        = "Auth-Id2",
                    AuthorName      = "Auth-Name2",
                    Comments        = "SomeComments2",
                    SchemaVersion   = "1.2"
                }
            };

            IEnumerable <PublishedFundingTemplate> pubblishedFundingTempaltes = new[]
            {
                new PublishedFundingTemplate()
                {
                    TemplateVersion = "1.0",
                    PublishDate     = new DateTime(2020, 06, 15, 10, 30, 50)
                }
            };

            IFundingTemplateRepository fundingTemplateRepository = CreateFundingTemplateRepository();

            fundingTemplateRepository
            .SearchTemplates(Arg.Is(blobNamePrefix))
            .Returns(pubblishedFundingTempaltes);

            ITemplateBuilderService templateBuilderService = CreateTemplateBuilderService();

            templateBuilderService.FindVersionsByFundingStreamAndPeriod(Arg.Is <FindTemplateVersionQuery>(x => x.FundingStreamId == fundingStreamId && x.FundingPeriodId == fundingPeriodId))
            .Returns(templateVersions);


            ILogger logger = CreateLogger();

            FundingTemplateService fundingTemplateService = CreateFundingTemplateService(
                logger,
                fundingTemplateRepository: fundingTemplateRepository,
                templateBuilderService: templateBuilderService);

            //Act
            ActionResult <IEnumerable <PublishedFundingTemplate> > result = await fundingTemplateService.GetFundingTemplates(fundingStreamId, fundingPeriodId);

            //Assert
            PublishedFundingTemplate resultTemplate   = result.Value.FirstOrDefault();
            TemplateSummaryResponse  templateResponse = templateVersions.First(x => x.MajorVersion == 1 && x.MinorVersion == 0);

            resultTemplate.TemplateVersion.Should().Be(pubblishedFundingTempaltes.First().TemplateVersion);
            resultTemplate.PublishDate.Should().Be(pubblishedFundingTempaltes.First().PublishDate);
            resultTemplate.AuthorId.Should().Be(templateResponse.AuthorId);
            resultTemplate.AuthorName.Should().Be(templateResponse.AuthorName);
            resultTemplate.PublishNote.Should().Be(templateResponse.Comments);
            resultTemplate.SchemaVersion.Should().Be(templateResponse.SchemaVersion);
        }