Show / Hide Table of Contents

Class CollectionAssertExtensions

Provides fluent assertion extension methods for collections.

Inheritance
object
CollectionAssertExtensions
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class CollectionAssertExtensions

Methods

| Edit this page View Source

ShouldAllMatch<T>(IEnumerable<T>, Func<T, bool>, string)

Verifies that all elements in the collection match the specified predicate.

Declaration
public static IEnumerable<T> ShouldAllMatch<T>(this IEnumerable<T> collection, Func<T, bool> predicate, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

Func<T, bool> predicate

The predicate to test against each element.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when not all elements match the predicate.

| Edit this page View Source

ShouldAnyMatch<T>(IEnumerable<T>, Func<T, bool>, string)

Verifies that at least one element in the collection matches the specified predicate.

Declaration
public static IEnumerable<T> ShouldAnyMatch<T>(this IEnumerable<T> collection, Func<T, bool> predicate, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

Func<T, bool> predicate

The predicate to test against each element.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when no elements match the predicate.

| Edit this page View Source

ShouldBeEmpty<T>(IEnumerable<T>, string)

Verifies that the collection is empty.

Declaration
public static IEnumerable<T> ShouldBeEmpty<T>(this IEnumerable<T> collection, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection is not empty.

| Edit this page View Source

ShouldBeSubsetOf<T>(IEnumerable<T>, IEnumerable<T>, string)

Verifies that the collection is a subset of the superset collection.

Declaration
public static IEnumerable<T> ShouldBeSubsetOf<T>(this IEnumerable<T> subset, IEnumerable<T> superset, string message)
Parameters
Type Name Description
IEnumerable<T> subset

The collection that should be a subset.

IEnumerable<T> superset

The collection that should contain all elements of the subset.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The subset collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collections.

Exceptions
Type Condition
AssertionException

Thrown when the subset is not contained in the superset.

| Edit this page View Source

ShouldBeSupersetOf<T>(IEnumerable<T>, IEnumerable<T>, string)

Verifies that the collection is a superset of the subset collection.

Declaration
public static IEnumerable<T> ShouldBeSupersetOf<T>(this IEnumerable<T> superset, IEnumerable<T> subset, string message)
Parameters
Type Name Description
IEnumerable<T> superset

The collection that should contain all elements of the subset.

IEnumerable<T> subset

The collection that should be contained in the superset.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The superset collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collections.

Exceptions
Type Condition
AssertionException

Thrown when the superset does not contain all elements of the subset.

| Edit this page View Source

ShouldContain<T>(IEnumerable<T>, T, string)

Verifies that the collection contains the specified item.

Declaration
public static IEnumerable<T> ShouldContain<T>(this IEnumerable<T> collection, T item, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to search.

T item

The item to search for.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection does not contain the item.

| Edit this page View Source

ShouldEqual<T>(IEnumerable<T>, IEnumerable<T>, string)

Verifies that the collection is equal to the expected collection by comparing elements in order.

Declaration
public static IEnumerable<T> ShouldEqual<T>(this IEnumerable<T> actual, IEnumerable<T> expected, string message)
Parameters
Type Name Description
IEnumerable<T> actual

The actual collection.

IEnumerable<T> expected

The expected collection.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The actual collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collections.

Exceptions
Type Condition
AssertionException

Thrown when the collections are not equal.

| Edit this page View Source

ShouldHaveCount<T>(IEnumerable<T>, int, string)

Verifies that the collection has the expected count.

Declaration
public static IEnumerable<T> ShouldHaveCount<T>(this IEnumerable<T> collection, int expectedCount, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

int expectedCount

The expected count.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection does not have the expected count.

| Edit this page View Source

ShouldHaveSingleElement<T>(IEnumerable<T>, Func<T, bool>, string)

Verifies that the collection contains exactly one element that matches the predicate.

Declaration
public static T ShouldHaveSingleElement<T>(this IEnumerable<T> collection, Func<T, bool> predicate, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

Func<T, bool> predicate

The predicate to test against each element.

string message

The message to display if the assertion fails.

Returns
Type Description
T

The single matching element in the collection.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection does not contain exactly one matching element.

| Edit this page View Source

ShouldHaveSingleElement<T>(IEnumerable<T>, string)

Verifies that the collection contains exactly one element.

Declaration
public static T ShouldHaveSingleElement<T>(this IEnumerable<T> collection, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

string message

The message to display if the assertion fails.

Returns
Type Description
T

The single element in the collection.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection does not contain exactly one element.

| Edit this page View Source

ShouldHaveUniqueElements<T>(IEnumerable<T>, string)

Verifies that the collection contains only unique elements.

Declaration
public static IEnumerable<T> ShouldHaveUniqueElements<T>(this IEnumerable<T> collection, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection contains duplicate elements.

| Edit this page View Source

ShouldNotBeEmpty<T>(IEnumerable<T>, string)

Verifies that the collection is not empty.

Declaration
public static IEnumerable<T> ShouldNotBeEmpty<T>(this IEnumerable<T> collection, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to check.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection is empty.

| Edit this page View Source

ShouldNotContain<T>(IEnumerable<T>, T, string)

Verifies that the collection does not contain the specified item.

Declaration
public static IEnumerable<T> ShouldNotContain<T>(this IEnumerable<T> collection, T item, string message)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to search.

T item

The item to search for.

string message

The message to display if the assertion fails.

Returns
Type Description
IEnumerable<T>

The collection for method chaining.

Type Parameters
Name Description
T

The type of elements in the collection.

Exceptions
Type Condition
AssertionException

Thrown when the collection contains the item.

  • Edit this page
  • View Source
In this article
Back to top Copyright © www.benday.com | info@benday.com