Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
594
UltraGrid 7.2 not populating from data source in unit test
posted

Hi,

 I'm testing a component that search the grid and, in order to do this, am populating a DataTable with random data and assigning it as the DataSource on a UltraGrid. However, it appears the grid doesn't do anything with the data. Is this possible, or is the grid only functional on a form?

 My test code:

[TestFixture]

public class UltraGridSearcherFixture

{

private struct ColumnLabels

{

public static string Id = "Id";

public static string Qty = "Qty";

public static string Value = "Value";

}

[Test]

public void Test()

{

#region Create test data

const int ROW_COUNT = 1000;

DataTable data = new DataTable("DataRecord");data.Columns.AddRange(new DataColumn[

{

new DataColumn(ColumnLabels.Id, typeof(Guid)),

new DataColumn(ColumnLabels.Qty, typeof(int)),new DataColumn(ColumnLabels.Value, typeof(decimal))

}

);

for (int i = 0; i < ROW_COUNT; i++)

{

Random rnd = new Random(Environment.TickCount);

DataRow newRow = data.NewRow();

newRow[ColumnLabels.Id] = Guid.NewGuid();

newRow[ColumnLabels.Qty] = rnd.Next(-100, 100);

newRow[ColumnLabels.Value] = 1000 * rnd.NextDouble();

}

#endregion

UltraGrid grid = new UltraGrid();

grid.DataSource = data;

grid.DataBind();

Assert.AreEqual(ROW_COUNT, grid.Rows.Count);

}

}

  • 37774
    posted

    The grid is never going to paint here, so it will never actually do anything with the data.  You will need to put the grid on a form and show that form; I also tend to dock the grid to Fill as well to ensure that it's visible when doing unit tests.

    -Matt