public void Reminder()
        {
            var textBox = new TextBox();
            var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            Assert.Fail("Implement");
            // CollectionAssert.IsEmpty(errorNode.Errors);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.AreEqual(new[] {TestValidationError.GetFor(textBox)} ,errorNode.Errors);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.IsEmpty(errorNode.Errors);
        }
Beispiel #2
0
            public void TextBoxSetSetForInputTypesTextBox()
            {
                var textBox    = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection {
                    typeof(System.Windows.Controls.TextBox), typeof(Selector)
                };

                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                CollectionAssert.IsEmpty(Scope.GetErrors(textBox));

                var errorNode = (InputNode)Scope.GetNode(textBox);

                Assert.AreEqual(textBox, errorNode.Source);
                Assert.AreEqual(false, errorNode.HasError);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);

                textBox.SetValidationError(validationError);
                var expectedErrors = new[] { validationError };

                Assert.AreEqual(true, Scope.GetHasError(textBox));
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));

                Assert.AreEqual(true, errorNode.HasError);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);
            }
 private void ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     var selectedItems = ((ListBox)sender).SelectedItems.Cast<Type>();
     var types = new InputTypeCollection();
     types.AddRange(selectedItems);
     Scope.SetForInputTypes(this.Form, types);
 }
            public static void Notifies()
            {
                var textBox = new System.Windows.Controls.TextBox();

                using (var textBoxEvents = textBox.SubscribeScopeEvents())
                {
                    var stackPanel = new StackPanel();
                    using (var stackPanelEVents = stackPanel.SubscribeScopeEvents())
                    {
                        stackPanel.Children.Add(textBox);
                        var inputTypes = new InputTypeCollection {
                            typeof(System.Windows.Controls.TextBox), typeof(Selector)
                        };
                        Scope.SetForInputTypes(stackPanel, inputTypes);
                        var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                        textBox.SetValidationError(validationError);
                        var expectedEvents = new List <ScopeValidationErrorEventArgs>
                        {
                            new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Added),
                        };
                        CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);
                        CollectionAssert.AreEqual(expectedEvents, stackPanelEVents, ScopeValidationErrorEventArgsComparer.Default);

                        textBox.ClearValidationError(validationError);
                        expectedEvents.Add(new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Removed));
                        CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);
                        CollectionAssert.AreEqual(expectedEvents, stackPanelEVents, ScopeValidationErrorEventArgsComparer.Default);
                    }
                }
            }
            public static void NodesForSelectorAndSlider()
            {
                var textBox    = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(Selector), typeof(Slider)
                };

                Scope.SetForInputTypes(stackPanel, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);

                textBox.SetValidationError(validationError);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));
            }
        public void Reminder()
        {
            var textBox    = new TextBox();
            var inputTypes = new InputTypeCollection {
                typeof(TextBox), typeof(Selector)
            };

            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);

            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            Assert.Fail("Implement");
            // CollectionAssert.IsEmpty(errorNode.Errors);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.AreEqual(new[] {TestValidationError.GetFor(textBox)} ,errorNode.Errors);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            // CollectionAssert.IsEmpty(errorNode.Errors);
        }
