public void Path()
        {
            var methodologyFile = new MethodologyFile
            {
                File = new File
                {
                    Id       = Guid.NewGuid(),
                    RootPath = Guid.NewGuid(),
                    Filename = "ancillary.pdf",
                    Type     = Ancillary
                }
            };

            Assert.Equal(methodologyFile.File.Path(), methodologyFile.Path());
        }
        public async Task Stream_BlobDoesNotExist()
        {
            var methodologyVersion = new MethodologyVersion();

            var methodologyFile = new MethodologyFile
            {
                MethodologyVersion = methodologyVersion,
                File = new File
                {
                    RootPath = Guid.NewGuid(),
                    Filename = "image.png",
                    Type     = Image
                }
            };

            var contentDbContextId = Guid.NewGuid().ToString();

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                await contentDbContext.MethodologyVersions.AddAsync(methodologyVersion);

                await contentDbContext.MethodologyFiles.AddAsync(methodologyFile);

                await contentDbContext.SaveChangesAsync();
            }

            var blobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict);

            blobStorageService.Setup(mock =>
                                     mock.CheckBlobExists(PublicMethodologyFiles, It.IsAny <string>()))
            .ReturnsAsync(false);

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                var service = SetupMethodologyImageService(contentDbContext: contentDbContext,
                                                           blobStorageService: blobStorageService.Object);

                var result = await service.Stream(methodologyVersion.Id, methodologyFile.File.Id);

                result.AssertNotFound();

                blobStorageService.Verify(
                    mock => mock.CheckBlobExists(PublicMethodologyFiles, methodologyFile.Path()),
                    Times.Once());
            }

            MockUtils.VerifyAllMocks(blobStorageService);
        }
        public async Task Stream()
        {
            var methodologyVersion = new MethodologyVersion();

            var methodologyFile = new MethodologyFile
            {
                MethodologyVersion = methodologyVersion,
                File = new File
                {
                    RootPath = Guid.NewGuid(),
                    Filename = "image.png",
                    Type     = Image
                }
            };

            var contentDbContextId = Guid.NewGuid().ToString();

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                await contentDbContext.MethodologyVersions.AddAsync(methodologyVersion);

                await contentDbContext.MethodologyFiles.AddAsync(methodologyFile);

                await contentDbContext.SaveChangesAsync();
            }

            var blobStorageService = new Mock <IBlobStorageService>(MockBehavior.Strict);

            var blob = new BlobInfo(
                path: methodologyFile.Path(),
                size: null,
                contentType: "image/png",
                contentLength: 0L,
                meta: GetMetaValuesReleaseDateTime(
                    releaseDateTime: DateTime.UtcNow.AddDays(-1)),
                created: null);

            blobStorageService.Setup(mock =>
                                     mock.CheckBlobExists(PublicMethodologyFiles, methodologyFile.Path()))
            .ReturnsAsync(true);

            blobStorageService.Setup(mock =>
                                     mock.GetBlob(PublicMethodologyFiles, methodologyFile.Path()))
            .ReturnsAsync(blob);

            blobStorageService.Setup(mock =>
                                     mock.DownloadToStream(PublicMethodologyFiles, methodologyFile.Path(),
                                                           It.IsAny <MemoryStream>(), null))
            .ReturnsAsync(new MemoryStream());

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                var service = SetupMethodologyImageService(contentDbContext: contentDbContext,
                                                           blobStorageService: blobStorageService.Object);

                var result = await service.Stream(methodologyVersion.Id, methodologyFile.File.Id);

                Assert.True(result.IsRight);

                blobStorageService.Verify(
                    mock => mock.CheckBlobExists(PublicMethodologyFiles, methodologyFile.Path()),
                    Times.Once());

                blobStorageService.Verify(
                    mock => mock.GetBlob(PublicMethodologyFiles, methodologyFile.Path()),
                    Times.Once());

                blobStorageService.Verify(
                    mock =>
                    mock.DownloadToStream(
                        PublicMethodologyFiles, methodologyFile.Path(),
                        It.IsAny <MemoryStream>(), null),
                    Times.Once());

                Assert.Equal("image/png", result.Right.ContentType);
                Assert.Equal("image.png", result.Right.FileDownloadName);
                Assert.IsType <MemoryStream>(result.Right.FileStream);
            }

            MockUtils.VerifyAllMocks(blobStorageService);
        }