Esempio n. 1
0
        public async Task ValidateSubjectName_SubjectNameNotUnique()
        {
            var release         = new Release();
            var dataReleaseFile = new ReleaseFile
            {
                Release = release,
                Name    = "Subject Title",
                File    = new File
                {
                    Type = FileType.Data,
                }
            };
            var contentDbContextId = Guid.NewGuid().ToString();

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                await contentDbContext.AddAsync(release);

                await contentDbContext.AddAsync(dataReleaseFile);

                await contentDbContext.SaveChangesAsync();
            }

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                var(service, _) = BuildService(contentDbContext);

                var result = await service.ValidateSubjectName(release.Id, "Subject Title");

                result.AssertBadRequest(SubjectTitleMustBeUnique);
            }
        }
Esempio n. 2
0
        private List <ReleaseFile> GetReleaseFiles()
        {
            List <ReleaseFile> fileList = new List <ReleaseFile>();

            foreach (ITaskItem item in this.releaseFileItems)
            {
                string filePath = null;
                try
                {
                    if (item.ItemSpec.Length != 0)
                    {
                        filePath = item.GetMetadata("FullPath");
                        using (Stream fileStream = File.OpenRead(filePath))
                        {
                            ReleaseFile file = new ReleaseFile(ReleaseTaskBase.GetMetadata(item, "Name"), ReleaseTaskBase.GetMetadata(item, "MimeType"), item.GetMetadata("Filename") + item.GetMetadata("Extension"), fileStream, base.GetEnumValue <ReleaseFileType>(ReleaseTaskBase.GetMetadata(item, "FileType") ?? "RuntimeBinary"));
                            fileList.Add(file);
                            base.LogMessage("  \"{0}\" as \"{1}\"", new object[] { file.FileName, file.Name ?? Path.GetFileName(file.FileName) });
                        }
                    }
                }
                catch (ArgumentException)
                {
                    throw;
                }
                catch (Exception)
                {
                    if (filePath != null)
                    {
                        base.LogError("Unable to open file: {0}", new object[] { filePath });
                    }
                }
            }
            return(fileList);
        }
Esempio n. 3
0
 public async Task <BlobInfo?> Get(ReleaseFile releaseFile)
 {
     return(await _blobStorageService.FindBlob(
                containerName : BlobContainers.PrivateReleaseFiles,
                path : releaseFile.File.Path()
                ));
 }
        public void ItReturnsTrueIfValuesAreEquals()
        {
            ReleaseFile f1 = new ReleaseFile("abcdef", "foo", "win-x86", "https://here.there.com");
            ReleaseFile f2 = new ReleaseFile("abcdef", "foo", "win-x86", "https://here.there.com");

            Assert.Equal(f1, f2);
        }
        public void ItReturnsFalseIfReferenceEquals2()
        {
            ReleaseFile f1 = new ReleaseFile("abcdef", "Foo", "win-x86", "https://here.there.com");
            ReleaseFile f2 = new ReleaseFile("abcdef", "foo", "win-x86", "https://here.there.com");

            Assert.NotEqual(f1, f2);
        }
Esempio n. 6
0
        public void ToFileInfo_NoCreatedBy()
        {
            var releaseFile = new ReleaseFile
            {
                Release = new Release(),
                Name    = "Test ancillary file",
                File    = new File
                {
                    Id       = Guid.NewGuid(),
                    RootPath = Guid.NewGuid(),
                    Filename = "ancillary.pdf",
                    Type     = Ancillary,
                }
            };

            var info = releaseFile.ToFileInfo(new BlobInfo
                                              (
                                                  path: "Ignored",
                                                  size: "400 B",
                                                  contentType: "Ignored",
                                                  contentLength: -1L,
                                                  meta: new Dictionary <string, string>()
                                              ));

            Assert.Null(info.Created);
            Assert.Null(info.UserName);
        }
        public async Task <ReleaseFile> Create(
            Guid releaseId,
            string filename,
            FileType type,
            Guid createdById,
            string?name    = null,
            string?summary = null)
        {
            if (!SupportedFileTypes.Contains(type))
            {
                throw new ArgumentOutOfRangeException(nameof(type), type, "Cannot create file for file type");
            }

            var releaseFile = new ReleaseFile
            {
                ReleaseId = releaseId,
                Name      = name,
                Summary   = summary,
                File      = new File
                {
                    Created     = DateTime.UtcNow,
                    CreatedById = createdById,
                    RootPath    = releaseId,
                    Filename    = filename,
                    Type        = type
                }
            };

            var created = (await _contentDbContext.ReleaseFiles.AddAsync(releaseFile)).Entity;
            await _contentDbContext.SaveChangesAsync();

            return(created);
        }
