Hi!
I am trying to unit test some code which manipulates a xamGrid. However, never fills with rows or columns even though I set an ItemsSource on it. This is my unit test. How can I create a XamGrid with rows and columns for testing? By the way, my project is in a WPF context, not Silverlight, but this is the only place with a XamGrid forum.
[TestFixture]public class XamGridUtilsTests { private class DataItem { public int I { get; set; } public string Text { get; set; } public DataItem(int i, string text) { I = i; Text = text; } } [Test] [RequiresSTA] public void SelectAllRows_NoneSelected_SelectsAllRows() { // Arrange ObservableCollection<DataItem> items = new ObservableCollection<DataItem>(); for (int i = 1; i < 4; i++) { items.Add(new DataItem(i, "Column" + i)); } XamGrid grid = new XamGrid(); grid.AutoGenerateColumns = true; grid.ItemsSource = items; CollectionAssert.IsNotEmpty(grid.Rows); <-- THIS FAILS CollectionAssert.IsNotEmpty(grid.Columns); <-- THIS FAILS // Act XamGridUtils.SelectAllRows(grid); // Assert foreach (var row in grid.Rows) { Assert.IsTrue(row.IsSelected); } }}
Hi Atle Rudshau,
as far as I could understand you do not attach the grid to a visual tree. There is huge chance that XamGrid needs to be loaded/measured in order to try to auto-generate its columns and populate the rows.
HTH,
Hello Atle,
Thank you for your post. I have been looking into it but it seems like that I am missing something in your scenario, so if this is still an issue for you, could you please send an isolated sample project, where the issue is reproduced, so I can investigate it further for you.
Looking forward for your reply.