public IEnumerable <ValidationResult> Validate(Resource resource) { var result = new List <ValidationResult>(); DotNetAttributeValidation.TryValidate(resource, result, true); return(result); }
public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); // The ID field does not need to be an abolute URI, // this should be the ResourceIdentity. // if (Id != null && !new Uri(Id,UriKind.RelativeOrAbsolute).IsAbsoluteUri) // result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry id must be an absolute URI")); if (Meta != null) { // if (!String.IsNullOrEmpty(this.Meta.VersionId) && !new Uri(Id,UriKind.RelativeOrAbsolute).IsAbsoluteUri) // result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry selflink must be an absolute URI")); if (Meta.Tag != null && validationContext.ValidateRecursively()) { DotNetAttributeValidation.TryValidate(Meta.Tag, result, true); } } // and process all the invariants from the resource ValidateInvariants(result); return(result); }
/// <summary> /// Validate Patient /// </summary> /// <param name="patient"></param> /// <returns></returns> private static bool ValidatePatient(Patient patient) { ICollection <ValidationResult> results = new List <ValidationResult>(); var success = DotNetAttributeValidation.TryValidate(patient, results, true); return(success); }
public virtual IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); if (Id != null && !Id.IsAbsoluteUri) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry id must be an absolute URI")); } if (Bundle.UriHasValue(SelfLink) && !SelfLink.IsAbsoluteUri) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry selflink must be an absolute URI")); } if (Links.FirstLink != null || Links.LastLink != null || Links.PreviousLink != null || Links.NextLink != null) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Paging links can only be used on feeds, not entries")); } if (Tags != null && validationContext.ValidateRecursively()) { DotNetAttributeValidation.TryValidate(Tags, result, true); } return(result); }
public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); if (Meta != null) { if (Meta.Tag != null && validationContext.ValidateRecursively()) { DotNetAttributeValidation.TryValidate(Meta.Tag, result, true); } } return(result); }
public IEnumerable <ValidationFailure> Validate(PropertyValidatorContext context) { EnsureArg.IsNotNull(context, nameof(context)); if (context.PropertyValue is Resource resource) { var results = new List <ValidationResult>(); if (!DotNetAttributeValidation.TryValidate(resource, results, recurse: false)) { foreach (var error in results) { yield return(new ValidationFailure(error.MemberNames?.FirstOrDefault(), error.ErrorMessage)); } } } }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); //if (String.IsNullOrWhiteSpace(Title)) // result.Add(new ValidationResult("Feed must contain a title", FhirValidator.SingleMemberName("Title")); //if (!UriHasValue(Id)) // result.Add(new ValidationResult("Feed must have an id")); //else // if (!Id.IsAbsoluteUri) // result.Add(new ValidationResult("Feed id must be an absolute URI")); if (Id != null && !Id.IsAbsoluteUri) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Feed id must be an absolute URI")); } //if (LastUpdated == null) // result.Add(new ValidationResult("Feed must have a updated date")); if (Links.SearchLink != null) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Links with rel='search' can only be used on feed entries")); } bool feedHasAuthor = !String.IsNullOrEmpty(this.AuthorName); if (Entries != null && validationContext.ValidateRecursively()) { foreach (var entry in Entries.Where(e => e != null)) { if (!feedHasAuthor && entry is ResourceEntry && String.IsNullOrEmpty(((ResourceEntry)entry).AuthorName)) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Bundle's author and Entry author cannot both be empty")); } DotNetAttributeValidation.TryValidate(entry, result, validationContext.ValidateRecursively()); } } return(result); }
public void ValidateDemoPatient() { var s = new StringReader(TestDataHelper.ReadTestData(@"TestPatient.xml")); var patient = new FhirXmlParser().Parse <Patient>(XmlReader.Create(s)); ICollection <ValidationResult> results = new List <ValidationResult>(); foreach (var contained in patient.Contained) { ((DomainResource)contained).Text = new Narrative() { Div = "<wrong />" } } ; Assert.IsFalse(DotNetAttributeValidation.TryValidate(patient, results, true)); Assert.IsTrue(results.Count > 0); results.Clear(); foreach (DomainResource contained in patient.Contained) { contained.Text = null; } // Try again Assert.IsTrue(DotNetAttributeValidation.TryValidate(patient, results, true)); patient.Identifier[0].System = "urn:oid:crap really not valid"; results = new List <ValidationResult>(); Assert.IsFalse(DotNetAttributeValidation.TryValidate(patient, results, true)); Assert.IsTrue(results.Count > 0); } }
public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { var result = new List <ValidationResult>(); if (Id != null && !new Uri(Id, UriKind.RelativeOrAbsolute).IsAbsoluteUri) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry id must be an absolute URI")); } if (Meta != null) { if (!String.IsNullOrEmpty(this.Meta.VersionId) && !new Uri(Id, UriKind.RelativeOrAbsolute).IsAbsoluteUri) { result.Add(DotNetAttributeValidation.BuildResult(validationContext, "Entry selflink must be an absolute URI")); } if (Meta.Tag != null && validationContext.ValidateRecursively()) { DotNetAttributeValidation.TryValidate(Meta.Tag, result, true); } } return(result); }
private static void validateElement(object value, ValidationContext validationContext, List <ValidationResult> result) { DotNetAttributeValidation.TryValidate(value, result, validationContext.ValidateRecursively()); }
public bool TryValidate(ResourceElement value, ICollection <ValidationResult> validationResults = null, bool recurse = false) { return(DotNetAttributeValidation.TryValidate(value.ToPoco(), validationResults, recurse)); }