private List <ValidationResult> validateProperty() { var controlValue = GetControlValidationValue(ControlToValidate); var value = TryConvertControlValue(controlValue); var objToValidate = setPropertyOnProxyObject(value); var results = ValidationCatalog.ValidateProperty(objToValidate, PropertyName, CurrentSpecificationBase).Errors; return(results); }
public void InheritedSpecifications_PolymorphicProperty_GetsSpecificationForInstanceAndNotClassType() { var classA = new ClassA() { BaseProperty = new InheritedClassA() }; var vn = ValidationCatalog.ValidateProperty(classA, c => c.BaseProperty); var d = vn.FindDescendents(desc => desc.Property.Name == "AdditionalProperty").ToList(); Assert.That(d.Any(), Is.True); }
public override IEnumerable <ModelValidationResult> Validate(object container) { var vn = ValidationCatalog.ValidateProperty(container, Metadata.PropertyName); foreach (var validationResult in vn.Errors) { //Don't set the display name because it won't bind on the view if you do yield return(new ModelValidationResult() { Message = validationResult.Message }); } }
public void ValidateProperty_NoValidationForProperty_ThrowsArgumentException() { //Create Rules Adhoc ValidationCatalog.AddSpecification <Contact>(x => { x.Check(c => c.FirstName).Required(); }); var contact = new Contact(); // Validation contact.LastName should result with only one error. Assert.Throws <ArgumentException>( () => { var propertyNotification = ValidationCatalog.ValidateProperty(contact, c => c.LastName); }); }
public void GetMessageForRuleWithMessageOverrrideAndMessageKey() { ValidationCatalog.Configure(x => x.AddMessageStore(new ResourceMessageStore(TestRuleErrorMessages.ResourceManager), "OverrideMessages")); ValidationCatalog.AddSpecification <Contact>(c => { c.Check(x => x.LastName).Required().IsAlpha().With(m => m.MessageKey = "TestRule"); } ); //Create an Entity var contact = new Contact(); contact.FirstName = null; contact.LastName = "1111"; var results = ValidationCatalog.ValidateProperty(contact, c => c.LastName); Assert.That(results.Errors.ToList().First().Message == "Last Name is invalid!"); }
public void ValidateProperty_SimpleProperty_OverridePropertyNameReturnsValidationNotification() { //Create Rules Adhoc ValidationCatalog.AddSpecification <Contact>(x => { x.Check(c => c.LastName, "Contact Last Name").Required(); x.Check(c => c.FirstName).Required(); }); var contact = new Contact(); // Validating contact as a whole should result in two errors. var objectNotification = ValidationCatalog.Validate(contact); Assert.IsFalse(objectNotification.IsValid); Assert.AreNotEqual(2, objectNotification.Errors); // Validation contact.LastName should result with only one error. var propertyNotification = ValidationCatalog.ValidateProperty(contact, c => c.LastName); Assert.IsFalse(propertyNotification.IsValid); Assert.AreNotEqual(1, propertyNotification.Errors); }
public void ValidateProperty_CollectionProperty_ReturnsValidationNotification() { //Create Rules Adhoc ValidationCatalog.AddSpecification <Address>(x => { x.Check(a => a.Street) .Required() .MaxLength(50); }); ValidationCatalog.AddSpecification <Contact>(x => { x.Check(c => c.Addresses).Required() .ForEachSpecification <Address>(); x.Check(c => c.FirstName).Required().MaxLength(100); }); var contact = new Contact(); contact.Addresses = new List <Address>() { new Address() }; // Validating contact as a whole should result in two errors. var objectNotification = ValidationCatalog.Validate(contact); Assert.IsFalse(objectNotification.IsValid); Assert.AreEqual(2, objectNotification.Errors.Count); // Validation contact.LastName should result with only one error. var propertyNotification = ValidationCatalog.ValidateProperty(contact, c => c.Addresses); Assert.IsFalse(propertyNotification.IsValid); Assert.AreEqual(1, propertyNotification.Errors.Count); }