Exemplo n.º 1
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new RangeSlider());
     });
 }
Exemplo n.º 2
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new Magnifier());
     });
 }
Exemplo n.º 3
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new DataGridView());
     });
 }
Exemplo n.º 4
0
        public void SetNewTimeTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                TimePicker picker     = new TimePicker();
                picker.SelectedHour   = 1;
                picker.SelectedMinute = 2;
                picker.SelectedSecond = 3;

                Assert.AreEqual(1, picker.SelectedTime.Hours, "Invalid hour set");
                Assert.AreEqual(2, picker.SelectedTime.Minutes, "Invalid minute set");
                Assert.AreEqual(3, picker.SelectedTime.Seconds, "Invalid second set");

                //try to set some invalid values
                picker                      = new TimePicker();
                bool hasEventFired          = false;
                picker.SelectedTimeChanged += delegate { hasEventFired = true; };
                picker.SelectedHour         = 44;
                //check if the event has been fired
                Assert.IsTrue(hasEventFired, "Event not fired");
                hasEventFired         = false;
                picker.SelectedMinute = 2;
                Assert.IsTrue(hasEventFired, "Event not fired");
                hasEventFired         = false;
                picker.SelectedSecond = 99;
                Assert.IsTrue(hasEventFired, "Event not fired");

                Assert.AreEqual(23, picker.SelectedTime.Hours, "Invalid hour set");
                Assert.AreEqual(2, picker.SelectedTime.Minutes, "Invalid minute set");
                Assert.AreEqual(59, picker.SelectedTime.Seconds, "Invalid second set");
            });
        }
Exemplo n.º 5
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new RatingSelector());
     });
 }
Exemplo n.º 6
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new DateTimePicker());
     });
 }
Exemplo n.º 7
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new TreeListBox());
     });
 }
Exemplo n.º 8
0
        public void TestResetItemsSource()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //populate sample data
                List <string> businessObjects = new List <string>(4);
                businessObjects.Add("A");
                businessObjects.Add("AA");
                businessObjects.Add("AAA");
                businessObjects.Add("AAAA");
                businessObjects.Add("AAAA");

                TreeListBox treeListBox = new TreeListBox();
                treeListBox.ExposedGenerateItemsSource(businessObjects);

                //check that there are 4 items in the items source and that they are of type TreeLiistBoxInfo
                Assert.AreEqual(5, treeListBox.Items.Count,
                                "Invalid number of items added");
                for (int i = 0; i < treeListBox.Items.Count; i++)
                {
                    Assert.AreEqual(typeof(TreeListBoxInfo),
                                    treeListBox.Items[i].GetType(),
                                    "Invalid type added to tree list box");
                }
            });
        }
Exemplo n.º 9
0
        public void TrimSelectedTextTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                TextBox textBox = new TextBox();
                //try to trim when there are no text
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("", textBox.Text, "Trim failed");

                textBox      = new TextBox();
                textBox.Text = "10";
                textBox.SelectAll();
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("", textBox.Text, "Trim failed when selection was All");

                textBox                 = new TextBox();
                textBox.Text            = "10";
                textBox.SelectionStart  = 0;
                textBox.SelectionLength = 1;
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("0", textBox.Text, "Trim failed when selection was at the first char");

                textBox                 = new TextBox();
                textBox.Text            = "10";
                textBox.SelectionStart  = 1;
                textBox.SelectionLength = 1;
                TimePicker.ExposeTrimSelectedText(textBox);
                Assert.AreEqual("1", textBox.Text, "Trim failed when selection was at the second char");
            });
        }
Exemplo n.º 10
0
 public void RunDataBindingTests()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         AvalonTestRunner.RunDataBindingTests(new MaskedTextBoxTest());
     });
 }
Exemplo n.º 11
0
 public void TestMainWindow()
 {
     AvalonTestRunner.RunInSTA(
         delegate
     {
         MainWindow window = new MainWindow();
         Assert.AreEqual(300, window.Height);
     });
 }
Exemplo n.º 12
0
 public void TestEventFire()
 {
     AvalonTestRunner.RunInSTA(delegate
     {
         DatePicker picker            = new DatePicker();
         bool hasEventFired           = false;
         picker.SelectedDateChanged  += delegate { hasEventFired = true; };
         picker.CurrentlySelectedDate = new DateTime(10);
         Assert.IsTrue(hasEventFired, "Event not fired");
     });
 }
