public async Task GetDistinctFundingTemplateMetadataFundingLinesContents_GivenContentsInCache_ReturnsOkObjecWithResultsFromCache()
        {
            //Arrange
            const string fundingStreamId = "PES";
            const string fundingPeriodId = "AY-2020";
            const string templateVersion = "1.0";
            string       cacheKey        = $"{CacheKeys.FundingTemplateContentMetadataDistinct}{fundingStreamId}:{fundingPeriodId}:{templateVersion}".ToLowerInvariant();

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

            IFundingTemplateRepository fundingTemplateRepository = CreateFundingTemplateRepository();

            fundingTemplateRepository
            .TemplateVersionExists(Arg.Is <string>(_ => _.Contains(blobNamePrefix)))
            .Returns(true);
            fundingTemplateRepository.GetFundingTemplateVersion(Arg.Is <string>(_ => _.Contains(blobNamePrefix)))
            .Returns(string.Empty);

            ILogger        logger        = CreateLogger();
            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider.GetAsync <TemplateMetadataDistinctContents>(cacheKey)
            .Returns(new TemplateMetadataDistinctContents()
            {
                FundingStreamId = fundingStreamId,
                FundingPeriodId = fundingPeriodId,
                TemplateVersion = templateVersion
            });

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

            //Act
            ActionResult <TemplateMetadataDistinctContents> result = await fundingTemplateService.GetDistinctFundingTemplateMetadataContents(fundingStreamId, fundingPeriodId, templateVersion);

            //Assert

            TemplateMetadataDistinctContents contents = result.Value;

            contents.Should().NotBeNull();
            contents.FundingStreamId.Should().Be(fundingStreamId);
            contents.FundingPeriodId.Should().Be(fundingPeriodId);
            contents.TemplateVersion.Should().Be(templateVersion);

            await cacheProvider
            .Received(1).GetAsync <TemplateMetadataDistinctContents>(cacheKey);

            await fundingTemplateRepository
            .Received(0).GetFundingTemplateVersion(Arg.Is <string>(_ => _.Contains(blobNamePrefix)));

            await cacheProvider
            .Received(0)
            .SetAsync(cacheKey,
                      Arg.Is <TemplateMetadataDistinctContents>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId && _.TemplateVersion == templateVersion),
                      TimeSpan.FromDays(365),
                      true,
                      null);
        }
        public async Task GetDistinctFundingTemplateMetadataFundingLinesContents_GivenTemplateIsInBlob_ReturnsOkObjecResultstWithDistinctFundingLinesAndCalculations()
        {
            //Arrange
            const string fundingStreamId = "PES";
            const string fundingPeriodId = "AY-2020";
            const string templateVersion = "1.0";

            string template = CreateJsonFile("CalculateFunding.Services.Policy.Resources.LogicalModelTemplateForDistinctMetadataContents.json");

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

            IFundingTemplateRepository fundingTemplateRepository = CreateFundingTemplateRepository();

            fundingTemplateRepository
            .TemplateVersionExists(Arg.Is <string>(_ => _.Contains(blobNamePrefix)))
            .Returns(true);
            fundingTemplateRepository.GetFundingTemplateVersion(Arg.Is <string>(_ => _.Contains(blobNamePrefix)))
            .Returns(template);

            ILogger        logger        = CreateLogger();
            ICacheProvider cacheProvider = CreateCacheProvider();

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

            //Act
            ActionResult <TemplateMetadataDistinctContents> result = await fundingTemplateService.GetDistinctFundingTemplateMetadataContents(fundingStreamId, fundingPeriodId, templateVersion);

            //Assert
            TemplateMetadataDistinctContents contents = result.Value;

            contents.Should().NotBeNull();
            contents.FundingLines.Count().Should().Be(2);
            contents.Calculations.Count().Should().Be(2);
            contents.FundingStreamId.Should().Be(fundingStreamId);
            contents.FundingPeriodId.Should().Be(fundingPeriodId);
            contents.TemplateVersion.Should().Be(templateVersion);

            string cacheKey = $"{CacheKeys.FundingTemplateContentMetadataDistinct}{fundingStreamId}:{fundingPeriodId}:{templateVersion}".ToLowerInvariant();
            await cacheProvider
            .Received(1)
            .SetAsync(cacheKey,
                      Arg.Is <TemplateMetadataDistinctContents>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId && _.TemplateVersion == templateVersion),
                      TimeSpan.FromDays(365),
                      true,
                      null);
        }