protected void AddressCustomValidator_ServerValidate(object source, ServerValidateEventArgs args) { Profile profile = new Profile(); Validator profileValidator = ValidationFactory.CreateValidator <Profile>(); profile.AccountNumber = AccountNumberTextBox.Text; profile.Email = EmailTextBox.Text; profile.Name = NameTextBox.Text; profile.Homepage = HomepageTextBox.Text; profile.State = StateTextBox.Text; profile.Zip = ZipTextBox.Text; //int age; //profile.Age = int.TryParse(AgeTextBox.Text, out age) ? (int?)age : null; ValidationResults results = profileValidator.Validate(profile); results = results.FindAll(TagFilter.Include, "Address"); args.IsValid = results.IsValid; if (!results.IsValid) { foreach (ValidationResult result in results) { AddressCustomValidator.ErrorMessage = result.Message; } } }
public void FindAllReturnsNewInstance() { ValidationResults validationResults = new ValidationResults(); validationResults.AddResult(new ValidationResult("with tag1 - 1", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag1 - 2", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag2 - 1", null, null, "tag2", null)); validationResults.AddResult(new ValidationResult("with tag3 - 1", null, null, "tag3", null)); validationResults.AddResult(new ValidationResult("without tag - 1", null, null, null, null)); validationResults.AddResult(new ValidationResult("without tag - 2", null, null, null, null)); ValidationResults filteredValidationResults = validationResults.FindAll(TagFilter.Include, "tag1"); Assert.AreNotSame(validationResults, filteredValidationResults); }
public void RepeatedTagsDoNotResultInRepeatedResults() { ValidationResults validationResults = new ValidationResults(); validationResults.AddResult(new ValidationResult("with tag1 - 1", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag1 - 2", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag2 - 1", null, null, "tag2", null)); validationResults.AddResult(new ValidationResult("with tag3 - 1", null, null, "tag3", null)); validationResults.AddResult(new ValidationResult("without tag - 1", null, null, null, null)); validationResults.AddResult(new ValidationResult("without tag - 2", null, null, null, null)); ValidationResults filteredValidationResults = validationResults.FindAll(TagFilter.Include, "tag2", "tag2"); IDictionary <string, ValidationResult> filteredResultsMapping = ValidationTestHelper.GetResultsMapping(filteredValidationResults); Assert.AreEqual(1, filteredResultsMapping.Count); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag2 - 1")); }
public void CanFilterWithIgnoreWithMultipleTagsIncludingNull() { ValidationResults validationResults = new ValidationResults(); validationResults.AddResult(new ValidationResult("with tag1 - 1", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag1 - 2", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag2 - 1", null, null, "tag2", null)); validationResults.AddResult(new ValidationResult("with tag3 - 1", null, null, "tag3", null)); validationResults.AddResult(new ValidationResult("without tag - 1", null, null, null, null)); validationResults.AddResult(new ValidationResult("without tag - 2", null, null, null, null)); ValidationResults filteredValidationResults = validationResults.FindAll(TagFilter.Ignore, null, "tag2"); IDictionary <string, ValidationResult> filteredResultsMapping = ValidationTestHelper.GetResultsMapping(filteredValidationResults); Assert.AreEqual(3, filteredResultsMapping.Count); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag1 - 1")); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag1 - 2")); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag3 - 1")); }
public void CanFilterWithIgnoreWithMultipleTagsIncludingNull() { ValidationResults validationResults = new ValidationResults(); validationResults.AddResult(new ValidationResult("with tag1 - 1", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag1 - 2", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag2 - 1", null, null, "tag2", null)); validationResults.AddResult(new ValidationResult("with tag3 - 1", null, null, "tag3", null)); validationResults.AddResult(new ValidationResult("without tag - 1", null, null, null, null)); validationResults.AddResult(new ValidationResult("without tag - 2", null, null, null, null)); ValidationResults filteredValidationResults = validationResults.FindAll(TagFilter.Ignore, null, "tag2"); IDictionary<string, ValidationResult> filteredResultsMapping = ValidationTestHelper.GetResultsMapping(filteredValidationResults); Assert.AreEqual(3, filteredResultsMapping.Count); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag1 - 1")); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag1 - 2")); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag3 - 1")); }
public void RepeatedTagsDoNotResultInRepeatedResults() { ValidationResults validationResults = new ValidationResults(); validationResults.AddResult(new ValidationResult("with tag1 - 1", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag1 - 2", null, null, "tag1", null)); validationResults.AddResult(new ValidationResult("with tag2 - 1", null, null, "tag2", null)); validationResults.AddResult(new ValidationResult("with tag3 - 1", null, null, "tag3", null)); validationResults.AddResult(new ValidationResult("without tag - 1", null, null, null, null)); validationResults.AddResult(new ValidationResult("without tag - 2", null, null, null, null)); ValidationResults filteredValidationResults = validationResults.FindAll(TagFilter.Include, "tag2", "tag2"); IDictionary<string, ValidationResult> filteredResultsMapping = ValidationTestHelper.GetResultsMapping(filteredValidationResults); Assert.AreEqual(1, filteredResultsMapping.Count); Assert.IsTrue(filteredResultsMapping.ContainsKey("with tag2 - 1")); }