public void ValidationSummaryPeerInvoke()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();
            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return page.validationSummary.Initialized; });
            this.EnqueueCallback(() =>
            {
                bool clicked = false;
                FocusingInvalidControlEventArgs eArgs = null;
                ValidationSummaryItem vsi = null;
                vs.FocusingInvalidControl += new EventHandler<FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    clicked = true;
                    eArgs = e;
                    vsi = e.Item;
                });

                ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs);
                Assert.IsNotNull(peer);
                ((IInvokeProvider)peer).Invoke();
                Assert.IsFalse(clicked, "No error is selected, so the event should not fire");

                ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this);
                vs.Errors.Add(newEsi);
                vs.ErrorsListBoxInternal.SelectedItem = newEsi;
                ((IInvokeProvider)peer).Invoke();
                Assert.IsTrue(clicked, "Invoking with a selected ESI triggers the event to fire");
                Assert.AreEqual(newEsi, vsi, "The ESI should match the selected item");
                Assert.AreEqual("property name", eArgs.Target.PropertyName, "The source should match the selected item");
            });
            EnqueueTestComplete();
        }
예제 #2
0
        public void Target()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(page.mainGrid, vs.Target);
                Assert.AreEqual(0, vs.Errors.Count);
                vs.Target = page.emailTextBox;
                page.emailTextBox.Text = "abcd";
                Assert.AreEqual(1, vs.Errors.Count);
                Assert.AreEqual("Email", vs.Errors[0].Sources[0].PropertyName);
                page.nameTextBox.Text = "ABCD!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                vs.Target             = page.nameTextBox;
                page.nameTextBox.Text = "ABCD!@#$%";
                Assert.AreEqual(1, vs.Errors.Count);
                Assert.AreEqual("Name", vs.Errors[0].Sources[0].PropertyName);
            });
            EnqueueTestComplete();
        }
예제 #3
0
        public void ShowErrorsInSummary()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                ExceptionHelper.ExpectArgumentNullException(delegate() { ValidationSummary.GetShowErrorsInSummary(null); }, "inputControl");
                ExceptionHelper.ExpectArgumentNullException(delegate() { ValidationSummary.SetShowErrorsInSummary(null, true); }, "inputControl");
                Assert.IsTrue(ValidationSummary.GetShowErrorsInSummary(page.emailTextBox));
                ValidationSummary.SetShowErrorsInSummary(page.emailTextBox, false);
                Assert.IsFalse(ValidationSummary.GetShowErrorsInSummary(page.emailTextBox));
                page.emailTextBox.Text = "1234";
                ReadOnlyObservableCollection <ValidationError> errors = Validation.GetErrors(page.emailTextBox);
                Assert.AreEqual(1, errors.Count);
                Assert.AreEqual(0, ((ICollection)vs.DisplayedErrors).Count);

                // Now set ShowErrorsInSummary to true and the errors will be added
                ValidationSummary.SetShowErrorsInSummary(page.emailTextBox, true);
                Assert.IsTrue(ValidationSummary.GetShowErrorsInSummary(page.emailTextBox));
                //Assert.AreEqual(0, ((ICollection)vs.DisplayedErrors).Count);
                //Assert.AreEqual(errors[0].Exception.Message, vs.DisplayedErrors[0].Message);
            });
            EnqueueTestComplete();
        }
        public void ValidationSummaryPeerInvoke()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                bool clicked = false;
                FocusingInvalidControlEventArgs eArgs = null;
                ValidationSummaryItem vsi             = null;
                vs.FocusingInvalidControl            += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    clicked = true;
                    eArgs   = e;
                    vsi     = e.Item;
                });

                ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs);
                Assert.IsNotNull(peer);
                ((IInvokeProvider)peer).Invoke();
                Assert.IsFalse(clicked, "No error is selected, so the event should not fire");

                ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this);
                vs.Errors.Add(newEsi);
                vs.ErrorsListBoxInternal.SelectedItem = newEsi;
                ((IInvokeProvider)peer).Invoke();
                Assert.IsTrue(clicked, "Invoking with a selected ESI triggers the event to fire");
                Assert.AreEqual(newEsi, vsi, "The ESI should match the selected item");
                Assert.AreEqual("property name", eArgs.Target.PropertyName, "The source should match the selected item");
            });
            EnqueueTestComplete();
        }
예제 #5
0
        public void HasDisplayedErrors()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs, "ValidationSummary is null");
                Assert.IsFalse(vs.HasDisplayedErrors, "ValidationSummary should have no errors");
                vs.HasDisplayedErrors = true;
                Assert.IsTrue(vs.HasDisplayedErrors, "HasDisplayedErrors should now be true");
                vs.HasDisplayedErrors = false;
                Assert.IsFalse(vs.HasDisplayedErrors, "HasDisplayedErrors set to false");

                page.nameTextBox.Text = "ABCD!@#$";
                page.nameTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
            });
            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(vs.HasDisplayedErrors, "HasDisplayedErrors set to true from error");
            });
            EnqueueTestComplete();
        }
예제 #6
0
        public void FocusCycling()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                ValidationSummaryItem newVsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);

                ValidationSummaryItemSource source1 = new ValidationSummaryItemSource("prop1", page.nameTextBox);
                newVsi.Sources.Add(source1);
                ValidationSummaryItemSource source2 = new ValidationSummaryItemSource("prop2", page.emailTextBox);
                newVsi.Sources.Add(source2);

                vs.Errors.Add(newVsi);
                ValidationSummaryItem newVsi2 = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);
                vs.Errors.Add(newVsi2);

                // Setup the delegate to capture the event
                vs.ErrorsListBoxInternal.SelectedItem      = newVsi;
                ValidationSummaryItemSource selectedSource = null;
                vs.FocusingInvalidControl += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    selectedSource = e.Target;
                });

                // First click
                vs.ExecuteClickInternal();
                Assert.AreEqual(source1, selectedSource);

                // Second
                vs.ExecuteClickInternal();
                Assert.AreEqual(source2, selectedSource);

                // Cycle back
                vs.ExecuteClickInternal();
                Assert.AreEqual(source1, selectedSource);

                // Change the ESI
                vs.ErrorsListBoxInternal.SelectedItem = newVsi2;

                // First click with new ESI
                vs.ExecuteClickInternal();
                Assert.AreEqual(null, selectedSource);
            });

            EnqueueTestComplete();
        }
예제 #7
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();
        }
예제 #8
0
        public void HasDisplayedErrorsReadOnly()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs);
                Assert.IsFalse(vs.HasDisplayedErrors);
                string ExpectedExceptionMessage = String.Format(System.Windows.Controls.Data.Input.Resources.UnderlyingPropertyIsReadOnly, "HasDisplayedErrors");
                ExceptionHelper.ExpectInvalidOperationException(delegate() { vs.SetValue(ValidationSummary.HasDisplayedErrorsProperty, true); }, ExpectedExceptionMessage);
            });
            EnqueueTestComplete();
        }
예제 #9
0
        public void FocusErrorsOnClick()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs);
                Assert.IsTrue(vs.FocusControlsOnClick);
                vs.FocusControlsOnClick = false;
                Assert.IsFalse(vs.FocusControlsOnClick);

                //
            });
            EnqueueTestComplete();
        }
예제 #10
0
        public void FocusingInvalidControl()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);
                bool clicked = false;

                // Setup the delegate to capture the event
                vs.ErrorsListBoxInternal.SelectedIndex = 0;

                FocusingInvalidControlEventArgs eArgs = null;
                ValidationSummaryItem vsi             = null;
                vs.FocusingInvalidControl            += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    clicked = true;
                    eArgs   = e;
                    vsi     = e.Item;
                });

                // Simulate a click on the first item
                vs.ExecuteClickInternal();
                Assert.IsTrue(clicked);
                Assert.IsNotNull(eArgs);
                Assert.IsNotNull(vsi);
                Assert.AreEqual("Name", vsi.Sources[0].PropertyName);

                // Set the flag to false, clicks should no longer occur, as it only affects focus
                vs.FocusControlsOnClick = false;
                clicked = false;
                eArgs   = null;
                vs.ExecuteClickInternal();
                Assert.IsFalse(clicked);
                Assert.IsNull(eArgs);
            });
            EnqueueTestComplete();
        }
예제 #11
0
        public void ErrorStyle()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs.ErrorsListBoxInternal);
                Assert.IsNotNull(vs.ErrorStyle);
                Style testErrorStyle = page.LayoutRoot.Resources["testErrorStyle"] as Style;
                vs.ErrorStyle        = testErrorStyle;
                Assert.AreEqual(testErrorStyle, vs.ErrorStyle);
                Assert.AreEqual(testErrorStyle, vs.ErrorsListBoxInternal.ItemContainerStyle);
            });
            EnqueueTestComplete();
        }
예제 #12
0
        public void GetHeaderString()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                // Add errors and see the header string update
                Assert.AreEqual("0 Errors", vs.GetHeaderString());
                vs.Errors.Add(new ValidationSummaryItem(null, "", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("1 Error", vs.GetHeaderString());
                vs.Errors.Add(new ValidationSummaryItem(null, "", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("2 Errors", vs.GetHeaderString());
            });
            EnqueueTestComplete();
        }
예제 #13
0
        public void Header()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(null, vs.Header);
                vs.Header = "newheader";
                Assert.AreEqual("newheader", vs.Header);
                Assert.AreEqual(vs.Header, vs.HeaderContentControlInternal.Content);
                vs.Header = null;
                Assert.IsNull(vs.Header);
                Assert.AreEqual("0 Errors", vs.HeaderContentControlInternal.Content);
            });
            EnqueueTestComplete();
        }
예제 #14
0
        public void HeaderTemplate()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs);
                Assert.IsNotNull(vs.HeaderTemplate);
                DataTemplate testDataTemplate = page.LayoutRoot.Resources["testDataTemplate"] as DataTemplate;
                Assert.IsNotNull(testDataTemplate);
                vs.HeaderTemplate = testDataTemplate;
                Assert.AreEqual(testDataTemplate, vs.HeaderTemplate);
                Assert.AreEqual(testDataTemplate, vs.HeaderContentControlInternal.ContentTemplate);
            });
            EnqueueTestComplete();
        }
예제 #15
0
        public void ErrorClickedSelectedItem()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                ValidationSummaryItem newVsi = new ValidationSummaryItem("test error", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource("property name", page.nameTextBox), this);
                vs.Errors.Add(newVsi);

                bool clicked = false;

                // Setup the delegate to capture the event
                vs.ErrorsListBoxInternal.SelectedItem = newVsi;
                FocusingInvalidControlEventArgs eArgs = null;
                ValidationSummaryItem vsi             = null;
                vs.FocusingInvalidControl            += new EventHandler <FocusingInvalidControlEventArgs>(delegate(object o, FocusingInvalidControlEventArgs e)
                {
                    clicked = true;
                    eArgs   = e;
                    vsi     = e.Item;
                });

                // Simulate a click on the first item
                vs.ExecuteClickInternal();
                Assert.IsTrue(clicked);
                Assert.IsNotNull(vsi);
                Assert.AreEqual("test error", vsi.Message);
                Assert.AreEqual(ValidationSummaryItemType.ObjectError, vsi.ItemType);
                Assert.AreEqual(this, vsi.Context);
                Assert.AreEqual(page.nameTextBox, vsi.Sources[0].Control);
                Assert.AreEqual("property name", vsi.Sources[0].PropertyName);
            });
            EnqueueTestComplete();
        }
예제 #16
0
        public void DisplayedErrors_ItemTypeUpdates()
        {
            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!@#$";
                Assert.AreEqual(1, vs.DisplayedErrors.Count);
                Assert.IsTrue(vs.HasErrors);
                Assert.IsTrue(vs.HasDisplayedErrors);

                // Add object error
                ValidationSummaryItem newError = new ValidationSummaryItem(null, "new error", ValidationSummaryItemType.ObjectError, null, null);
                vs.Errors.Add(newError);
                Assert.AreEqual(2, vs.DisplayedErrors.Count);
                Assert.IsTrue(vs.HasErrors);
                Assert.IsTrue(vs.HasDisplayedErrors);

                // Change filter
                vs.Filter = ValidationSummaryFilters.ObjectErrors;
                Assert.AreEqual(1, vs.DisplayedErrors.Count);
                Assert.IsTrue(vs.HasErrors);
                Assert.IsTrue(vs.HasDisplayedErrors);

                // Change ItemType so that there's no object errors
                newError.ItemType = ValidationSummaryItemType.PropertyError;
                Assert.AreEqual(0, vs.DisplayedErrors.Count);
                Assert.IsTrue(vs.HasErrors);
                Assert.IsFalse(vs.HasDisplayedErrors);
            });
            EnqueueTestComplete();
        }
