public void CallOnApplyTemplateMultipleTimes()
        {
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();
            dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(3, ListOperations.All);

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                dataFormApp.dataForm.OnApplyTemplate();
                dataFormApp.dataForm.OnApplyTemplate();

                // The only buttons that would have any additional effect if there were multiple event handlers
                // would be next and previous, since the others make it so you can't do the same action again
                // once you do it the first time.
                ButtonBase nextItemButton = this.GetTemplatePart<ButtonBase>("NextItemButton");
                this.ExpectCurrentItemChange();
                InvokeButton(nextItemButton);
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(1, dataFormApp.dataForm.CurrentIndex);
                dataFormApp.dataForm.CurrentIndex = 2;

                ButtonBase previousItemButton = this.GetTemplatePart<ButtonBase>("PreviousItemButton");
                this.ExpectCurrentItemChange();
                InvokeButton(previousItemButton);
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(1, dataFormApp.dataForm.CurrentIndex);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureCurrentIndexSyncedAfterCollectionViewMovesToAfterLast()
        {
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();
            PagedCollectionView pcv = new PagedCollectionView(DataClassList.GetDataClassList(2, ListOperations.All));
            dataFormApp.dataForm.ItemsSource = pcv;

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(0, pcv.CurrentPosition);
                Assert.AreEqual(pcv[0], dataFormApp.dataForm.CurrentItem);
                this.ExpectCurrentItemChange();
                pcv.MoveCurrentToPosition(2);
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(2, pcv.CurrentPosition);
                Assert.AreEqual(2, dataFormApp.dataForm.CurrentIndex);
                Assert.IsNull(dataFormApp.dataForm.CurrentItem);
                this.ExpectCurrentItemChange();
                pcv.MoveCurrentToPosition(0);
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.CurrentIndex = 2;
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(2, pcv.CurrentPosition);
                Assert.AreEqual(2, dataFormApp.dataForm.CurrentIndex);
                Assert.IsNull(dataFormApp.dataForm.CurrentItem);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureCollectionViewAtBeforeFirstIsMovedToFirst()
        {
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();
            PagedCollectionView cv = new PagedCollectionView(DataClassList.GetDataClassList(2, ListOperations.All));
            cv.MoveCurrentToPosition(-1);
            dataFormApp.dataForm.ItemsSource = cv;

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                Assert.AreEqual(0, cv.CurrentPosition);
            });

            this.EnqueueTestComplete();
        }
        public void SetHeader()
        {
            ContentControl headerElement = null;
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                headerElement = this.GetTemplatePart<ContentControl>("HeaderElement");

                dataFormApp.dataForm.Header = "header";
                Assert.AreEqual("header", headerElement.Content);

                dataFormApp.dataForm.Header = "DataForm 1";
                Assert.AreEqual("DataForm 1", headerElement.Content);

                dataFormApp.dataForm.Header = string.Empty;
                Assert.AreEqual(string.Empty, headerElement.Content);

                dataFormApp.dataForm.Header = null;
                Assert.IsNull(headerElement.Content);

                dataFormApp.dataForm.HeaderTemplate = new HeaderTemplate();
                Assert.IsNotNull(headerElement.ContentTemplate);
                TextBlock textBlock = headerElement.ContentTemplate.LoadContent() as TextBlock;
                Assert.IsNotNull(textBlock);
                Assert.AreEqual("DataForm", textBlock.Text);
            });

            this.EnqueueTestComplete();
        }
        public void SetCurrentItemToNullWithSet()
        {
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
                dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(3, ListOperations.All);
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                dataFormApp.dataForm.CurrentItem = null;
                Assert.IsNull(dataFormApp.dataForm.CurrentItem);
            });

            this.EnqueueTestComplete();
        }
        public void EnsureUpdateButtonsWhenDisabledDoesNotDisableButtons()
        {
            DataFormApp_Standard dataFormApp = new DataFormApp_Standard();
            dataFormApp.dataForm.ItemsSource = DataClassList.GetDataClassList(4, ListOperations.All);
            dataFormApp.dataForm.CurrentIndex = 1;

            this.EnqueueCallback(() =>
            {
                this.DataFormAppBase = dataFormApp;
            });

            this.AddToPanelAndWaitForLoad();

            this.EnqueueCallback(() =>
            {
                dataFormApp.dataForm.IsEnabled = false;
                this.ExpectCurrentItemChange();
                dataFormApp.dataForm.DeleteItem();
            });

            this.WaitForCurrentItemChange();

            this.EnqueueCallback(() =>
            {
                dataFormApp.dataForm.IsEnabled = true;

                ButtonBase firstItemButton = this.GetTemplatePart<ButtonBase>("FirstItemButton");
                ButtonBase previousItemButton = this.GetTemplatePart<ButtonBase>("PreviousItemButton");
                ButtonBase nextItemButton = this.GetTemplatePart<ButtonBase>("NextItemButton");
                ButtonBase lastItemButton = this.GetTemplatePart<ButtonBase>("LastItemButton");
                ButtonBase newItemButton = this.GetTemplatePart<ButtonBase>("NewItemButton");
                ButtonBase deleteItemButton = this.GetTemplatePart<ButtonBase>("DeleteItemButton");
                ButtonBase editButton = this.GetTemplatePart<ButtonBase>("EditButton");

                Assert.IsTrue(firstItemButton.IsEnabled);
                Assert.IsTrue(previousItemButton.IsEnabled);
                Assert.IsTrue(nextItemButton.IsEnabled);
                Assert.IsTrue(lastItemButton.IsEnabled);
                Assert.IsTrue(newItemButton.IsEnabled);
                Assert.IsTrue(deleteItemButton.IsEnabled);
                Assert.IsTrue(editButton.IsEnabled);
            });

            this.EnqueueTestComplete();
        }