public void CancelAndRevert()
        {
            string search = "Data1";

            OverriddenSelectionAdapter.Current = null;
            OverriddenAutoCompleteBox     control = GetDerivedAutoComplete();
            ObservableCollection <string> data    = new ObservableCollection <string>
            {
                "Data1",
                "Data2",
            };

            control.ItemsSource = data;
            ObservableCollection <object> view = null;
            OverriddenSelectionAdapter    tsa  = null;

            bool isLoaded = false;

            control.Loaded += delegate { isLoaded = true; };
            EnqueueCallback(() => TestPanel.Children.Add(control));
            EnqueueConditional(() => isLoaded);

            EnqueueCallback(
                () => Assert.IsNotNull(control.TextBox, "The TextBox part could not be retrieved."),
                () => control.SelectedItem = search,
                () => control.TextBox.Text = "Dat");
            EnqueueConditional(() => control.IsDropDownOpen);

            // Assert the 2 items, then add an item, and assert the new value
            EnqueueCallback(
                () => tsa = OverriddenSelectionAdapter.Current,
                () => Assert.IsNotNull(tsa, "The testable selection adapter was not found."),
                () => view = tsa.ItemsSource as ObservableCollection <object>,
                () => Assert.AreEqual(2, view.Count),
                () => tsa.SelectFirst(),
                () => tsa.SelectNext(), // control.TextBox.Text = "Data2",
                () => tsa.TestCancel());

            // Wait for the drop down to close
            EnqueueConditional(() => control.IsDropDownOpen == false);

            // Assert the revert
            EnqueueCallback(() => Assert.AreEqual("Dat", control.Text, "The text was not reverted to the search text value."));

            EnqueueTestComplete();
        }
        public void SelectedItemBinding()
        {
            OverriddenAutoCompleteBox acb = new OverriddenAutoCompleteBox();
            acb.ItemsSource = "words go here".Split();
            ContentControl cc = new ContentControl();
            Binding b = new Binding("SelectedItem");
            b.Source = acb;
            cc.SetBinding(ContentControl.ContentProperty, b);

            int loadedCount = 0;
            acb.Loaded += (o, e) => loadedCount++;
            cc.Loaded += (o, e) => loadedCount++;

            EnqueueCallback(() => TestPanel.Children.Add(acb));
            EnqueueCallback(() => TestPanel.Children.Add(cc));
            EnqueueConditional(() => 2 == loadedCount);

            EnqueueCallback(() => acb.TextBox.Text = "w");
            EnqueueConditional(() => acb.IsDropDownOpen);

            EnqueueCallback(() => OverriddenSelectionAdapter.Current.SelectFirst());
            EnqueueCallback(() => Assert.AreEqual("words", acb.SelectedItem));

            EnqueueCallback(() => OverriddenSelectionAdapter.Current.TestCommit());
            EnqueueConditional(() => !acb.IsDropDownOpen);

            EnqueueCallback(() => Assert.AreEqual("words", cc.Content));

            EnqueueTestComplete();
        }
        public void NoDropDownOpeningAtStartup()
        {
            OverriddenAutoCompleteBox acb = new OverriddenAutoCompleteBox();
            bool eventFired = false;
            bool isLoaded = false;
            acb.DropDownOpening += (o, e) => eventFired = true;
            MethodCallMonitor dropDownOpeningMonitor = acb.DropDownOpeningActions.CreateMonitor();
            acb.Loaded += (o, e) => isLoaded = true;

            EnqueueCallback(() => TestPanel.Children.Add(acb));
            EnqueueConditional(() => isLoaded);
            EnqueueCallback(() => Assert.IsFalse(eventFired, "The DropDownOpening event fired during startup."));
            EnqueueCallback(() => dropDownOpeningMonitor.AssertNotCalled("The OnDropDownOpening method was called."));
            EnqueueTestComplete();
        }