예제 #17
0
        public void SelectionChanged()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, vs.Errors.Count);

                ValidationSummaryItem newEsi = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);

                ValidationSummaryItemSource source1 = new ValidationSummaryItemSource("prop1", page.nameTextBox);
                newEsi.Sources.Add(source1);
                ValidationSummaryItemSource source2 = new ValidationSummaryItemSource("prop2", page.emailTextBox);
                newEsi.Sources.Add(source2);

                vs.Errors.Add(newEsi);
                ValidationSummaryItem newEsi2 = new ValidationSummaryItem(null, "test error", ValidationSummaryItemType.ObjectError, null, null);
                vs.Errors.Add(newEsi2);

                // Setup the delegate to capture the event
                bool selectionChanged = false;
                vs.SelectionChanged  += new EventHandler <SelectionChangedEventArgs>(delegate(object o, SelectionChangedEventArgs e)
                {
                    selectionChanged = true;
                });

                vs.ErrorsListBoxInternal.SelectedItem = newEsi;
                vs.ErrorsListBoxInternal.SelectedItem = newEsi2;
                // First click
                vs.ExecuteClickInternal();
                Assert.IsTrue(selectionChanged);
            });

            EnqueueTestComplete();
        }
        public void ValidationSummaryPeer()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();
            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return page.validationSummary.Initialized; });
            this.EnqueueCallback(() =>
            {
                ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs);
                Assert.IsNotNull(peer);
                Assert.AreEqual(AutomationControlType.Group, peer.GetAutomationControlType());
                Assert.AreEqual("ValidationSummary", peer.GetClassName());
                Assert.AreEqual("0 Errors", peer.GetName());

                vs.Errors.Add(new ValidationSummaryItem("header1", "msg1", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("1 Error", peer.GetName());
                vs.Errors.Add(new ValidationSummaryItem("header2", "msg2", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("2 Errors", peer.GetName());
            });
            EnqueueTestComplete();
        }
예제 #19
0
        public void Filter()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(vs);
                ICollection filteredErrors = vs.DisplayedErrors;
                Assert.IsNotNull(filteredErrors);
                Assert.AreEqual(0, filteredErrors.Count);
                page.nameTextBox.Text = "ABCDEFG!@#$";
                Assert.AreEqual(1, filteredErrors.Count);
                page.emailTextBox.Text = "abcd";
                Assert.AreEqual(2, filteredErrors.Count);

                vs.Errors.Add(new ValidationSummaryItem(null, "custom1", ValidationSummaryItemType.ObjectError, null, null));
                Assert.AreEqual(3, filteredErrors.Count);
                vs.Errors.Add(new ValidationSummaryItem(null, "custom2", ValidationSummaryItemType.ObjectError, null, null));
                Assert.AreEqual(4, filteredErrors.Count);

                vs.Filter = ValidationSummaryFilters.ObjectErrors;
                Assert.AreEqual(2, filteredErrors.Count);

                vs.Filter = ValidationSummaryFilters.PropertyErrors;
                Assert.AreEqual(2, filteredErrors.Count);
                vs.Filter = ValidationSummaryFilters.None;
                Assert.AreEqual(0, filteredErrors.Count);
                vs.Filter = ValidationSummaryFilters.ObjectErrors | ValidationSummaryFilters.PropertyErrors;
                Assert.AreEqual(4, filteredErrors.Count, "or'ing entity and property");
                vs.Filter = ValidationSummaryFilters.All;
                Assert.AreEqual(4, filteredErrors.Count, "all");
            });
            EnqueueTestComplete();
        }
