Если все тесты должны быть запущены , вы можете сделать это без LINQ:
private bool TestAll()
{
var allTestsPassed = true;
foreach (var item in Items)
{
allTestsPassed = Test(item) && allTestsPassed;
}
return allTestsPassed;
}
Вы можете сделать это с помощью LINQ:
private bool TestAll()
{
return Items.Count(Test) == Items.Count();
}
Обновление: возврат false
, если нет тестов для запуска
private bool TestAllWithoutLinq()
{
if (Items.Count == 0) { // or something equivalent
return false;
}
var allTestsPassed = true;
foreach (var item in Items)
{
allTestsPassed = Test(item) && allTestsPassed;
}
return allTestsPassed;
}
private bool TestAllWithLinq()
{
return Items.Any() && Items.Count(Test) == Items.Count();
}