public void PublicPath_ReleaseFile()
        {
            var release = new Release
            {
                Publication = new Publication
                {
                    Slug = PublicationSlug
                },
                Slug = ReleaseSlug
            };

            var releaseFile = new ReleaseFile
            {
                Release = release,
                File    = _file
            };

            Assert.Equal(_file.PublicPath(release), releaseFile.PublicPath());
        }
Esempio n. 2
0
        public void PublicPath()
        {
            var release = new Release
            {
                Id = Guid.NewGuid()
            };

            var releaseFile = new ReleaseFile
            {
                Release = release,
                File    = new File
                {
                    Id       = Guid.NewGuid(),
                    RootPath = Guid.NewGuid(),
                    Filename = "ancillary.pdf",
                    Type     = Ancillary
                }
            };

            Assert.Equal(releaseFile.File.PublicPath(release), releaseFile.PublicPath());
        }
        public async Task GetDownloadFiles()
        {
            var contentDbContextId = Guid.NewGuid().ToString();

            using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                await contentDbContext.AddRangeAsync(Publications);

                await contentDbContext.AddRangeAsync(Releases);

                await contentDbContext.AddRangeAsync(ReleaseFiles);

                await contentDbContext.SaveChangesAsync();
            }

            var fileStorageService = new Mock <IFileStorageService>(MockBehavior.Strict);

            using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                fileStorageService.Setup(s =>
                                         s.CheckBlobExists(PublicFilesContainerName,
                                                           PublicationARelease2AncillaryReleaseFile.PublicPath()))
                .ReturnsAsync(true);

                fileStorageService.Setup(s =>
                                         s.CheckBlobExists(PublicFilesContainerName,
                                                           PublicationARelease2DataReleaseFile.PublicPath()))
                .ReturnsAsync(true);

                fileStorageService.Setup(s =>
                                         s.CheckBlobExists(PublicFilesContainerName,
                                                           PublicReleaseAllFilesZipPath(PublicationA.Slug, PublicationARelease2.Slug)))
                .ReturnsAsync(true);

                fileStorageService.Setup(s =>
                                         s.GetBlob(PublicFilesContainerName,
                                                   PublicationARelease2AncillaryReleaseFile.PublicPath()))
                .ReturnsAsync(new BlobInfo
                              (
                                  path: PublicationARelease2AncillaryReleaseFile.PublicPath(),
                                  size: "15 Kb",
                                  contentType: "application/pdf",
                                  contentLength: 0L,
                                  meta: GetAncillaryFileMetaValues(
                                      name: "Ancillary Test File",
                                      filename: "Ignored"),
                                  created: null
                              ));

                fileStorageService.Setup(s =>
                                         s.GetBlob(PublicFilesContainerName,
                                                   PublicationARelease2DataReleaseFile.PublicPath()))
                .ReturnsAsync(new BlobInfo
                              (
                                  path: PublicationARelease2DataReleaseFile.PublicPath(),
                                  size: "10 Mb",
                                  contentType: "text/csv",
                                  contentLength: 0L,
                                  meta: GetDataFileMetaValues(
                                      name: "Data Test File",
                                      metaFileName: "data.meta.csv",
                                      userName: "******",
                                      numberOfRows: 200),
                                  created: null
                              ));

                fileStorageService.Setup(s => s.GetBlob(PublicFilesContainerName,
                                                        PublicReleaseAllFilesZipPath(PublicationA.Slug, PublicationARelease2.Slug)))
                .ReturnsAsync(new BlobInfo
                              (
                                  path: PublicReleaseAllFilesZipPath(PublicationA.Slug, PublicationARelease2.Slug),
                                  size: "3 Mb",
                                  contentType: "application/x-zip-compressed",
                                  contentLength: 0L,
                                  meta: GetAllFilesZipMetaValues(
                                      name: "All files",
                                      releaseDateTime: DateTime.Now),
                                  created: null
                              ));

                var service = BuildReleaseService(contentDbContext: contentDbContext,
                                                  fileStorageService: fileStorageService.Object);

                var result = await service.GetDownloadFiles(PublicationARelease2);

                fileStorageService.VerifyAll();

                Assert.Equal(3, result.Count);
                Assert.False(result[0].Id.HasValue);
                Assert.Equal("zip", result[0].Extension);
                Assert.Equal("publication-a_2018-19-q2.zip", result[0].FileName);
                Assert.Equal("All files", result[0].Name);
                Assert.Equal(PublicReleaseAllFilesZipPath(PublicationA.Slug, PublicationARelease2.Slug), result[0].Path);
                Assert.Equal("3 Mb", result[0].Size);
                Assert.Equal(Ancillary, result[0].Type);
                Assert.Equal(PublicationARelease2AncillaryReleaseFile.File.Id, result[1].Id);
                Assert.Equal("pdf", result[1].Extension);
                Assert.Equal("ancillary.pdf", result[1].FileName);
                Assert.Equal("Ancillary Test File", result[1].Name);
                Assert.Equal(PublicationARelease2AncillaryReleaseFile.PublicPath(), result[1].Path);
                Assert.Equal("15 Kb", result[1].Size);
                Assert.Equal(Ancillary, result[1].Type);
                Assert.Equal(PublicationARelease2DataReleaseFile.File.Id, result[2].Id);
                Assert.Equal("csv", result[2].Extension);
                Assert.Equal("data.csv", result[2].FileName);
                Assert.Equal("Data Test File", result[2].Name);
                Assert.Equal(PublicationARelease2DataReleaseFile.PublicPath(), result[2].Path);
                Assert.Equal("10 Mb", result[2].Size);
                Assert.Equal(FileType.Data, result[2].Type);
            }
        }