This is a migrated thread and some comments may be shown as answers.

Doing greater than/less than comparisons on textblocks?

1 Answer 67 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ahmed
Top achievements
Rank 1
Ahmed asked on 20 Jan 2012, 06:25 AM
My situation is as follows:

I have a grid of text blocks which are supposed to be ordered in alphabetical order, like say:

A00000
A00001
A00002
B00001

and I'd like to write a test case to verify this.

The issues I have are two fold:

How do I do a comparison check between rows? As in check if row 2 is greater than row 1, then check if row 3 is greater than row 2, so on and so forth. I know I can do tests for the values in a single row but not sure how I'm supposed to tell the program to keep going down new rows programatically.

My other somewhat more pressing problem is that I've found text blocks do not have greater than/less than comparisons. A number based property such as 'ActualHeight' does have such comparisons and it seems strange text blocks do not considering C# does have gerater than and less than operations you can carry out on strings (and this is how the grid we're using orders data).


So any ideas on what I should do to achieve this? I'm using silverlight.    

1 Answer, 1 is accepted

Sort by
0
Anthony
Telerik team
answered on 20 Jan 2012, 07:55 PM
Hello Ahmed,

1. This can be accomplished in a coded step. See the following example against this Microsoft Silverlight demo site. After navigating there, I click "DataGrid" in the left-hand menu, then I click the "FirstName" header cell to alphabetize that column. Here is the subsequent coded step:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
DataGrid grid = app.Find.ByAutomationId<DataGrid>("dataGrid");
int r = grid.Rows.Count;
List<string> list = new List<string>();
 
for (int i = 0; i < r; i++)
{
    DataGridRow row = grid.Rows[i];
    DataGridCell cell = row.Cells[2];   
    list.Add(cell.TextBlockContent);
}
 
for (int j = 0; j < list.Count; j++)
{
    if (j+1 == list.Count)
    {
        break;
    }
    else
    {
        Assert.IsTrue(list[j+1].CompareTo(list[j]) >= 0);
    }
}
 
2. Ensure you target the .Text property of the TextBlock to access the CompareTo method:

SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
TextBlock tb = app.Find.ById<TextBlock>("test");
 
string a = "alpha";
Log.WriteLine(tb.Text.CompareTo(a).ToString());


All the best,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Ahmed
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Share this question
or