Exemplo n.º 13
0
        public void TestDataBindingForControls()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //test the main window XAML.
                //This will assert all data binding errors
                AvalonTestRunner.RunDataBindingTests(new MainWindow());

                //runs the test for a specific user control
                AvalonTestRunner.RunDataBindingTests(new UserControlTests());
            });
        }
Exemplo n.º 14
0
        public void TestItemsSourceCollectionNotifications()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //populate sample data
                ObservableCollection <string> businessObjects =
                    new ObservableCollection <string>();
                businessObjects.Add("A");
                businessObjects.Add("AA");
                businessObjects.Add("AAA");
                businessObjects.Add("AAAA");

                TreeListBox treeListBox = new TreeListBox();
                treeListBox.ExposedGenerateItemsSource(businessObjects);
                Assert.AreEqual(4, treeListBox.Items.Count,
                                "Invalid number of items added");

                //add anew item and verify that this item was added to the items source
                businessObjects.Add("NewItem1");
                //check the Count
                Assert.AreEqual(5, treeListBox.Items.Count,
                                "Invalid number of items added");
                //check the position of the item
                Assert.AreEqual("NewItem1",
                                ((TreeListBoxInfo)treeListBox.Items[4]).DataItem,
                                "Item was added at an invalid index");

                //insert another item in the begining of the list
                businessObjects.Insert(1, "NewItem2");
                //check the Count
                Assert.AreEqual(6, treeListBox.Items.Count,
                                "Invalid number of items added");
                //check the position of the item
                Assert.AreEqual("NewItem2",
                                ((TreeListBoxInfo)treeListBox.Items[1]).DataItem,
                                "Item was added at an invalid index");

                //Check the remove
                businessObjects.RemoveAt(1);
                //check the Count
                Assert.AreEqual(5, treeListBox.Items.Count,
                                "Invalid number of items added");
                //validate that the item was deleted properly
                for (int i = 0; i < treeListBox.Items.Count; i++)
                {
                    Assert.AreNotEqual("NewItem2",
                                       ((TreeListBoxInfo)treeListBox.Items[i]).DataItem,
                                       "Item was removed from the wrong index");
                }
            });
        }
Exemplo n.º 15
0
        public void AdjustCarretIndexOrMoveToNeighbourTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                TextBox textBox   = new TextBox();
                TextBox neighbour = new TextBox();
                textBox.Text      = "10";
                TimePicker.ExposeAdjustCarretIndexOrMoveToNeighbour(textBox, neighbour);
                Assert.AreEqual(1, textBox.CaretIndex, "Invalid caret index");
                Assert.IsFalse(neighbour.IsFocused, "Neighbour is focused");

                //the carrot is now moved...try to call the method again to focus the neighbour
                TimePicker.ExposeAdjustCarretIndexOrMoveToNeighbour(textBox, neighbour);
                Assert.IsTrue(neighbour.IsFocused, "Neighbour is not focused");
            });
        }
Exemplo n.º 16
0
        public void TestChangeDateSelected()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                DateTimePicker picker = new DateTimePicker();
                picker.OnApplyTemplate();
                bool hasEventFired              = false;
                picker.SelectedDateTimeChanged += delegate { hasEventFired = true; };
                picker.DateTimeSelected         = new DateTime(10);
                Assert.IsTrue(hasEventFired, "Event not fired");

                DateTime s = new DateTime(1, 1, 1, 2, 2, 2);

                picker.DateTimeSelected = new DateTime(1, 1, 1, 2, 2, 2);
                Assert.AreEqual(new DateTime(1, 1, 1, 2, 2, 2), picker.DateTimeSelected, "Invalid date set");
            });
        }
Exemplo n.º 17
0
        public void MaskTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                MaskedTextBox textBox = new MaskedTextBox();
                //set mask and test output
                textBox.Mask = "00-00";
                textBox.Text = "1111";
                Assert.AreEqual("11-11", textBox.Text, "Invalid text set");

                //make same test but this time first set the text
                textBox      = new MaskedTextBox();
                textBox.Text = "1111";
                textBox.Mask = "00-00";
                Assert.AreEqual("11-11", textBox.Text, "Invalid text set");
            }
                                      );
        }
