IEnumerable<T> Assertions

These assertion extension methods can be applied to only IEnumerable<T> object types.

ShouldBeEmpty

Asserts that this IEnumerable<T> does not contain any items.

Usage

public static IEnumerable<T> ShouldBeEmpty<T>(this IEnumerable<T> source)
public static IEnumerable<T> ShouldBeEmpty<T>(this IEnumerable<T> source, string message)
public static IEnumerable<T> ShouldBeEmpty<T>(this IEnumerable<T> source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>();
   foo.ShouldBeEmpty();
}
Supported Releases: 1.2 and later

ShouldNotBeEmpty

Asserts that this IEnumerable<T> contains items.

Usage

public static IEnumerable<T> ShouldNotBeEmpty<T>(this IEnumerable<T> source)
public static IEnumerable<T> ShouldNotBeEmpty<T>(this IEnumerable<T> source, string message)
public static IEnumerable<T> ShouldNotBeEmpty<T>(this IEnumerable<T> source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldNotBeEmpty();
}
Supported Releases: 1.2 and later

ShouldContain

Asserts that this IEnumerable<T> contains the specified item.

Usage

public static IEnumerable<T> ShouldContain<T>(this IEnumerable<T> source, T item)
public static IEnumerable<T> ShouldContain<T>(this IEnumerable<T> source, T item, string message)
public static IEnumerable<T> ShouldContain<T>(this IEnumerable<T> source, T item, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldContain(1);
}
Supported Releases: 1.2 and later

ShouldNotContain

Asserts that this IEnumerable<T> does not contain the specified item.

Usage

public static IEnumerable<T> ShouldNotContain<T>(this IEnumerable<T> source, T item)
public static IEnumerable<T> ShouldNotContain<T>(this IEnumerable<T> source, T item, string message)
public static IEnumerable<T> ShouldNotContain<T>(this IEnumerable<T> source, T item, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldNotContain(0);
}
Supported Releases: 1.2 and later

ShouldHaveCountOf

Asserts that this IEnumerable<T> contains the specified number of items.

Usage

public static IEnumerable<T> ShouldHaveCountOf<T>(this IEnumerable<T> source, int count)
public static IEnumerable<T> ShouldHaveCountOf<T>(this IEnumerable<T> source, int count, string message)
public static IEnumerable<T> ShouldHaveCountOf<T>(this IEnumerable<T> source, int count, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldHaveCountOf(3);
}
Supported Releases: 1.2 and later

ShouldNotHaveCountOf

Asserts that this IEnumerable<T> does not contain the specified number of items.

Usage

public static IEnumerable<T> ShouldNotHaveCountOf<T>(this IEnumerable<T> source, int count)
public static IEnumerable<T> ShouldNotHaveCountOf<T>(this IEnumerable<T> source, int count, string message)
public static IEnumerable<T> ShouldNotHaveCountOf<T>(this IEnumerable<T> source, int count, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldNotHaveCountOf(4);
}
Supported Releases: 1.2 and later

ShouldHaveCountOfAtLeast

Asserts that this IEnumerable<T> contains a minimum specified number of items.

Usage

public static IEnumerable<T> ShouldHaveCountOfAtLeast<T>(this IEnumerable<T> source, int count)
public static IEnumerable<T> ShouldHaveCountOfAtLeast<T>(this IEnumerable<T> source, int count, string message)
public static IEnumerable<T> ShouldHaveCountOfAtLeast<T>(this IEnumerable<T> source, int count, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldHaveCountOfAtLeast(2);
}
Supported Releases: 1.2 and later

ShouldHaveCountOfAtMost

Asserts that this IEnumerable<T> contains a maximum specified number of items.

Usage

public static IEnumerable<T> ShouldHaveCountOfAtMost<T>(this IEnumerable<T> source, int count)
public static IEnumerable<T> ShouldHaveCountOfAtMost<T>(this IEnumerable<T> source, int count, string message)
public static IEnumerable<T> ShouldHaveCountOfAtMost<T>(this IEnumerable<T> source, int count, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   IEnumerable<int> foo = new List<int>() { 1, 2, 3 };
   foo.ShouldHaveCountOfAtMost(4);
}
Supported Releases: 1.2 and later

Last edited Dec 9, 2010 at 3:32 PM by jeremiahclark, version 4

Comments

No comments yet.