Beispiel #7
0
        public void UpdatesAndNotifiesError()
        {
            var textBox    = new TextBox();
            var inputTypes = new InputTypeCollection {
                typeof(TextBox), typeof(Selector)
            };

            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);
            var errorArgs = errorNode.Errors.SubscribeAllEvents();
            var nodeArgs  = errorNode.SubscribeAllEvents();

            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            CollectionAssert.IsEmpty(errorNode.Errors);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            CollectionAssert.AreEqual(new[] { TestValidationError.GetFor(textBox) }, errorNode.Errors);

            var expectedErrorArgs = new List <EventArgs>
            {
                new PropertyChangedEventArgs("Count"),
                new PropertyChangedEventArgs("Item[]"),
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, TestValidationError.GetFor(textBox), 0)
            };

            CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);
            var expectedNodeArgs = new List <EventArgs>
            {
                new PropertyChangedEventArgs("Count"),
                new PropertyChangedEventArgs("Item[]"),
                new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, TestValidationError.GetFor(textBox), 0),
                new PropertyChangedEventArgs("HasErrors"),
            };

            CollectionAssert.AreEqual(expectedNodeArgs, nodeArgs, ObservableCollectionArgsComparer.Default);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
            CollectionAssert.IsEmpty(errorNode.Errors);

            expectedErrorArgs.Add(new PropertyChangedEventArgs("Count"));
            expectedErrorArgs.Add(new PropertyChangedEventArgs("Item[]"));
            expectedErrorArgs.Add(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, TestValidationError.GetFor(textBox), 0));
            CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);

            expectedNodeArgs.Add(new PropertyChangedEventArgs("Count"));
            expectedNodeArgs.Add(new PropertyChangedEventArgs("Item[]"));
            expectedNodeArgs.Add(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, TestValidationError.GetFor(textBox), 0));
            expectedNodeArgs.Add(new PropertyChangedEventArgs("HasErrors"));
            CollectionAssert.AreEqual(expectedNodeArgs, nodeArgs, ObservableCollectionArgsComparer.Default);
        }
            public void TextBoxSetSetForInputTypesTextBox()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                CollectionAssert.IsEmpty(Scope.GetErrors(textBox));

                var errorNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                Assert.AreEqual(false, errorNode.HasError);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                var expectedErrors = new[] { validationError };
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));

                Assert.AreEqual(true, errorNode.HasError);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);
            }
        public void UpdatesError()
        {
            var textBox    = new TextBox();
            var inputTypes = new InputTypeCollection {
                typeof(TextBox), typeof(Selector)
            };

            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            var errorNode = (ErrorNode)Scope.GetErrors(textBox);

            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);

            textBox.SetValidationError();
            Assert.AreEqual(true, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);

            textBox.ClearValidationError();
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            errorNode = (ErrorNode)Scope.GetErrors(textBox);
            Assert.AreEqual(textBox, errorNode.Source);
            CollectionAssert.IsEmpty(errorNode.Children);
        }
        private void ListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var selectedItems = ((ListBox)sender).SelectedItems.Cast <Type>();
            var types         = new InputTypeCollection();

            types.AddRange(selectedItems);
            Scope.SetForInputTypes(this.Form, types);
        }
 public void TextBoxSetSetForInputTypes()
 {
     var textBox = new TextBox();
     var inputTypes = new InputTypeCollection { typeof(Selector), typeof(Slider) };
     textBox.SetForInputTypes(inputTypes);
     Assert.AreEqual(false, Scope.GetHasErrors(textBox));
     Assert.AreEqual(null, Scope.GetErrors(textBox));
 }
            public static void NodesForInputTypesTextBox()
            {
                var textBox    = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(System.Windows.Controls.TextBox), typeof(Selector)
                };

                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                var errorNode = (InputNode)Scope.GetNode(textBox);

                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);

                textBox.SetValidationError(validationError);

                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                var expectedErrors = new[] { validationError };

                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(stackPanel));
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));

                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);

                CollectionAssert.AreEqual(new[] { errorNode }, scopeNode.Children);
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(true, scopeNode.HasError);
                Assert.AreEqual(true, errorNode.HasError);
                CollectionAssert.AreEqual(expectedErrors, scopeNode.Errors);
                CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
 public void TextBoxSetSetForInputTypesTextBox()
 {
     var textBox = new TextBox();
     var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
     textBox.SetForInputTypes(inputTypes);
     Assert.AreEqual(false, Scope.GetHasErrors(textBox));
     var errorNode = (ErrorNode)Scope.GetErrors(textBox);
     Assert.AreEqual(textBox, errorNode.Source);
     CollectionAssert.IsEmpty(errorNode.Children);
 }
        public void TextBoxSetSetForInputTypes()
        {
            var textBox    = new TextBox();
            var inputTypes = new InputTypeCollection {
                typeof(Selector), typeof(Slider)
            };

            textBox.SetForInputTypes(inputTypes);
            Assert.AreEqual(false, Scope.GetHasErrors(textBox));
            Assert.AreEqual(null, Scope.GetErrors(textBox));
        }
 public void TextBoxSetSetForInputTypes()
 {
     var textBox = new TextBox();
     var stackPanel = new StackPanel();
     stackPanel.Children.Add(textBox);
     var inputTypes = new InputTypeCollection { typeof(Selector), typeof(Slider) };
     stackPanel.SetForInputTypes(inputTypes);
     Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
     Assert.AreEqual(null, Scope.GetErrors(stackPanel));
     Assert.AreEqual(false, Scope.GetHasErrors(textBox));
     Assert.AreEqual(null, Scope.GetErrors(textBox));
 }