Esempio n. 8
0
		private List<ReleaseFile> GetReleaseFiles()
		{
			List<ReleaseFile> fileList = new List<ReleaseFile>();
			foreach ( ITaskItem item in this.releaseFileItems )
			{
				string filePath = null;
				try
				{
					if ( item.ItemSpec.Length != 0 )
					{
						filePath = item.GetMetadata( "FullPath" );
						using ( Stream fileStream = File.OpenRead( filePath ) )
						{
							ReleaseFile file = new ReleaseFile( ReleaseTaskBase.GetMetadata( item, "Name" ), ReleaseTaskBase.GetMetadata( item, "MimeType" ), item.GetMetadata( "Filename" ) + item.GetMetadata( "Extension" ), fileStream, base.GetEnumValue<ReleaseFileType>( ReleaseTaskBase.GetMetadata( item, "FileType" ) ?? "RuntimeBinary" ) );
							fileList.Add( file );
							base.LogMessage( "  \"{0}\" as \"{1}\"", new object[] { file.FileName, file.Name ?? Path.GetFileName( file.FileName ) } );
						}
					}
				}
				catch ( ArgumentException )
				{
					throw;
				}
				catch ( Exception )
				{
					if ( filePath != null )
					{
						base.LogError( "Unable to open file: {0}", new object[] { filePath } );
					}
				}
			}
			return fileList;
		}
Esempio n. 9
0
        public void DeleteAll()
        {
            var releaseFile = new ReleaseFile
            {
                Release = _release,
                File    = new File
                {
                    Filename = "ancillary.pdf",
                    Type     = Ancillary,
                    Release  = _release
                }
            };

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

            using (var contentDbContext = DbUtils.InMemoryApplicationDbContext(contentDbContextId))
            {
                contentDbContext.AddAsync(releaseFile);
                contentDbContext.SaveChangesAsync();
            }

            PolicyCheckBuilder <SecurityPolicies>()
            .ExpectResourceCheckToFail(_release, CanUpdateSpecificRelease)
            .AssertForbidden(
                userService =>
            {
                var service = SetupReleaseFileService(
                    contentDbContext: DbUtils.InMemoryApplicationDbContext(contentDbContextId),
                    userService: userService.Object);
                return(service.DeleteAll(_release.Id));
            }
                );
        }
        public async Task ItThrowsIfDestinationPathIsNull()
        {
            ProductRelease release = GetProductRelease("2.1", "2.1.8");
            ReleaseFile    file    = release.Files.FirstOrDefault();
            Func <Task>    f       = async() => await file.DownloadAsync(null);

            ArgumentNullException exception = await Assert.ThrowsAsync <ArgumentNullException>(f);
        }
        public async Task Get()
        {
            var release = new Release
            {
                MetaGuidance = "Release Meta Guidance"
            };

            var releaseFile = new ReleaseFile
            {
                Release = release,
                File    = new File
                {
                    Filename  = "file1.csv",
                    Release   = release,
                    Type      = FileType.Data,
                    SubjectId = Guid.NewGuid()
                }
            };

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

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                await contentDbContext.AddAsync(release);

                await contentDbContext.AddAsync(releaseFile);

                await contentDbContext.SaveChangesAsync();
            }

            var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict);

            metaGuidanceSubjectService.Setup(mock =>
                                             mock.GetSubjects(release.Id, new List <Guid>
            {
                releaseFile.File.SubjectId.Value
            })).ReturnsAsync(SubjectMetaGuidance);

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                var service = SetupMetaGuidanceService(contentDbContext: contentDbContext,
                                                       metaGuidanceSubjectService: metaGuidanceSubjectService.Object);

                var result = await service.Get(release.Id);

                Assert.True(result.IsRight);

                metaGuidanceSubjectService.Verify(mock =>
                                                  mock.GetSubjects(release.Id, new List <Guid>
                {
                    releaseFile.File.SubjectId.Value
                }), Times.Once);

                Assert.Equal(release.Id, result.Right.Id);
                Assert.Equal("Release Meta Guidance", result.Right.Content);
                Assert.Equal(SubjectMetaGuidance, result.Right.Subjects);
            }
        }
        public void Path_ReleaseFile()
        {
            var releaseFile = new ReleaseFile
            {
                File = _file
            };

            Assert.Equal(_file.Path(), releaseFile.Path());
        }
        public static FileInfo ToFileInfoNotFound(this ReleaseFile releaseFile)
        {
            var fileInfo = releaseFile.ToPublicFileInfoNotFound();

            fileInfo.UserName = releaseFile.File.CreatedBy?.Email;
            fileInfo.Created  = releaseFile.File.Created;

            return(fileInfo);
        }
        public static FileInfo ToFileInfo(this ReleaseFile releaseFile, BlobInfo blobInfo)
        {
            var info = releaseFile.ToPublicFileInfo(blobInfo);

            info.Created  = releaseFile.File.Created;
            info.UserName = releaseFile.File.CreatedBy?.Email;

            return(info);
        }
        public async Task ItThrowsIfDestinationPathIsEmpty()
        {
            ProductRelease release = GetProductRelease("2.1", "2.1.8");
            ReleaseFile    file    = release.Files.FirstOrDefault();
            Func <Task>    f       = async() => await file.DownloadAsync("");

            ArgumentException exception = await Assert.ThrowsAsync <ArgumentException>(f);

            Assert.Equal($"Value cannot be empty.{Environment.NewLine}Parameter name: destinationPath", exception.Message);
        }
        private async Task HydrateReleaseFile(ReleaseFile releaseFile)
        {
            await _contentDbContext.Entry(releaseFile)
            .Reference(rf => rf.File)
            .LoadAsync();

            await _contentDbContext.Entry(releaseFile.File)
            .Reference(f => f.CreatedBy)
            .LoadAsync();
        }
 public static FileInfo ToPublicFileInfoNotFound(this ReleaseFile releaseFile)
 {
     return(new FileInfo
     {
         Id = releaseFile.FileId,
         FileName = releaseFile.File.Filename,
         Name = releaseFile.Name ?? releaseFile.File.Filename,
         Summary = releaseFile.Summary,
         Size = FileInfo.UnknownSize,
         Type = releaseFile.File.Type,
     });
 }
 public static FileInfo ToPublicFileInfo(this ReleaseFile releaseFile, BlobInfo blobInfo)
 {
     return(new FileInfo
     {
         Id = releaseFile.FileId,
         FileName = releaseFile.File.Filename,
         Name = releaseFile.Name ?? releaseFile.File.Filename,
         Summary = releaseFile.Summary,
         Size = blobInfo.Size,
         Type = releaseFile.File.Type,
     });
 }
        private static void AssertAmendedReleaseFileCorrect(ReleaseFile originalFile, ReleaseFile amendmentDataFile,
                                                            Release amendment)
        {
            // assert it's a new link table entry between the Release amendment and the data file reference
            Assert.NotEqual(originalFile.Id, amendmentDataFile.Id);
            Assert.Equal(amendment, amendmentDataFile.Release);
            Assert.Equal(amendment.Id, amendmentDataFile.ReleaseId);

            // and assert that the file referenced is the SAME file reference as linked from the original Release's
            // link table entry
            Assert.Equal(originalFile.File.Id, amendmentDataFile.File.Id);
        }
Esempio n. 20
0
        public async Task CanCreateReleaseFile_FailOnFolderNotExisting()
        {
            var dummyReleaseFileEntries = CreateReleaseFiles();
            var fileLocation            = Randomizer.GetString();

            if (Directory.Exists(fileLocation))
            {
                Directory.Delete(fileLocation, true);
            }
            Assert.False(await ReleaseFile.CreateReleaseFile(dummyReleaseFileEntries, fileLocation),
                         "Creating RELEASE file passed even when we had no folder to work with");
        }
Esempio n. 21
0
        public async Task CanCreateReleaseFile()
        {
            var dummyReleaseFileEntries = CreateReleaseFiles();

            Assert.True(
                await ReleaseFile.CreateReleaseFile(dummyReleaseFileEntries, TestContext.CurrentContext.WorkDirectory),
                "Wasn't able to create the release file");

            Assert.True(
                dummyReleaseFileEntries.SequenceEqual(
                    ReleaseFile.ReadReleaseFile(File.ReadLines(ReleaseFileLocation))),
                "What we made and what we read from disk isn't the same");
        }
