public void DataGridItem_ISelectionProvider() { List<Customer> boundList = CreateCustomerList(5); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = boundList; dataGrid.ColumnWidth = new DataGridLength(100.0); TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); AutomationPeer peer; ISelectionProvider selector; TestPeer testPeer = new TestPeer(dataGrid); EnqueueCallback(delegate { peer = new DataGridItemAutomationPeer(boundList[0], dataGrid); Assert.IsNotNull(peer); selector = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selector); Assert.AreEqual(1, selector.GetSelection().Length); peer = testPeer.GetPeerFromProvider(selector.GetSelection()[0]); Assert.AreEqual(typeof(DataGridCell).Name, peer.GetClassName(), "GetSelection did not return DataGridCell"); }); this.EnqueueYieldThread(); EnqueueTestComplete(); }
public void DataGridItem_ISelectionItemProvider() { List<Customer> boundList = CreateCustomerList(5); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = boundList; dataGrid.ColumnWidth = new DataGridLength(100.0); TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); List<DataGridRow> rows = new List<DataGridRow>(); AutomationPeer peer; List<ISelectionItemProvider> selectionItems = new List<ISelectionItemProvider>(); EnqueueCallback(delegate { for (int i = 0; i < boundList.Count; i++) { rows.Add(dataGrid.GetRowFromItem(boundList[i])); peer = new DataGridItemAutomationPeer(boundList[i], dataGrid); Assert.IsNotNull(peer); selectionItems.Add(peer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider); Assert.IsNotNull(selectionItems[i]); selectionItems[i].AddToSelection(); } }); this.EnqueueYieldThread(); EnqueueCallback(delegate { foreach (DataGridRow row in rows) { Assert.IsTrue(row.IsSelected); } foreach (ISelectionItemProvider select in selectionItems) { select.RemoveFromSelection(); } }); this.EnqueueYieldThread(); EnqueueCallback(delegate { foreach (DataGridRow row in rows) { Assert.IsFalse(row.IsSelected); } selectionItems[0].Select(); selectionItems[3].Select(); selectionItems[3].Select(); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.IsFalse(rows[0].IsSelected); Assert.IsTrue(rows[3].IsSelected); dataGrid.SelectionMode = DataGridSelectionMode.Single; selectionItems[4].AddToSelection(); // }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.IsFalse(rows[2].IsSelected); Assert.IsTrue(rows[4].IsSelected); }); EnqueueTestComplete(); }
public void DataGridItem_IInvokeProvider() { List<Customer> boundList = CreateCustomerList(5); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 200; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = boundList; TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); AutomationPeer peer; IInvokeProvider invoker; int index = 0; for (int i = 0; i < boundList.Count; i++) { EnqueueCallback(delegate { Assert.IsNull(dataGrid.EditingRow); Assert.AreEqual(-1, dataGrid.EditingColumnIndex); peer = new DataGridItemAutomationPeer(boundList[index], dataGrid); Assert.IsNotNull(peer); invoker = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke); Assert.IsNotNull(invoker); invoker.Invoke(); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.AreEqual(0, dataGrid.EditingColumnIndex); Assert.IsNotNull(dataGrid.EditingRow); Assert.AreEqual(index, dataGrid.EditingRow.Index); peer = new DataGridItemAutomationPeer(boundList[index], dataGrid); Assert.IsNotNull(peer); invoker = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke); Assert.IsNotNull(invoker); invoker.Invoke(); index++; }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.IsNull(dataGrid.EditingRow); Assert.AreEqual(-1, dataGrid.EditingColumnIndex); }); } EnqueueTestComplete(); }
public void DataGridItem_IScrollItemProvider() { List<Customer> boundList = CreateCustomerList(25); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = boundList; dataGrid.ColumnWidth = new DataGridLength(100.0); TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); AutomationPeer peer; IScrollItemProvider scrollItem; int index = boundList.Count; for (int i = 0; i < boundList.Count; i++) { EnqueueCallback(delegate { index--; peer = new DataGridItemAutomationPeer(boundList[index], dataGrid); Assert.IsNotNull(peer); scrollItem = peer.GetPattern(PatternInterface.ScrollItem) as IScrollItemProvider; Assert.IsNotNull(scrollItem); scrollItem.ScrollIntoView(); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.IsTrue(dataGrid.IsSlotVisible(dataGrid.SlotFromRowIndex(index))); }); } EnqueueTestComplete(); }
public void DataGridGroupItem_ISelectionProvider() { PagedCollectionView customers = CreateGroupedCustomerCollectionView(); DataGrid dataGrid = new DataGrid(); Assert.IsNotNull(dataGrid); isLoaded = false; dataGrid.Width = 350; dataGrid.Height = 250; dataGrid.Loaded += new RoutedEventHandler(dataGrid_Loaded); dataGrid.AutoGenerateColumns = true; dataGrid.ItemsSource = customers; TestPanel.Children.Add(dataGrid); EnqueueConditional(delegate { return isLoaded; }); this.EnqueueYieldThread(); AutomationPeer peer; ISelectionProvider selector = null; TestPeer testPeer = new TestPeer(dataGrid); EnqueueCallback(delegate { CollectionViewGroup group = customers.Groups[1] as CollectionViewGroup; Assert.IsNotNull(group, "PagedCollectionView did not return CollectionViewGroup"); peer = new DataGridGroupItemAutomationPeer(group, dataGrid); Assert.IsNotNull(peer); selector = peer.GetPattern(PatternInterface.Selection) as ISelectionProvider; Assert.IsNotNull(selector); Assert.AreEqual(0, selector.GetSelection().Length, "There should not be any selected items within this group"); // Select an item within group 1 peer = new DataGridItemAutomationPeer(customers[3], dataGrid); Assert.IsNotNull(peer); ISelectionItemProvider selectionItem = peer.GetPattern(PatternInterface.SelectionItem) as ISelectionItemProvider; Assert.IsNotNull(selectionItem); selectionItem.AddToSelection(); }); this.EnqueueYieldThread(); EnqueueCallback(delegate { Assert.IsNotNull(selector); Assert.AreEqual(1, selector.GetSelection().Length, "There should be a single selected item within this group"); peer = testPeer.GetPeerFromProvider(selector.GetSelection()[0]); Assert.AreEqual(typeof(DataGridRow).Name, peer.GetClassName(), "GetSelection did not return DataGridRow"); }); this.EnqueueYieldThread(); EnqueueTestComplete(); }