Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the ValidationSummary class.
 /// </summary>
 public ValidationSummary()
 {
     this.DefaultStyleKey = typeof(ValidationSummary);
     this._errors         = new ValidationItemCollection();
     this._validationSummaryItemDictionary = new Dictionary <string, ValidationSummaryItem>();
     this._displayedErrors           = new ValidationItemCollection();
     this._errors.CollectionChanged += new NotifyCollectionChangedEventHandler(this.Errors_CollectionChanged);
     this.Loaded           += new RoutedEventHandler(this.ValidationSummary_Loaded);
     this.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.ValidationSummary_IsEnabledChanged);
     if (DesignerProperties.IsInDesignTool)
     {
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
     }
 }
 /// <summary>
 /// Initializes a new instance of the ValidationSummary class.
 /// </summary>
 public ValidationSummary()
 {
     this.DefaultStyleKey = typeof(ValidationSummary);
     this._errors = new ValidationItemCollection();
     this._validationSummaryItemDictionary = new Dictionary<string, ValidationSummaryItem>();
     this._displayedErrors = new ValidationItemCollection();
     this._errors.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(this.Errors_CollectionChanged);
     this.Loaded += new RoutedEventHandler(this.ValidationSummary_Loaded);
     this.IsEnabledChanged += new DependencyPropertyChangedEventHandler(this.ValidationSummary_IsEnabledChanged);
     if (DesignerProperties.IsInDesignTool)
     {
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
         this.Errors.Add(new ValidationSummaryItem(resources.ValidationSummarySampleError, typeof(ValidationSummaryItem).Name, ValidationSummaryItemType.ObjectError, null, null));
     }
 }
Exemplo n.º 4
0
        /// <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);
            }
        }
Exemplo n.º 5
0
        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);
            }
        }