public void MoveCurrencyWithDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();

            dataFormApp.dataForm.ItemsSource = this.dataClassList;
            ContentPresenter contentPresenter = null;

            dataFormApp.dataForm.CurrentItem = this.dataClassList[2];
            this.DataFormAppBase             = dataFormApp;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                TextBox textBox  = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[2], textBox.DataContext);

                Assert.IsTrue(dataFormApp.dataForm.CanMoveToFirstItem);
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.MoveToFirstItem();
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[0], textBox.DataContext);
                Assert.AreEqual(this.dataClassList[0], dataFormApp.dataForm.CurrentItem);

                Assert.IsFalse(dataFormApp.dataForm.CanMoveToFirstItem);
                Assert.IsTrue(dataFormApp.dataForm.CanMoveToNextItem);
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.MoveToNextItem();
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[1], textBox.DataContext);
                Assert.AreEqual(this.dataClassList[1], dataFormApp.dataForm.CurrentItem);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureUIUpdatedAfterEditDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();

            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.ExpectBeginEdit();
                InvokeButton(editButton);
            });

            this.WaitForBeginEdit();

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

                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.Edit, dataFormApp.dataForm.Mode);
                textBox.Text = "new string";

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

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                Assert.AreEqual("new string", textBox.Text);
            });

            this.EnqueueTestComplete();
        }
        public void ReplaceDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();

            dataFormApp.dataForm.CurrentItem = new DataClass();
            this.DataFormAppBase             = dataFormApp;
            ContentPresenter contentPresenter = null;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                TextBox textBox  = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);

                this.ExpectContentLoaded();

                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty, new Binding("Age")
                {
                    Mode = BindingMode.TwoWay
                });
                DataField dataField = new DataField()
                {
                    Label = "Age", PropertyPath = "Age", Content = textBox
                };
                StackPanel stackPanel = new StackPanel();
                stackPanel.Children.Add(dataField);
                dataFormApp.dataForm.Content = stackPanel;
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                contentPresenter      = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                StackPanel stackPanel = contentPresenter.Content as StackPanel;
                Assert.IsNotNull(stackPanel);
                Assert.AreEqual(dataFormApp.dataForm.Content, stackPanel);
            });

            this.EnqueueTestComplete();
        }
        public void ReplaceDirectContentWithEditTemplate()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();

            dataFormApp.dataForm.CurrentItem = new DataClass();
            this.DataFormAppBase             = dataFormApp;
            ContentPresenter contentPresenter = null;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                TextBox textBox  = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);

                this.ExpectContentLoaded();

                dataFormApp.dataForm.EditTemplate = ((DataFormApp_DirectContent)dataFormApp).editTemplate;
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                contentPresenter = this.GetTemplatePart <ContentPresenter>("ContentPresenter");
                TextBox textBox  = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual("Edit Template", textBox.Text);
                Assert.AreNotEqual(dataFormApp.dataForm.Content, textBox);
            });

            this.EnqueueTestComplete();
        }
        public void TestPropertyLevelValidationWithTextChangedInDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();
            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.ExpectBeginEdit();
                dataFormApp.dataForm.BeginEdit();
            });

            this.WaitForBeginEdit();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(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(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.Edit, dataFormApp.dataForm.Mode);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

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

            this.WaitForTextChanged();

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

                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual("test string 2", textBox.Text);

                this.ExpectEditEnded();
                dataFormApp.dataForm.CancelEdit();
            });

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                Assert.AreEqual("test string 1", textBox.Text);
            });

            this.EnqueueTestComplete();
        }
        public void MoveCurrencyWithDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();
            dataFormApp.dataForm.ItemsSource = this.dataClassList;
            ContentPresenter contentPresenter = null;
            dataFormApp.dataForm.CurrentItem = this.dataClassList[2];
            this.DataFormAppBase = dataFormApp;

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[2], textBox.DataContext);

                Assert.IsTrue(dataFormApp.dataForm.CanMoveToFirstItem);
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.MoveToFirstItem();
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[0], textBox.DataContext);
                Assert.AreEqual(this.dataClassList[0], dataFormApp.dataForm.CurrentItem);

                Assert.IsFalse(dataFormApp.dataForm.CanMoveToFirstItem);
                Assert.IsTrue(dataFormApp.dataForm.CanMoveToNextItem);
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.MoveToNextItem();
            });
            
            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(this.dataClassList[1], textBox.DataContext);
                Assert.AreEqual(this.dataClassList[1], dataFormApp.dataForm.CurrentItem);
            });

            this.EnqueueTestComplete();
        }
        public void ReplaceDirectContentWithEditTemplate()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();
            dataFormApp.dataForm.CurrentItem = new DataClass();
            this.DataFormAppBase = dataFormApp;
            ContentPresenter contentPresenter = null;
            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);

                this.ExpectContentLoaded();

                dataFormApp.dataForm.EditTemplate = ((DataFormApp_DirectContent)dataFormApp).editTemplate;
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual("Edit Template", textBox.Text);
                Assert.AreNotEqual(dataFormApp.dataForm.Content, textBox);
            });

            this.EnqueueTestComplete();
        }
        public void ReplaceDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();
            dataFormApp.dataForm.CurrentItem = new DataClass();
            this.DataFormAppBase = dataFormApp;
            ContentPresenter contentPresenter = null;
            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);

                this.ExpectContentLoaded();

                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty, new Binding("Age") { Mode = BindingMode.TwoWay });
                DataField dataField = new DataField() { Label = "Age", PropertyPath = "Age", Content = textBox };
                StackPanel stackPanel = new StackPanel();
                stackPanel.Children.Add(dataField);
                dataFormApp.dataForm.Content = stackPanel;
            });

            this.WaitForContentLoaded();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                contentPresenter = this.GetTemplatePart<ContentPresenter>("ContentPresenter");
                StackPanel stackPanel = contentPresenter.Content as StackPanel;
                Assert.IsNotNull(stackPanel);
                Assert.AreEqual(dataFormApp.dataForm.Content, stackPanel);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureUIUpdatedAfterEditDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();
            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.ExpectBeginEdit();
                InvokeButton(editButton);
            });

            this.WaitForBeginEdit();

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

                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.Edit, dataFormApp.dataForm.Mode);
                textBox.Text = "new string";

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

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                TextBox textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                Assert.AreEqual("new string", textBox.Text);
            });

            this.EnqueueTestComplete();
        }
        public void TestPropertyLevelValidationWithTextChangedInDirectContent()
        {
            DataFormApp_DirectContent dataFormApp = new DataFormApp_DirectContent();

            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.ExpectBeginEdit();
                dataFormApp.dataForm.BeginEdit();
            });

            this.WaitForBeginEdit();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(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(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.Edit, dataFormApp.dataForm.Mode);
                Assert.AreEqual("StringProperty is required.", validationSummary.Errors[0].Message);

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

            this.WaitForTextChanged();

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

                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual("test string 2", textBox.Text);

                this.ExpectEditEnded();
                dataFormApp.dataForm.CancelEdit();
            });

            this.WaitForEditEnded();

            this.EnqueueCallback(() =>
            {
                this.textBox = contentPresenter.Content as TextBox;
                Assert.IsNotNull(textBox);
                Assert.AreEqual(dataFormApp.dataForm.Content, textBox);
                Assert.AreEqual(DataFormMode.ReadOnly, dataFormApp.dataForm.Mode);
                Assert.AreEqual("test string 1", textBox.Text);
            });

            this.EnqueueTestComplete();
        }