Beispiel #16
0
            public void UpdatesAndNotifiesError()
            {
                var textBox    = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection {
                    typeof(System.Windows.Controls.TextBox), typeof(Selector)
                };

                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var errorNode = (InputNode)Scope.GetNode(textBox);

                using (var errorArgs = errorNode.Errors.SubscribeObservableCollectionEvents())
                {
                    using (var nodeArgs = errorNode.SubscribePropertyChangedEvents())
                    {
                        Assert.AreEqual(textBox, errorNode.Source);
                        CollectionAssert.IsEmpty(errorNode.Children);
                        CollectionAssert.IsEmpty(errorNode.Errors);
                        var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                        textBox.SetValidationError(validationError);
                        Assert.AreEqual(true, Scope.GetHasError(textBox));
                        errorNode = (InputNode)Scope.GetNode(textBox);
                        Assert.AreEqual(textBox, errorNode.Source);
                        CollectionAssert.IsEmpty(errorNode.Children);
                        CollectionAssert.AreEqual(new[] { validationError }, errorNode.Errors);

                        var expectedErrorArgs = new List <EventArgs>
                        {
                            new PropertyChangedEventArgs("Count"),
                            new PropertyChangedEventArgs("Item[]"),
                            new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, validationError, 0)
                        };
                        CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);
                        CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);

                        textBox.ClearValidationError(validationError);
                        Assert.AreEqual(false, Scope.GetHasError(textBox));
                        Assert.AreSame(errorNode, Scope.GetNode(textBox));
                        Assert.AreEqual(textBox, errorNode.Source);
                        CollectionAssert.IsEmpty(errorNode.Children);
                        CollectionAssert.IsEmpty(errorNode.Errors);

                        expectedErrorArgs.Add(new PropertyChangedEventArgs("Count"));
                        expectedErrorArgs.Add(new PropertyChangedEventArgs("Item[]"));
                        expectedErrorArgs.Add(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, validationError, 0));
                        CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);

                        CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)), new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);
                    }
                }
            }
        private static InputTypeCollection ConvertFromText(string text)
        {
            var typeNames = text.Split(SeparatorChars, StringSplitOptions.RemoveEmptyEntries)
                .Select(x => x.Trim())
                .ToArray();
            var inputTypeCollection = new InputTypeCollection();
            foreach (var typeName in typeNames)
            {
                var match = CompatibleTypeCache.FindType(typeName);
                inputTypeCollection.Add(match);
            }

            return inputTypeCollection;
        }
            public void TextBoxSetSetForSelectorAndSlider()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection { typeof(Selector), typeof(Slider) };
                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(textBox));
            }
            public void NodesForInputTypesTextBox()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                var errorNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);

                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                var expectedErrors = new[] { validationError };
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(stackPanel));
                CollectionAssert.AreEqual(expectedErrors, Scope.GetErrors(textBox));

                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);
                CollectionAssert.AreEqual(new[] { errorNode }, scopeNode.Children);
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(true, scopeNode.HasError);
                Assert.AreEqual(true, errorNode.HasError);
                CollectionAssert.AreEqual(expectedErrors, scopeNode.Errors);
                CollectionAssert.AreEqual(expectedErrors, errorNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(stackPanel));
                Assert.AreSame(ErrorCollection.EmptyValidationErrors, Scope.GetErrors(textBox));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(false, errorNode.HasError);
                Assert.AreNotSame(ErrorCollection.EmptyValidationErrors, errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Errors);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
            public static void UpdatesErrors()
            {
                var textBox    = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(System.Windows.Controls.TextBox), typeof(Selector)
                };

                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var inputNode = (InputNode)Scope.GetNode(textBox);

                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);

                textBox.SetValidationError(validationError);
                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);

                Assert.AreEqual(stackPanel, scopeNode.Source);
                Assert.AreEqual(1, scopeNode.Children.Count);
                CollectionAssert.AreEqual(new[] { validationError }, scopeNode.Errors);

                Assert.AreEqual(true, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.AreEqual(new[] { validationError }, inputNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);
            }
