public void IsDatasetNominationValidForApproval_MaximumTagsExceeded_ExpectError() { var nomination = new DatasetNomination { Tags = new List <string>(Enumerable.Repeat("*", 11)) }; IsMessageFoundForApproval($"Maximum of {Constraints.MaxTags} tags allowed.", nomination).Should().BeTrue(); }
public void IsDatasetNominationValidForUpdate_MissingOtherLicenseName(NominationLicenseType licenseType, bool expectError) { var nomination = new DatasetNomination { NominationLicenseType = licenseType, OtherLicenseName = String.Empty }; IsMessageFoundForUpdate("License Name is required.", nomination).Should().Be(expectError); }
public void IsDatasetNominationValidForUpdate_OtherLicenseContentTooLong(NominationLicenseType licenseType, bool expectError) { var nomination = new DatasetNomination { NominationLicenseType = licenseType, OtherLicenseContentHtml = new string('*', Constraints.OtherLicenseContentHtml + 1) }; IsMessageFoundForUpdate($"License Content must be maximum of {Constraints.OtherLicenseContentHtml} characters.", nomination).Should().Be(expectError); }
public void IsDatasetNominationValidForUpdate_OtherLicenseContentRequired(NominationLicenseType licenseType, bool expectError) { var nomination = new DatasetNomination { NominationLicenseType = licenseType, OtherLicenseContentHtml = string.Empty }; IsMessageFoundForUpdate("License Content is required.", nomination).Should().Be(expectError); }
public void IsDatasetNominationValidForUpdate_OtherLicenseFileNameTooLong(NominationLicenseType licenseType, bool expectError) { var nomination = new DatasetNomination { NominationLicenseType = licenseType, OtherLicenseFileName = new string('*', Constraints.MaxFileNameLength + 1) }; IsMessageFoundForUpdate($"License File Name must be maximum of {Constraints.MaxFileNameLength} characters.", nomination).Should().Be(expectError); }
public static DatasetNomination GenerateNominationWithAllMaxLengthFieldsExceeded() { var nomination = new DatasetNomination { Name = new string('*', Constraints.LongName + 1), Description = new string('*', Constraints.MedDescription + 1), DatasetUrl = new string('*', Constraints.UrlLength + 1), ProjectUrl = new string('*', Constraints.UrlLength + 1), Version = new string('*', Constraints.VersionLength + 1), Domain = new string('*', Constraints.ShortName + 1), ContactName = new string('*', Constraints.ContactNameLength + 1), ContactInfo = new string('*', Constraints.ContactInfoLength + 1) }; return(nomination); }
public async Task <IActionResult> CreateNomination( [FromForm] DatasetNomination nomination, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var validationResult = ValidationService.IsDatasetNominationValidForCreate(nomination); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } await this.Storage.CreateDatasetNominationAsync(this.User, nomination, cancellationToken); return(this.Ok(true)); }
public async Task <Guid?> UpdateDatasetNominationAsync(ClaimsPrincipal user, DatasetNomination nomination, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var userId = GetUserId(user); if (!userId.HasValue) { return(null); } var name = GetUserName(user); var email = GetUserEmail(user); var options = new FeedOptions { PartitionKey = new PartitionKey(WellKnownIds.DatasetNominationDatasetId.ToString()) }; var uri = this.UserDataDocumentCollectionUri; var existingDocument = this.Client.CreateDocumentQuery <DatasetNominationStorageItem>(uri, options) .Where(r => r.Id == nomination.Id) .AsEnumerable() .SingleOrDefault(); if (existingDocument == null) { throw new InvalidOperationException("Dataset Nomination not found."); } var storageItem = nomination.ToDatasetNominationStorageItem((d) => { d.Created = existingDocument.Created; d.CreatedByUserId = existingDocument.CreatedByUserId; d.CreatedByUserName = existingDocument.CreatedByUserName; d.CreatedByUserEmail = existingDocument.CreatedByUserEmail; d.ModifiedByUserName = name; d.ModifiedByUserEmail = email; d.Modified = DateTime.UtcNow; }); uri = UserDataDocumentUriById(storageItem.Id.ToString()); await this.Client.ReplaceDocumentAsync(uri, storageItem); return(nomination.Id); }
private DatasetNomination CreateNominationForLicensePropertyTests(NominationLicenseType licenseType) { var licenseId = Guid.NewGuid(); var isOtherLicense = licenseType == NominationLicenseType.HtmlText || licenseType == NominationLicenseType.InputFile; var nomination = new DatasetNomination() { NominationLicenseType = licenseType, LicenseId = isOtherLicense ? default(Guid) : licenseId, OtherLicenseContentHtml = licenseType == NominationLicenseType.HtmlText ? "OtherLicenseContentHtml" : null, OtherLicenseFileName = licenseType == NominationLicenseType.InputFile ? "OtherLicenseFileName" : null, OtherLicenseAdditionalInfoUrl = "OtherLicenseAdditionalInfoUrl", OtherLicenseName = "OtherLicenseName" }; return(nomination); }
public async Task <IActionResult> Reject( [FromRoute] Guid id, [FromBody] DatasetNomination nomination, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (id != nomination.Id) { throw new InvalidOperationException("Nomination id is not valid."); } // intentionally no validation for Rejecting a nomination bool found = await UserDataStorage.RejectNominationAsync(id, this.User, cancellationToken).ConfigureAwait(false); if (!found) { return(this.NotFound()); } return(Ok()); }
public async Task <IActionResult> CreateApproved( [FromForm] DatasetNomination nomination, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var validationResult = ValidationService.IsDatasetNominationValidForApproval(nomination); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } nomination.NominationStatus = NominationStatus.Approved; var nominationId = await UserDataStorage.CreateDatasetNominationAsync(this.User, nomination, cancellationToken).ConfigureAwait(false); if (nominationId.HasValue) { return(this.Ok(nominationId)); } return(this.NotFound()); }
public static DatasetNominationStorageItem ToDatasetNominationStorageItem(this DatasetNomination source, Action <DatasetNominationStorageItem> update = null) { return(ModelMapper <DatasetNominationMapper> .Mapper.Map(source).WithUpdate(update)); }
private async Task CreateDatasetDocument( DatasetNomination nomination, DatasetImportProperties storage, (ICollection <string> fileTypes, int fileCount, long fileSize, string containerUri) fileDetails,