How do you verify that IEnumerable <SomeClass> has all the elements of the SomeClass class in MBunit?
2 answers
I did not see anything in the MBUnit CollectionAssertClass that could help you here
You can easily write your own though (untested).
public class MyCollectionAssert
{
public void CollectionAssert(IEnumerable source, Predicate<object> assertion)
{
foreach(var item in source)
{
Assert.IsTrue(assertion(item));
}
}
public void AllAreInstancesOfType(IEnumerable source, Type type)
{
return CollectionAssert(source, o => o.GetType() == type);
}
}
I assume that you actually mean IEnumerable, and not IEnumerable<SomeClass>which the compiler provides type safety. To use this extension method, call:
MyCollectionAssert.AllAreInstancesOfType(myList, typeof(SomeClass));
0
, Gallio issue . : Assert.ForAll Assert.Exists. Gallio/MbUnit (v3.1), , ( ).
Edit:
Gallio/MbUnit v3.1.213, Assert.ForAll<T>(IEnumerable<T>, Predicate<T>).
[Test]
public void AllMyObjectsShouldBeStrings()
{
var list = GetThemAll();
Assert.ForAll(list, x => x.GetType() == typeof(string));
}
+1