예제 #20
0
        public void SortByVisualTreeOrdering()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(0, ValidationSummary.SortByVisualTreeOrdering(null, null), "both null");
                Assert.AreEqual(0, ValidationSummary.SortByVisualTreeOrdering(null, page.emailTextBox), "null 1");
                Assert.AreEqual(0, ValidationSummary.SortByVisualTreeOrdering(page.nameTextBox, null), "null 2");
                Assert.AreEqual(-1, ValidationSummary.SortByVisualTreeOrdering(page.nameTextBox, page.emailTextBox), "same level");
                Assert.AreEqual(0, ValidationSummary.SortByVisualTreeOrdering(page.mainPanel, page.mainPanel), "same reference");
                Assert.AreEqual(1, ValidationSummary.SortByVisualTreeOrdering(page.emailTextBox, page.nameTextBox), "inverse");
                Assert.AreEqual(0, ValidationSummary.SortByVisualTreeOrdering(page.emailTextBox, new TextBox()), "not in visual tree");
                Assert.AreEqual(-1, ValidationSummary.SortByVisualTreeOrdering(page.emailTextBox, page.tb1), "nested");
                Assert.AreEqual(1, ValidationSummary.SortByVisualTreeOrdering(page.lastTextBox, page.tb1), "nested after");
                Assert.AreEqual(-1, ValidationSummary.SortByVisualTreeOrdering(page.mainPanel, page.tb1), "parent child");
                Assert.AreEqual(1, ValidationSummary.SortByVisualTreeOrdering(page.tb1, page.mainPanel), "parent child reverse");
            });
            EnqueueTestComplete();
        }
        public void ValidationSummaryPeer()
        {
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            this.TestPanel.Children.Add(page);
            ValidationSummary vs = page.validationSummary;

            this.EnqueueConditional(() => { return(page.validationSummary.Initialized); });
            this.EnqueueCallback(() =>
            {
                ValidationSummaryAutomationPeer peer = new ValidationSummaryAutomationPeer(vs);
                Assert.IsNotNull(peer);
                Assert.AreEqual(AutomationControlType.Group, peer.GetAutomationControlType());
                Assert.AreEqual("ValidationSummary", peer.GetClassName());
                Assert.AreEqual("0 Errors", peer.GetName());

                vs.Errors.Add(new ValidationSummaryItem("header1", "msg1", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("1 Error", peer.GetName());
                vs.Errors.Add(new ValidationSummaryItem("header2", "msg2", ValidationSummaryItemType.PropertyError, null, null));
                Assert.AreEqual("2 Errors", peer.GetName());
            });
            EnqueueTestComplete();
        }
예제 #22
0
        public void ErrorInfoSorting()
        {
            ValidationSummaryItem     ei1  = new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null);
            ValidationSummaryTestPage page = new ValidationSummaryTestPage();

            // 1. Compare ErrorInfo reference
            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(null, null), "1. null null");
            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(null, ei1), "1. null ei1");
            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(ei1, null), "1. ei1 null");

            // 2. Compare ErrorType
            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null)),
                                  "2. None None");

            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null)),
                                  "2. EntityError EntityError");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.PropertyError, null, null)),
                                  "2. EntityError PropertyError");

            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.PropertyError, null, null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null)),
                                  "2. PropertyError EntityError");

            // 3. Compare Control
            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, null, null)),
                                  "3. null null");

            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "3. tb1 tb1");

            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, null), null)),
                                  "3. tb1 null");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, null), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "3. null tb1");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb2), null)),
                                  "3. tb1 tb2");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb2), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb4), null)),
                                  "3. tb2 tb4 increasing tabindex");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb6), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb2), null)),
                                  "3. tb6 tb2 decreasing tabindex");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb3), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb5), null)),
                                  "3. tb3 tb5 increasing tabindex");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb3), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb7), null)),
                                  "3. tb3 tb7 Name compare");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb7), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb6), null)),
                                  "3. tb7 tb6 ordering compare");

            TextBox tbNoName = new TextBox();

            tbNoName.TabIndex = 2;
            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb7), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, tbNoName), null)),
                                  "3. tb7 tbNoName Name compare");

            // 4. MessageHeader compare
            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "4. null null");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem("", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "4. null ''");

            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem("blah", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "4. blah null");

            // 5. ErrorMessage
            Assert.AreEqual <int>(0, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "5. null null");

            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem("a", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "5. a null");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem(null, null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem("a", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "5. null a");

            Assert.AreEqual <int>(1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem("b", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem("a", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "5. b a");

            Assert.AreEqual <int>(-1, ValidationSummary.CompareValidationSummaryItems(
                                      new ValidationSummaryItem("a", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null),
                                      new ValidationSummaryItem("b", null, ValidationSummaryItemType.ObjectError, new ValidationSummaryItemSource(null, page.tb1), null)),
                                  "5. a b");
        }