Exemplo n.º 18
0
        public void TryFocusNeighbourControlTest()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                TextBox current = new TextBox();
                TextBox left    = new TextBox();
                TextBox right   = new TextBox();

                current.Text       = "10";
                current.CaretIndex = 2;

                //test going focus left with null
                TimePicker.ExposeTryFocusNeighbourControl(current, null, null, Key.Left);
                //now test with left textbox but with the invalid caret index
                TimePicker.ExposeTryFocusNeighbourControl(current, left, right, Key.Left);
                Assert.IsFalse(left.IsFocused, "left was focused");

                current.CaretIndex = 0;
                TimePicker.ExposeTryFocusNeighbourControl(current, left, right, Key.Left);
                Assert.IsTrue(left.IsFocused, "left was NOT focused");

                current = new TextBox();
                left    = new TextBox();
                right   = new TextBox();

                current.Text       = "10";
                current.CaretIndex = 0;
                //test going focus right with null
                TimePicker.ExposeTryFocusNeighbourControl(current, null, null, Key.Right);
                //now test with right textbox but with the invalid caret index
                TimePicker.ExposeTryFocusNeighbourControl(current, left, right, Key.Right);
                Assert.IsFalse(right.IsFocused, "right was focused");

                current.CaretIndex = 2;
                TimePicker.ExposeTryFocusNeighbourControl(current, left, right, Key.Right);
                Assert.IsTrue(right.IsFocused, "right was NOT focused");
            });
        }
Exemplo n.º 19
0
        public void TestSyncronizationOFPickers()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                DateTimePicker picker = new DateTimePicker();
                DatePicker datePicker = null;
                TimePicker timePicker = null;
                picker.OnApplyTemplate();//force the apply template
                picker.ExposedDatePicker(ref datePicker, ref timePicker);
                picker.DateTimeSelected = new DateTime(1, 1, 1, 2, 2, 2);
                Assert.AreEqual(picker.DateTimeSelected.Date, datePicker.CurrentlySelectedDate.Date, "Invalid date set");
                Assert.AreEqual(picker.DateTimeSelected.TimeOfDay, timePicker.SelectedTime, "Invalid time set");

                //now check that if the date is changed from the picker the date for DateTimePicker is updated as well
                DateTime testDate = new DateTime(1, 2, 1);
                datePicker.CurrentlySelectedDate = testDate;
                Assert.AreEqual(testDate, picker.DateTimeSelected.Date, "Invalid date set from date picker");

                TimeSpan testTime       = new TimeSpan(1, 2, 1);
                timePicker.SelectedTime = testTime;
                Assert.AreEqual(testTime, picker.DateTimeSelected.TimeOfDay, "Invalid time set from time picker");
            });
        }
Exemplo n.º 20
0
        public void TestPopulationOfChildrenFromNotifications()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //children collection
                ObservableCollection <MockHierarchalObject> childNodes =
                    new ObservableCollection <MockHierarchalObject>(
                        new List <MockHierarchalObject>(new MockHierarchalObject[]
                {
                    //children
                    new MockHierarchalObject(
                        "child1 of A"),
                    new MockHierarchalObject(
                        "child2 of A"),
                    new MockHierarchalObject(
                        "child3 of A"),
                }));

                //create sample data
                MockHierarchalObject dataSource =
                    new MockHierarchalObject("A", childNodes);

                //prepare the parent collection
                TreeListBox parentControl         = new TreeListBox();
                parentControl.ChildItemSourcePath = "Children";
                parentControl.ExposedGenerateItemsSource(new MockHierarchalObject[]
                {
                    new MockHierarchalObject(
                        "First, item with no children")
                    ,
                    //add a simple item that has no children
                    dataSource,
                    //add the item that has children to test on
                    new MockHierarchalObject(
                        "Last, item with no children")
                });

                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");
                //create an item to test
                TreeListBoxItem item = new TreeListBoxItem(parentControl);
                item.ExposePrepareItem(parentControl.Items[1] as TreeListBoxInfo);
                //pass the info that was create for the item that has children

                //expand the item this should result in the items source of the parent include the children
                item.IsExpanded = true;
                //3 root nodes and 3 children are suppose to be in the list
                Assert.AreEqual(3 + 3, parentControl.Items.Count,
                                "Invalid number of items");

                //add a new item to child collection and check if it is added
                childNodes.Add(new MockHierarchalObject("child4 of A"));
                //3 root nodes and 3 + 1(which is the new one) children are suppose to be in the list
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items");
                //check the index of the new item in the flat list
                //1 is the index of the container item, and 4 is the count of the children
                Assert.AreEqual("child4 of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1 + 4]).DataItem).
                                Text,
                                "Item was not added in the right index");

                //check that the insert in a specific index
                childNodes.Insert(2, new MockHierarchalObject("inserted child of A"));
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items");
                //check that the insert was done in the right index(where 1 is the parent index and 2 is the index in the children collection)
                Assert.AreEqual("inserted child of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1 + 3]).DataItem).
                                Text,
                                "Item was not added in the right index");

                //check the remove of items
                childNodes.RemoveAt(2);
                //check the Count
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items added");
                //validate that the item was deleted properly
                for (int i = 0; i < parentControl.Items.Count; i++)
                {
                    Assert.AreNotEqual("inserted child of A",
                                       ((MockHierarchalObject)
                                        ((TreeListBoxInfo)parentControl.Items[i]).
                                        DataItem).Text,
                                       "Item was removed from the wrong index");
                }

                //check that if we collapse the items no children are add
                item.IsExpanded = false;
                //check that the items where collapsed
                Assert.AreEqual(3, parentControl.Items.Count,
                                "Invalid number of items after collapse item");

                childNodes.Add(new MockHierarchalObject("Test collapse"));
                //check that the item was not added to the flat list since the item is collapsed
                Assert.AreEqual(3, parentControl.Items.Count,
                                "Invalid number of items after collapse item");

                //check that when you re expand the item all items are generated
                item.IsExpanded = true;
                Assert.AreEqual(3 + childNodes.Count, parentControl.Items.Count,
                                "Invalid number of items after collapse item");
            });
        }
