public void IsRequired()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(page.nameLabel.IsRequired);
                Assert.IsFalse(page.emailLabel.IsRequired);

                // name should now be overriden
                page.nameLabel.IsRequired = false;
                Assert.IsFalse(page.nameLabel.IsRequired);

                // This causes metadata to be reloaded, but it won't overwrite IsFieldRequired
                page.nameLabel.PropertyPath = "Name";
                Assert.IsFalse(page.nameLabel.IsRequired);

                // Refresh everything
                page.nameLabel.Refresh();
                Assert.IsTrue(page.nameLabel.IsRequired);
            });
            EnqueueTestComplete();
        }
        public void Target_ValidChecksWithTargetChanges()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                Assert.IsTrue(page.nameLabel.IsValid, "initial valid state");
                page.nameTextBox.Text = "ABCDEF!@#1";
                Assert.IsFalse(page.nameLabel.IsValid, "invalid data");
                page.nameLabel.Target = page.emailTextBox;
                Assert.IsTrue(page.nameLabel.IsValid, "switch to valid target");
                page.nameLabel.Target = page.nameTextBox;
                Assert.IsFalse(page.nameLabel.IsValid, "switch back to invalid target");
                page.nameTextBox.Text = "ABC";
                Assert.IsTrue(page.nameLabel.IsValid, "turned valid again");
                page.emailTextBox.Text = "asdfkhask";
                page.nameLabel.Target  = page.emailTextBox;
                Assert.IsFalse(page.nameLabel.IsValid, "switch to second, invalid target");
                page.nameLabel.Target = null;
                Assert.IsTrue(page.nameLabel.IsValid, "no target");
            });
            EnqueueTestComplete();
        }
        public void Content_Override()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.Content = "example";
                Assert.AreEqual("example", page.nameLabel.Content);
                page.nameLabel.Target = page.emailTextBox;
                Assert.AreEqual("example", page.nameLabel.Content);
                page.nameLabel.Content = null;
                Assert.IsNull(page.nameLabel.Content);

                page.nameLabel.Refresh();
                Assert.AreEqual("Alternate Email", page.nameLabel.Content);
                page.nameLabel.Target = page.nameTextBox;
                Assert.AreEqual("Name", page.nameLabel.Content);

                page.nameLabel.Content = null;
                Assert.IsNull(page.nameLabel.Content);

                //When Content is set to null, Refresh() consumes the metadata again.
                page.nameLabel.Refresh();
                Assert.AreEqual("Name", page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
        public void Target_Null()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.Target = null;
                Assert.IsNull(page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
        public void Target()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.Target = page.emailTextBox;
                Assert.AreEqual("Alternate Email", page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
        public void IsValidReadOnly()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.IsNotNull(page.nameLabel);
                Assert.IsTrue(page.nameLabel.IsValid);
                string ExpectedExceptionMessage = String.Format(System.Windows.Controls.Data.Input.Resources.UnderlyingPropertyIsReadOnly, "IsValid");
                ExceptionHelper.ExpectInvalidOperationException(delegate() { page.nameLabel.SetValue(Label.IsValidProperty, false); }, ExpectedExceptionMessage);
            });
            EnqueueTestComplete();
        }
        public void IsEnabled()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameLabel.IsEnabled = true;
                Assert.IsTrue(page.nameLabel.IsEnabled);
                page.nameLabel.IsEnabled = false;
                Assert.IsFalse(page.nameLabel.IsEnabled);
            });
            EnqueueTestComplete();
        }
        public void PropertyPath_NoDataContext()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameLabel.DataContext = null;
                Assert.IsNull(page.nameLabel.DataContext);
                page.nameLabel.PropertyPath = "blah";
                page.nameLabel.DataContext  = page.DataContext;
            });
            EnqueueTestComplete();
        }
        public void Content()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.Content = "example";
                Assert.AreEqual("example", page.nameLabel.Content);
                page.nameLabel.Refresh();
                Assert.AreEqual("Name", page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
示例#10
0
        public void Refresh()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                page.nameLabel.IsRequired = false;
                Assert.AreEqual("Name", page.nameLabel.Content);
                Assert.IsFalse(page.nameLabel.IsRequired);
                page.nameLabel.Refresh();
                Assert.AreEqual("Name", page.nameLabel.Content);
                Assert.IsTrue(page.nameLabel.IsRequired);
            });
            EnqueueTestComplete();
        }
