/// <summary> /// Validates an <see cref="StoreRequest"/>. /// </summary> /// <param name="request">The request to validate.</param> /// <exception cref="BadRequestException">Thrown when request body is missing.</exception> /// <exception cref="UidValidator">Thrown when the specified StudyInstanceUID is not a valid identifier.</exception> // TODO cleanup this method with Unit tests #72595 public static void ValidateRequest(StoreRequest request) { if (request.RequestBody == null) { throw new BadRequestException(DicomCoreResource.MissingRequestBody); } if (request.StudyInstanceUid != null) { DicomElementMinimumValidation.ValidateUI(request.StudyInstanceUid, nameof(request.StudyInstanceUid)); } }
private static void ValidatePrivateCreator(DicomTag tag, string privateCreator, string tagPath) { if (!tag.IsPrivate) { // Standard tags should not have private creator. if (!string.IsNullOrWhiteSpace(privateCreator)) { throw new ExtendedQueryTagEntryValidationException( string.Format(CultureInfo.InvariantCulture, DicomCoreResource.PrivateCreatorNotEmpty, tagPath)); } return; } // PrivateCreator Tag should not have privateCreator. if (tag.DictionaryEntry == DicomDictionary.PrivateCreatorTag) { if (!string.IsNullOrWhiteSpace(privateCreator)) { throw new ExtendedQueryTagEntryValidationException( string.Format(CultureInfo.InvariantCulture, DicomCoreResource.PrivateCreatorNotEmptyForPrivateIdentificationCode, tagPath)); } return; } // Private tag except PrivateCreator requires privateCreator if (string.IsNullOrWhiteSpace(privateCreator)) { throw new ExtendedQueryTagEntryValidationException( string.Format(CultureInfo.InvariantCulture, DicomCoreResource.MissingPrivateCreator, tagPath)); } try { DicomElementMinimumValidation.ValidateLO(privateCreator, nameof(privateCreator)); } catch (DicomElementValidationException ex) { throw new ExtendedQueryTagEntryValidationException( string.Format(CultureInfo.InvariantCulture, DicomCoreResource.PrivateCreatorNotValidLO, tagPath), ex); } }
[InlineData("0123456789123")] // exceed max length public void GivenISInvalidValue_WhenValidating_Throws(string value) { Assert.Throws <DicomElementValidationException>(() => DicomElementMinimumValidation.ValidateIS(value, nameof(value))); }
public void GivenUIInvalidValue_WhenValidating_Throws(string id) { Assert.Throws <InvalidIdentifierException>(() => DicomElementMinimumValidation.ValidateUI(id, nameof(id))); }