Exemplo n.º 21
0
        public void TestPopulationOfChildren()
        {
            AvalonTestRunner.RunInSTA(delegate
            {
                //create sample data
                MockHierarchalObject dataSource =
                    new MockHierarchalObject("A",
                                             new List <MockHierarchalObject>(
                                                 new MockHierarchalObject[]
                {
                    //children
                    new MockHierarchalObject(
                        "child1 of A"),
                    new MockHierarchalObject(
                        "child2 of A"),
                    new MockHierarchalObject(
                        "child3 of A"),
                }));

                //prepare the parent collection
                TreeListBox parentControl         = new TreeListBox();
                parentControl.ChildItemSourcePath = "Children";
                parentControl.ExposedGenerateItemsSource(new MockHierarchalObject[]
                {
                    new MockHierarchalObject(
                        "First, item with no children")
                    ,
                    //add a simple item that has no children
                    dataSource,
                    //add the item that has children to test on
                    new MockHierarchalObject(
                        "Last, item with no children")
                });
                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");
                //create an item to test
                TreeListBoxItem item = new TreeListBoxItem(parentControl);
                item.ExposePrepareItem(parentControl.Items[1] as TreeListBoxInfo);
                //pass the info that was create for the item that has children

                //expand the item this should result in the items source of the parent include the children
                item.IsExpanded = true;
                //3 root nodes and 3 children are suppose to be in the list
                Assert.AreEqual(3 + 3, parentControl.Items.Count,
                                "Invalid number of items");

                //check that the items where create in the right indeces
                Assert.AreEqual("child1 of A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2]).DataItem).Text,
                                "Child Item was placed in the wrong index");
                //validate that the last item(which is index to of the root nodes) of the root nodes has been moved to the proper index
                //2 is the index in the root nodes, 3 is the count of the children, so the last item should have moved to index 5
                Assert.AreEqual("Last, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2 + 3]).DataItem).
                                Text,
                                "Root Item was placed in the wrong index");

                //validate that the level of the items has been incremented
                //start from index 2, since the children are place at index 2
                for (int i = 2; i < 3 + 2; i++)
                {
                    Assert.AreEqual(1, ((TreeListBoxInfo)parentControl.Items[i]).Level,
                                    "Invalid level set for child nodes");
                }

                //Validate the Collapse
                item.IsExpanded = false;

                //all children should be dropped
                Assert.AreEqual(3, parentControl.Items.Count, "Invalid number of items");

                //check that the indeces of the items is back to normal
                Assert.AreEqual("First, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[0]).DataItem).Text,
                                "Root Item was placed in the wrong index");
                Assert.AreEqual("A",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[1]).DataItem).Text,
                                "Root Item was placed in the wrong index");
                Assert.AreEqual("Last, item with no children",
                                ((MockHierarchalObject)
                                 ((TreeListBoxInfo)parentControl.Items[2]).DataItem).Text,
                                "Root Item was placed in the wrong index");
            });
        }