In some of my tests, I need to check the order of the lists and do something like this
DateTime lastDate = new DateTime(2009, 10, 1);
foreach (DueAssigmentViewModel assignment in _dueAssigments)
{
if (assignment.DueDate < lastDate)
{
Assert.Fail("Not Correctly Ordered");
}
lastDate = assignment.DueDate;
}
What I would like to do, I turn this into an extension method in IEnumerable to make it reusable.
My inner idea was that
public static bool IsOrderedBy<T, TestType>(this IEnumerable<T> value, TestType initalValue)
{
TestType lastValue = initalValue;
foreach (T enumerable in value)
{
if(enumerable < lastValue)
{
return false;
}
lastValue = value;
}
return true;
}
The obvious problem is that you cannot match common values. Can someone suggest a way around this.
Cheers Colin
source
share