Beispiel #21
0
            public void TextBoxSetSetForInputTypes()
            {
                var textBox    = new TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(Selector), typeof(Slider)
                };

                stackPanel.SetForInputTypes(inputTypes);
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                Assert.AreEqual(null, Scope.GetErrors(stackPanel));
                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                Assert.AreEqual(null, Scope.GetErrors(textBox));
            }
            public void TextBoxSetSetForInputTypesTextBox()
            {
                var textBox = new TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
                stackPanel.SetForInputTypes(inputTypes);
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                IErrorNode errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
Beispiel #23
0
            public void Errors()
            {
                var textBox    = new TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(TextBox), typeof(Selector)
                };

                stackPanel.SetForInputTypes(inputTypes);

                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                IErrorNode errorNode = (ScopeNode)Scope.GetErrors(stackPanel);

                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                textBox.SetValidationError();
                Assert.AreEqual(true, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(stackPanel, errorNode.Source);
                Assert.AreEqual(1, errorNode.Children.Count);
                CollectionAssert.AreEqual(new[] { TestValidationError.GetFor(textBox) }, errorNode.Errors);

                Assert.AreEqual(true, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(new[] { TestValidationError.GetFor(textBox) }, errorNode.Errors);

                textBox.ClearValidationError();
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);
            }
            public void UpdatesAndNotifiesError()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(textBox, inputTypes);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var errorNode = (InputNode)Scope.GetNode(textBox);
                var errorArgs = errorNode.Errors.SubscribeObservableCollectionEvents();
                var nodeArgs = errorNode.SubscribePropertyChangedEvents();
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);
                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                Assert.AreEqual(true, Scope.GetHasError(textBox));
                errorNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(new[] { validationError }, errorNode.Errors);

                var expectedErrorArgs = new List<EventArgs>
                                   {
                                       new PropertyChangedEventArgs("Count"),
                                       new PropertyChangedEventArgs("Item[]"),
                                       new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, validationError, 0)
                                   };
                CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);
                CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(errorNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                expectedErrorArgs.Add(new PropertyChangedEventArgs("Count"));
                expectedErrorArgs.Add(new PropertyChangedEventArgs("Item[]"));
                expectedErrorArgs.Add(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, validationError, 0));
                CollectionAssert.AreEqual(expectedErrorArgs, errorArgs, ObservableCollectionArgsComparer.Default);

                CollectionAssert.AreEqual(new[] { new PropertyChangedEventArgs(nameof(Node.HasError)), new PropertyChangedEventArgs(nameof(Node.HasError)) }, nodeArgs, PropertyChangedEventArgsComparer.Default);
            }
Beispiel #25
0
            public void TextBoxSetSetForInputTypesTextBox()
            {
                var textBox    = new TextBox();
                var stackPanel = new StackPanel();

                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection {
                    typeof(TextBox), typeof(Selector)
                };

                stackPanel.SetForInputTypes(inputTypes);
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                IErrorNode errorNode = (ScopeNode)Scope.GetErrors(stackPanel);

                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
            }
#pragma warning restore SA1202 // Elements must be ordered by access

        public static void SetForInputTypes(this UIElement element, InputTypeCollection value)
        {
            element.SetValue(ForInputTypesProperty, value);
        }
            public void UpdatesErrors()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(stackPanel, inputTypes);

                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                var inputNode = (InputNode)Scope.GetNode(textBox);
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);

                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                Assert.AreEqual(true, Scope.GetHasError(stackPanel));
                var scopeNode = (ScopeNode)Scope.GetNode(stackPanel);
                Assert.AreEqual(stackPanel, scopeNode.Source);
                Assert.AreEqual(1, scopeNode.Children.Count);
                CollectionAssert.AreEqual(new[] { validationError }, scopeNode.Errors);

                Assert.AreEqual(true, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.AreEqual(new[] { validationError }, inputNode.Errors);

                textBox.ClearValidationError(validationError);
                Assert.AreEqual(false, Scope.GetHasError(stackPanel));
                Assert.AreEqual(ValidNode.Default, Scope.GetNode(stackPanel));

                Assert.AreEqual(false, Scope.GetHasError(textBox));
                Assert.AreSame(inputNode, Scope.GetNode(textBox));
                Assert.AreEqual(textBox, inputNode.Source);
                CollectionAssert.IsEmpty(inputNode.Children);
                CollectionAssert.IsEmpty(inputNode.Errors);
            }
            public void Notifies()
            {
                var textBox = new System.Windows.Controls.TextBox();
                var textBoxEvents = textBox.SubscribeScopeEvents();
                var stackPanel = new StackPanel();
                var stackPanelEVents = stackPanel.SubscribeScopeEvents();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(System.Windows.Controls.TextBox), typeof(Selector) };
                Scope.SetForInputTypes(stackPanel, inputTypes);
                var validationError = TestValidationError.GetFor(textBox, System.Windows.Controls.TextBox.TextProperty);
                textBox.SetValidationError(validationError);
                var expectedEvents = new List<ScopeValidationErrorEventArgs>
                                         {
                                             new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Added)
                                         };
                CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);
                CollectionAssert.AreEqual(expectedEvents, stackPanelEVents, ScopeValidationErrorEventArgsComparer.Default);

                textBox.ClearValidationError(validationError);
                expectedEvents.Add(new ScopeValidationErrorEventArgs(validationError, ValidationErrorEventAction.Removed));
                CollectionAssert.AreEqual(expectedEvents, textBoxEvents, ScopeValidationErrorEventArgsComparer.Default);
                CollectionAssert.AreEqual(expectedEvents, stackPanelEVents, ScopeValidationErrorEventArgsComparer.Default);
            }
            public void Errors()
            {
                var textBox = new TextBox();
                var stackPanel = new StackPanel();
                stackPanel.Children.Add(textBox);
                var inputTypes = new InputTypeCollection { typeof(TextBox), typeof(Selector) };
                stackPanel.SetForInputTypes(inputTypes);

                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                IErrorNode errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);

                textBox.SetValidationError();
                Assert.AreEqual(true, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(stackPanel, errorNode.Source);
                Assert.AreEqual(1, errorNode.Children.Count);
                CollectionAssert.AreEqual(new[] { TestValidationError.GetFor(textBox) }, errorNode.Errors);

                Assert.AreEqual(true, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.AreEqual(new[] { TestValidationError.GetFor(textBox) }, errorNode.Errors);

                textBox.ClearValidationError();
                Assert.AreEqual(false, Scope.GetHasErrors(stackPanel));
                errorNode = (ScopeNode)Scope.GetErrors(stackPanel);
                Assert.AreEqual(null, errorNode);

                Assert.AreEqual(false, Scope.GetHasErrors(textBox));
                errorNode = (ErrorNode)Scope.GetErrors(textBox);
                Assert.AreEqual(textBox, errorNode.Source);
                CollectionAssert.IsEmpty(errorNode.Children);
                CollectionAssert.IsEmpty(errorNode.Errors);
            }
 public static void SetForInputTypes(FrameworkElement element, InputTypeCollection value) => element.SetValue(ForInputTypesProperty, value);