ICollection<T> Assertions

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

ShouldBeEmpty

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

Usage

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

Example

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

ShouldNotBeEmpty

Asserts that this ICollection<T> contains items.

Usage

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

Example

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

ShouldContain

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

Usage

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

Example

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

ShouldNotContain

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

Usage

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

Example

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

ShouldHaveCountOf

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

Usage

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

Example

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

Last edited Dec 9, 2010 at 2:54 PM by jeremiahclark, version 3

Comments

No comments yet.