Esempio n. 22
0
        public static UpdateInfo?GetUpdateInfo(string fileLocation, ApplicationMetadata metadata, bool grabDeltaUpdates, object?tag = null, string?folderLocation = null)
        {
            if (!File.Exists(fileLocation))
            {
                Logger.Error("{0} doesn't exist, can't get UpdateInfo", fileLocation);
                return(null);
            }

            return(new UpdateInfo(metadata.ApplicationVersion,
                                  ReleaseFile.ReadReleaseFile(File.ReadLines(fileLocation))
                                  .ToReleaseEntries(folderLocation ?? metadata.TempFolder, tag)
                                  .FilterReleases(metadata.ApplicationFolder, grabDeltaUpdates, metadata.ApplicationVersion).ToArray()));
        }
        public async Task Validate_SubjectMetaGuidanceNotPopulated()
        {
            var release = new Release
            {
                MetaGuidance = "Release Meta Guidance"
            };

            var releaseFile = new ReleaseFile
            {
                Release = release,
                File    = new File
                {
                    Filename  = "file1.csv",
                    Release   = release,
                    Type      = FileType.Data,
                    SubjectId = Guid.NewGuid()
                }
            };

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

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                await contentDbContext.AddAsync(release);

                await contentDbContext.AddAsync(releaseFile);

                await contentDbContext.SaveChangesAsync();
            }

            var metaGuidanceSubjectService = new Mock <IMetaGuidanceSubjectService>(MockBehavior.Strict);

            metaGuidanceSubjectService.Setup(mock => mock.Validate(release.Id))
            .ReturnsAsync(false);

            await using (var contentDbContext = InMemoryApplicationDbContext(contentDbContextId))
            {
                var service = SetupMetaGuidanceService(contentDbContext: contentDbContext,
                                                       metaGuidanceSubjectService: metaGuidanceSubjectService.Object);

                var result = await service.Validate(release.Id);

                Assert.True(result.IsLeft);

                metaGuidanceSubjectService.Verify(mock => mock.Validate(release.Id), Times.Once);

                ValidationTestUtil.AssertValidationProblem(result.Left, PublicMetaGuidanceRequired);
            }
        }
Esempio n. 24
0
        public async Task ListSubjects_FiltersSubjectsWithNoFileSubjectId()
        {
            var releaseId = Guid.NewGuid();

            var release = new Release
            {
                Id = releaseId
            };

            var releaseFile = new ReleaseFile
            {
                Release = release,
                File    = new File
                {
                    Filename = "data1.csv",
                    Type     = FileType.Data,
                }
            };

            var import = new DataImport
            {
                File   = releaseFile.File,
                Status = DataImportStatus.COMPLETE
            };

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

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

                await contentDbContext.AddRangeAsync(releaseFile);

                await contentDbContext.AddRangeAsync(import);

                await contentDbContext.SaveChangesAsync();
            }

            await using (var contentDbContext = InMemoryContentDbContext(contentDbContextId))
            {
                var service = BuildReleaseService(contentDbContext: contentDbContext);

                var result = await service.ListSubjects(release.Id);

                var subjects = result.AssertRight();

                Assert.Empty(subjects);
            }
        }
Esempio n. 25
0
        public void BatchesPath()
        {
            var releaseFile = new ReleaseFile
            {
                File = new File
                {
                    Id       = Guid.NewGuid(),
                    RootPath = Guid.NewGuid(),
                    Filename = "data.csv",
                    Type     = FileType.Data
                }
            };

            Assert.Equal(releaseFile.File.BatchesPath(), releaseFile.BatchesPath());
        }
