public void EnsureUIUpdatedAfterEdit()
        {
            DataFormApp_TemplatesWithBinding dataFormApp = new DataFormApp_TemplatesWithBinding();

            this.DataFormAppBase             = dataFormApp;
            dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(1, ListOperations.All);
            ContentPresenter contentPresenter = null;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter      = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                ButtonBase editButton = this.GetTemplatePart <ButtonBase>("EditButton");

                this.ExpectContentLoaded();
                InvokeButton(editButton);
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                ButtonBase commitButton = this.GetTemplatePart <ButtonBase>("CommitButton");

                TextBox textBox = contentPresenter.Content as TextBox;
                textBox.Text    = "new string";

                this.ExpectEditEnded();
                InvokeButton(commitButton);
            });

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.AreEqual("new string", textBox.Text);
            });

            this.EnqueueTestComplete();
        }
        public void TestPropertyLevelValidationWithTextChangedInTemplate()
        {
            DataFormApp_TemplatesWithBinding dataFormApp = new DataFormApp_TemplatesWithBinding();
            dataFormApp.dataForm.CurrentItem = new DataClassWithValidation()
            {
                IntProperty = 1,
                StringProperty = "test string 1"
            };

            this.DataFormAppBase = dataFormApp;
            ContentPresenter contentPresenter = null;
            ValidationSummary validationSummary = null;
            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                validationSummary = this.GetTemplatePart<ValidationSummary>("ValidationSummary");
                this.ExpectContentLoaded();
                dataFormApp.dataForm.BeginEdit();
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;

                SetValue(this.textBox, string.Empty);
                this.CommitAllFields();

                Assert.IsFalse(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(1, validationSummary.Errors.Count);
                Assert.AreEqual(this.textBox, validationSummary.Errors[0].Sources[0].Control);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, "test string 1");
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(0, validationSummary.Errors.Count);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, string.Empty);
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsFalse(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(1, validationSummary.Errors.Count);
                Assert.AreEqual(this.textBox, validationSummary.Errors[0].Sources[0].Control);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, "test string 1");
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(0, validationSummary.Errors.Count);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, string.Empty);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureUIUpdatedAfterEdit()
        {
            DataFormApp_TemplatesWithBinding dataFormApp = new DataFormApp_TemplatesWithBinding();
            this.DataFormAppBase = dataFormApp;
            dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(1, ListOperations.All);
            ContentPresenter contentPresenter = null;
            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                ButtonBase editButton = this.GetTemplatePart<ButtonBase>("EditButton");

                this.ExpectContentLoaded();
                InvokeButton(editButton);
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                ButtonBase commitButton = this.GetTemplatePart<ButtonBase>("CommitButton");

                TextBox textBox = contentPresenter.Content as TextBox;
                textBox.Text = "new string";

                this.ExpectEditEnded();
                InvokeButton(commitButton);
            });

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.AreEqual("new string", textBox.Text);
            });

            this.EnqueueTestComplete();
        }
        public void TestPropertyLevelValidationWithTextChangedInTemplate()
        {
            DataFormApp_TemplatesWithBinding dataFormApp = new DataFormApp_TemplatesWithBinding();

            dataFormApp.dataForm.CurrentItem = new DataClassWithValidation()
            {
                IntProperty    = 1,
                StringProperty = "test string 1"
            };

            this.DataFormAppBase = dataFormApp;
            ContentPresenter  contentPresenter  = null;
            ValidationSummary validationSummary = null;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter  = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                validationSummary = this.GetTemplatePart <ValidationSummary>("ValidationSummary");
                this.ExpectContentLoaded();
                dataFormApp.dataForm.BeginEdit();
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;

                SetValue(this.textBox, string.Empty);
                this.CommitAllFields();

                Assert.IsFalse(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(1, validationSummary.Errors.Count);
                Assert.AreEqual(this.textBox, validationSummary.Errors[0].Sources[0].Control);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, "test string 1");
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(0, validationSummary.Errors.Count);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, string.Empty);
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsFalse(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(1, validationSummary.Errors.Count);
                Assert.AreEqual(this.textBox, validationSummary.Errors[0].Sources[0].Control);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, "test string 1");
            });

            this.WaitForTextChanged();

            this.EnqueueCallback(() =>
            {
                Assert.IsTrue(dataFormApp.dataForm.IsItemValid);
                Assert.AreEqual(0, validationSummary.Errors.Count);

                this.ExpectTextChangedOnTextBox();
                SetValue(this.textBox, string.Empty);
            });

            this.EnqueueTestComplete();
        }