public async Task GetFundingTemplates_GivenTemplateIsInBlob_ReturnsOkObjectResult()
        {
            //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    = 0,
                    Status          = TemplateStatus.Published
                }
            };
            IEnumerable <PublishedFundingTemplate> publishedFundingTemplate = new[]
            {
                new PublishedFundingTemplate()
                {
                    TemplateVersion = "1.0"
                }
            };

            IFundingTemplateRepository fundingTemplateRepository = CreateFundingTemplateRepository();

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

            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
            result
            .Value
            .Should()
            .BeEquivalentTo(publishedFundingTemplate);
        }
 private async Task <IEnumerable <PublishedFundingTemplate> > SearchTemplates(string blobNamePrefix)
 {
     try
     {
         return(await _fundingTemplateRepositoryPolicy.ExecuteAsync(() => _fundingTemplateRepository.SearchTemplates(blobNamePrefix)));
     }
     catch (Exception ex)
     {
         throw new NonRetriableException($"Failed to search for funding template: '{blobNamePrefix}' from blob storage", ex);
     }
 }
        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);
        }