How do you verify that IEnumerable <SomeClass> has all the elements of the SomeClass class in MBunit?

How do you verify that IEnumerable has all the elements of the SomeClass class in MBunit?

I once used the Visual Studio Unit Test Framework and found CollectionAssert.AllAreInstancesOfTypeor something to test this.

But how to do it in MBunit?

+3
source share
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

Source: https://habr.com/ru/post/1711851/


All Articles