示例#11
0
        public void PropertyPath_ChangingDataContextWithTarget()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.PropertyPath = "BirthDate";
                Assert.AreEqual("Birth date", page.nameLabel.Content);
                page.nameLabel.DataContext = new Order();
                Assert.IsFalse(page.nameLabel.IsRequired);
                Assert.IsNull(page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
示例#12
0
        public void Target_ValidChecks()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                Assert.IsTrue(page.nameLabel.IsValid);
                page.nameTextBox.Text = "ABCDEF!@#1";
                Assert.IsFalse(page.nameLabel.IsValid);
                page.nameTextBox.Text = "ABC";
                Assert.IsTrue(page.nameLabel.IsValid);
            });
            EnqueueTestComplete();
        }
示例#13
0
        public void ContentTemplate()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                page.nameLabel.Content = "example";
                Assert.IsNull(page.nameLabel.ContentTemplate);
                DataTemplate testContentTemplate = page.Resources["testContentTemplate"] as DataTemplate;
                page.nameLabel.ContentTemplate   = testContentTemplate;
                Assert.AreEqual(testContentTemplate, page.nameLabel.ContentTemplate);
            });
            EnqueueTestComplete();
        }
示例#14
0
        public void Target_NonVisualTreeElement()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                TextBox tb = new TextBox();
                Binding b  = new Binding("Email");
                tb.SetBinding(TextBox.TextProperty, b);
                tb.DataContext        = page.DataContext;
                page.nameLabel.Target = tb;
                Assert.AreEqual("Email", page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
示例#15
0
        public void Target_Unbound()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);

            this.EnqueueConditional(() => { return(page.nameLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Name", page.nameLabel.Content);
                Assert.IsTrue(page.nameLabel.IsValid, "initial valid state");
                page.nameTextBox.Text = "ABCDEF!@#1";
                Assert.IsFalse(page.nameLabel.IsValid, "invalid data");

                page.nameLabel.Target = new TextBox();
                Assert.IsTrue(page.nameLabel.IsValid, "no target");
                Assert.IsNull(page.nameLabel.Content);
            });
            EnqueueTestComplete();
        }
示例#16
0
        public void PropertyPath_UpdateValidStateWhenChanged()
        {
            LabelTestPage page = new LabelTestPage();

            this.TestPanel.Children.Add(page);
            Binding b = new Binding();

            b.Path = new PropertyPath("Email");
            b.ValidatesOnExceptions   = true;
            b.NotifyOnValidationError = true;
            b.Mode = BindingMode.TwoWay;
            page.emailTextBox.SetBinding(TextBox.TextProperty, b);
            Label fl = page.emailLabel;

            this.EnqueueConditional(() => { return(page.emailLabel.Initialized); });
            this.EnqueueCallback(() =>
            {
                Assert.AreEqual("Email", fl.Content);
                Assert.IsTrue(fl.IsValid);
                Assert.IsTrue(fl.IsRequired);
                Assert.AreEqual("Email", fl.Content);
                page.emailTextBox.Text = "asdfasdl;kj#@$";
                page.emailTextBox.GetBindingExpression(TextBox.TextProperty).UpdateSource();
                Assert.IsFalse(fl.IsValid);

                // Set PropertyPath
                fl.PropertyPath = "BirthDate"; // Not required
                Assert.IsFalse(fl.IsValid, "IsValid state should be unchanged because target is still set.");
                Assert.IsFalse(fl.IsRequired);
                Assert.AreEqual("Birth date", fl.Content);
                Assert.AreEqual(page.emailTextBox, fl.Target);

                fl.PropertyPath = null;
                Assert.IsTrue(fl.IsRequired);
                Assert.AreEqual("Email", fl.Content);
                Assert.AreEqual(page.emailTextBox, fl.Target);
                Assert.IsFalse(fl.IsValid);
            });
            EnqueueTestComplete();
        }