Пример #1
0
        public void ParseDocumentPathRelativeToBlobContainerFromFullUrl_ParsesAsExpected(string input, string output)
        {
            //Arrange
            PublishedFundingRetrievalService service = CreatePublishedFundingRetrievalService();

            //Act
            string result = service.ParseDocumentPathRelativeToBlobContainerFromFullUrl(input);

            //Assert
            result.Should().Be(output);
        }
Пример #2
0
        public async Task GetFundingFeedDocument_NoFundingStream_LogsAndReturnsNull()
        {
            string documentPath            = "uri";
            string absoluteDocumentPathUrl = $"https://cfs/base/{documentPath}";

            ICloudBlob cloudBlob = CreateBlob();

            cloudBlob
            .Exists()
            .Returns(true);

            IBlobClient blobClient = CreateBlobClient();

            blobClient
            .GetBlockBlobReference(Arg.Any <string>())
            .Returns(cloudBlob);

            blobClient
            .DownloadToStreamAsync(cloudBlob)
            .Returns(new MemoryStream());

            ILogger logger = CreateLogger();

            PublishedFundingRetrievalService service = CreatePublishedFundingRetrievalService(
                blobClient: blobClient,
                logger: logger);

            string result = await service.GetFundingFeedDocument(absoluteDocumentPathUrl);

            result
            .Should()
            .BeNull();

            blobClient
            .Received(1)
            .GetBlockBlobReference(documentPath);

            cloudBlob
            .Received(1)
            .Exists(null, null);

            await blobClient
            .Received(1)
            .DownloadToStreamAsync(cloudBlob);

            logger
            .Received(1)
            .Error($"Invalid blob returned: {documentPath}");
        }
Пример #3
0
        public async Task GetFundingFeedDocument_BlobDoesntExist_LogsAndReturnsNull(string documentPath)
        {
            string absoluteDocumentPathUrl = $"https://cfs/base/{documentPath}";

            ICloudBlob cloudBlob = CreateBlob();

            cloudBlob
            .Exists()
            .Returns(false);

            IBlobClient blobClient = CreateBlobClient();

            blobClient
            .GetBlockBlobReference(Arg.Any <string>())
            .Returns(cloudBlob);

            ILogger logger = CreateLogger();

            PublishedFundingRetrievalService service = CreatePublishedFundingRetrievalService(
                blobClient: blobClient,
                logger: logger);

            string result = await service.GetFundingFeedDocument(absoluteDocumentPathUrl);

            result
            .Should()
            .BeNull();

            blobClient
            .Received(1)
            .GetBlockBlobReference(documentPath);

            cloudBlob
            .Received(1)
            .Exists(null, null);

            logger
            .Received(1)
            .Error($"Failed to find blob with path: {documentPath}");
        }
Пример #4
0
        public async Task GetFundingFeedDocument_WhenReturnsFromBlobStorage_ReturnsOK(bool fileSystemCacheEnabled,
                                                                                      int expectedCacheAccessCount)
        {
            //Arrange
            string template     = new RandomString();
            string documentPath = "cromulent.json";
            string uri          = $"https://cfs/test/{documentPath}";

            Stream memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(template));

            ILogger          logger          = CreateLogger();
            ICloudBlob       cloudBlob       = CreateBlob();
            IFileSystemCache fileSystemCache = CreateFileSystemCache();
            IExternalApiFileSystemCacheSettings cacheSettings = Substitute.For <IExternalApiFileSystemCacheSettings>();

            cacheSettings.IsEnabled.Returns(fileSystemCacheEnabled);

            cloudBlob
            .Exists()
            .Returns(true);
            cloudBlob
            .Exists(Arg.Any <BlobRequestOptions>(), Arg.Any <OperationContext>())
            .Returns(true);

            IBlobClient blobClient = CreateBlobClient();

            blobClient
            .GetBlockBlobReference(Arg.Is(documentPath))
            .Returns(cloudBlob);

            blobClient
            .DownloadToStreamAsync(Arg.Is(cloudBlob))
            .Returns(memoryStream);

            PublishedFundingRetrievalService service = CreatePublishedFundingRetrievalService(
                blobClient: blobClient,
                logger: logger,
                fileSystemCache: fileSystemCache,
                cacheSettings: cacheSettings);

            //Act
            string result = await service.GetFundingFeedDocument(uri);

            //Assert
            result
            .Should()
            .Be(template);

            blobClient
            .Received(1)
            .GetBlockBlobReference(documentPath);

            cloudBlob
            .Received(1)
            .Exists();

            logger
            .Received(0)
            .Error(Arg.Any <string>());

            await blobClient
            .Received(1)
            .DownloadToStreamAsync(cloudBlob);

            fileSystemCache
            .Received(0)
            .Get(Arg.Any <FundingFileSystemCacheKey>());

            string documentName = Path.GetFileNameWithoutExtension(documentPath);

            fileSystemCache
            .Received(expectedCacheAccessCount)
            .Add(Arg.Is <FundingFileSystemCacheKey>(
                     _ => _.Key == documentName),
                 memoryStream);
        }