Skip to content

Provides assertions for IEnumerable<T> that follow the same patterns as the assertion classes provided in MSTest.TestFramework

License

Notifications You must be signed in to change notification settings

ellenfieldn/EnumerableAssert

Repository files navigation

MSTest.TestFramework.Contrib.EnumerableAssert

Provides assertions for IEnumerable<T> that follow the same patterns as the assertion classes provided in MSTest.TestFramework

Example:

var collection = new List<string> { "element", "unexpected element", "element2" };
EnumerableAssert.DoesNotContain(collection, s => s.IndexOf("u") == 0); //Throws an exception

API

  • EnumerableAssert.IsNullOrEmpty(IEnumerable)
  • EnumerableAssert.Contains(IEnumerable, T) - Contains the element at least once
  • EnumerableAssert.Contains(IEnumerable, Func<T, bool>) - Contains at least one element matching the predicate
  • EnumerableAssert.ContainsOne(IEnumerable, T) - Enumerable contains the element exactly once
  • EnumerableAssert.ContainsOne(IEnumerable, Func<T, bool>) - Enumerable contains exactly one element that matches the predicate
  • EnumerableAssert.IsTrueForAll(IEnumerable, Func<T, bool>) - Predicate is true for all elements in the collection
  • EnumerableAssert.DoesNotContain(IEnumerable, T) - Enumerable does not contain the element
  • EnumerableAssert.DoesNotContain(IEnumerable, Func<T, bool>) - Enumerable does not contain an element matching the predicate

Plan

In no particular order:

  • Add assertion similar to CollectionAssert.AreEquivalent, but that instead asserts that everything in collection A matches an element in collection B via a specified predicate
  • Same as above, but for Equals and the various subset/superset options.
  • Add assertions for non-generic collections such as IEnumerable.
  • Each method will contain overloads like the following
    • EnumerableAssert.IsNullOrEmpty<T>(IEnumerable<T>)
    • EnumerableAssert.IsNullOrEmpty<T>(IEnumerable<T>, String)
    • EnumerableAssert.IsNullOrEmpty<T>(IEnumerable<T>, String, Object[])
  • Allow for extensibility: EnumerableAssert.That.MyAssertionMethod

About

Provides assertions for IEnumerable<T> that follow the same patterns as the assertion classes provided in MSTest.TestFramework

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages