Show / Hide Table of Contents

Class AssertThatCollection

Provides static methods for making assertions on collections with descriptive failure messages.

Inheritance
object
AssertThatCollection
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 AssertThatCollection

Methods

| Edit this page View Source

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

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

Declaration
public static void AllMatch<T>(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.

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

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

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

Declaration
public static void AnyMatch<T>(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.

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

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

Verifies that two collections are equal by comparing their elements in order.

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

The expected collection.

IEnumerable<T> actual

The actual collection.

string message

The message to display if the assertion fails.

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

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

Verifies that the collection contains the specified item.

Declaration
public static void Contains<T>(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.

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

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

Verifies that the collection does not contain the specified item.

Declaration
public static void DoesNotContain<T>(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.

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

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

Verifies that the collection has the expected count.

Declaration
public static void HasCount<T>(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.

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

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

Verifies that the collection contains only unique elements.

Declaration
public static void HasUniqueElements<T>(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.

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

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

Verifies that the collection is empty.

Declaration
public static void IsEmpty<T>(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.

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

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

Verifies that the collection is not empty.

Declaration
public static void IsNotEmpty<T>(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.

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

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

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

Declaration
public static void IsSubsetOf<T>(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.

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

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

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

Declaration
public static void IsSupersetOf<T>(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.

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
In this article
Back to top Copyright © www.benday.com | info@benday.com