public void ErrorUpdates() { ValidationSummaryTestPage page = new ValidationSummaryTestPage(); this.TestPanel.Children.Add(page); ValidationSummary vs = page.validationSummary; this.EnqueueConditional(() => { return(page.validationSummary.Initialized); }); this.EnqueueCallback(() => { Assert.IsNotNull(vs); BindingExpression be = page.nameTextBox.GetBindingExpression(TextBox.TextProperty); Assert.IsNotNull(be); // Cause a validation error via the input control page.nameTextBox.Text = "ABCDEFG!@#$"; ReadOnlyObservableCollection <ValidationError> errors = Validation.GetErrors(page.nameTextBox); Assert.AreEqual(1, errors.Count); Assert.AreEqual(1, vs.Errors.Count); Assert.AreEqual(errors[0].Exception.Message, vs.Errors[0].Message); Assert.IsTrue(vs.HasErrors); // Fix the error page.nameTextBox.Text = "abcd"; errors = Validation.GetErrors(page.nameTextBox); Assert.AreEqual(0, errors.Count); Assert.AreEqual(0, vs.Errors.Count); Assert.IsFalse(vs.HasErrors); // Check ValidationErrorCollection page.nameTextBox.Text = "ABCDEFG!@#$"; ValidationSummaryItem newError = new ValidationSummaryItem(null, "new error", ValidationSummaryItemType.ObjectError, null, null); ValidationItemCollection errorCollection = vs.Errors as ValidationItemCollection; System.Collections.Specialized.NotifyCollectionChangedEventHandler handler = new System.Collections.Specialized.NotifyCollectionChangedEventHandler( delegate(object o, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { Assert.AreEqual(newError, e.NewItems[0], "new error does not match"); }); errorCollection.CollectionChanged += handler; Assert.AreEqual(1, errorCollection.Count); errorCollection.Add(newError); errorCollection.CollectionChanged -= handler; Assert.AreEqual(2, errorCollection.Count); errorCollection.ClearErrors(ValidationSummaryItemType.ObjectError); Assert.AreEqual(1, errorCollection.Count); }); EnqueueTestComplete(); }
/// <summary> /// Clears errors of the given source type /// </summary> /// <param name="errorType">The type of the error (Entity or Property)</param> internal void ClearErrors(ValidationSummaryItemType errorType) { // Clear entity errors ValidationItemCollection errorsToRemove = new ValidationItemCollection(); foreach (ValidationSummaryItem error in this) { if (error != null && error.ItemType == errorType) { errorsToRemove.Add(error); } } foreach (ValidationSummaryItem error in errorsToRemove) { this.Remove(error); } }
internal void ClearErrors(ValidationSummaryItemType errorType) { ValidationItemCollection items = new ValidationItemCollection(); foreach (ValidationSummaryItem item in this) { if (item == null) { continue; } if (item.ItemType == errorType) { items.Add(item); } } foreach (ValidationSummaryItem item2 in items) { base.Remove(item2); } }