コード例 #1
0
 public void GridRowNumberConverter_Convert_WhenInputNotDataGridRow_ReturnsMinus1()
 {
     //------------Setup for test--------------------------
     var converter = new GridRowNumberConverter();
     DataGrid dataGrid = new DataGrid { AutoGenerateColumns = true };
     var itemsSource = new List<string> { "Item 1 ", "Item 2" };
     dataGrid.ItemsSource = itemsSource;
     dataGrid.SelectedItem = itemsSource[0];
     var row = new Object();
     //------------Execute Test---------------------------
     var result = converter.Convert(row, typeof(string), null, CultureInfo.CurrentCulture);
     //------------Assert Results-------------------------
     Assert.AreEqual(-1, result);
 }
コード例 #2
0
 public void GridRowNumberConverter_Convert_WhenValidRow_ReturnsRowIndex()
 {
     var converter = new GridRowNumberConverter();
     DataGrid dataGrid = new DataGrid { AutoGenerateColumns = true };
     var itemsSource = new List<string> { "Item 1 ", "Item 2" };
     dataGrid.ItemsSource = itemsSource;
     dataGrid.SelectedItem = itemsSource[0];
     IItemContainerGenerator generator = dataGrid.ItemContainerGenerator;
     var position = generator.GeneratorPositionFromIndex(0);
     using(generator.StartAt(position, GeneratorDirection.Forward, true))
     {
         foreach(object o in dataGrid.Items)
         {
             DependencyObject dp = generator.GenerateNext();
             generator.PrepareItemContainer(dp);
         }
     }
     var row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromItem(dataGrid.SelectedItem);
     //------------Execute Test---------------------------
     var result = converter.Convert(row, typeof(string), null, CultureInfo.CurrentCulture);
     //------------Assert Results-------------------------
     Assert.AreEqual(1, result);
 }