Esempio n. 26
0
        public void Path()
        {
            var releaseFile = new ReleaseFile
            {
                File = new File
                {
                    Id       = Guid.NewGuid(),
                    RootPath = Guid.NewGuid(),
                    Filename = "ancillary.pdf",
                    Type     = Ancillary
                }
            };

            Assert.Equal(releaseFile.File.Path(), releaseFile.Path());
        }
        public async Task <File> Create(
            Guid releaseId,
            Guid subjectId,
            string filename,
            FileType type,
            Guid createdById,
            string name        = null,
            File replacingFile = null,
            File source        = null)
        {
            if (!SupportedFileTypes.Contains(type))
            {
                throw new ArgumentOutOfRangeException(nameof(type), type, "Cannot create file for file type");
            }

            if (type == Metadata && replacingFile != null)
            {
                throw new ArgumentException("replacingFile only used with Files of type Data, not Metadata.");
            }

            var releaseFile = new ReleaseFile
            {
                ReleaseId = releaseId,
                Name      = name,
                File      = new File
                {
                    Created     = DateTime.UtcNow,
                    CreatedById = createdById,
                    RootPath    = releaseId,
                    SubjectId   = subjectId,
                    Filename    = filename,
                    Type        = type,
                    Replacing   = replacingFile,
                    Source      = source
                }
            };
            var created = (await _contentDbContext.ReleaseFiles.AddAsync(releaseFile)).Entity;

            if (replacingFile != null)
            {
                _contentDbContext.Update(replacingFile);
                replacingFile.ReplacedBy = releaseFile.File;
            }

            await _contentDbContext.SaveChangesAsync();

            return(created.File);
        }
        private async Task <FileInfo> GetReleaseFileInfo(ReleaseFile releaseFile)
        {
            var blobExists = await _blobStorageService.CheckBlobExists(
                PrivateReleaseFiles,
                releaseFile.Path()
                );

            if (!blobExists)
            {
                return(releaseFile.ToFileInfoNotFound());
            }

            var blob = await _blobStorageService.GetBlob(PrivateReleaseFiles, releaseFile.Path());

            return(releaseFile.ToFileInfo(blob));
        }
Esempio n. 29
0
        static void upload(ReleaseService rs, FileInfo fi, string release, string checkfile)
        {
            if (isNewer(checkfile, fi.FullName))
            {
                Console.WriteLine("Uploading " + release + "...");
                ReleaseFile f = new ReleaseFile();
                f.Name     = fi.Name;
                f.MimeType = "application/octet-stream";
                f.FileName = fi.Name;
                f.FileType = ReleaseFileType.RuntimeBinary;
                f.FileData = File.ReadAllBytes(fi.FullName);

                List <ReleaseFile> files = new List <ReleaseFile>();
                files.Add(f);
                rs.UploadReleaseFiles("Z3", release, files, f.Name);
            }
        }
        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. 31
0
        public async Task GetReleaseCoverArtShouldGetReleaseCoverArt()
        {
            var release = new Release();

            var releaseFile = new ReleaseFile
            {
                ReleaseId = release.Id,
                FileType  = FileType.Image,
                IsPreview = true
            };

            await this.dbContext.ReleaseFiles.AddAsync(releaseFile);

            await this.dbContext.SaveChangesAsync();

            var coverArt = await this.releaseFilesService.GetReleaseCoverArt <ReleaseFileResourceModel>(release.Id);


            Assert.NotNull(coverArt);
        }
Esempio n. 32
0
 /// <remarks/>
 public System.IAsyncResult BeginUploadTheReleaseFiles(string projectName, string releaseName, ReleaseFile[] files, string recommendedFileName, string username, string password, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("UploadTheReleaseFiles", new object[] {
       projectName,
       releaseName,
       files,
       recommendedFileName,
       username,
       password}, callback, asyncState);
 }
Esempio n. 33
0
 public void UploadTheReleaseFiles(string projectName, string releaseName, ReleaseFile[] files, string recommendedFileName, string username, string password)
 {
     this.Invoke("UploadTheReleaseFiles", new object[] {
       projectName,
       releaseName,
       files,
       recommendedFileName,
       username,
       password});
 }
Esempio n. 34
0
 /// <remarks/>
 public void UploadTheReleaseFilesAsync(string projectName, string releaseName, ReleaseFile[] files, string recommendedFileName, string username, string password)
 {
     this.UploadTheReleaseFilesAsync(projectName, releaseName, files, recommendedFileName, username, password, null);
 }
Esempio n. 35
0
 /// <remarks/>
 public void UploadTheReleaseFilesAsync(string projectName, string releaseName, ReleaseFile[] files, string recommendedFileName, string username, string password, object userState)
 {
     if ((this.UploadTheReleaseFilesOperationCompleted == null)) {
     this.UploadTheReleaseFilesOperationCompleted = new System.Threading.SendOrPostCallback(this.OnUploadTheReleaseFilesOperationCompleted);
       }
       this.InvokeAsync("UploadTheReleaseFiles", new object[] {
       projectName,
       releaseName,
       files,
       recommendedFileName,
       username,
       password}, this.UploadTheReleaseFilesOperationCompleted, userState);
 }