Show / Hide Table of Contents

Class Assert

Contains various static methods that are used to verify that conditions are met during the process of running tests.

Inheritance
Object
Assert
Namespace: Xunit
Assembly: xunit.assert.dll
Syntax
public class Assert : object

Constructors

| Improve this Doc View Source

Assert()

Initializes a new instance of the Assert class.

Declaration
protected Assert()

Methods

| Improve this Doc View Source

All<T>(IEnumerable<T>, Action<T>)

Verifies that all items in the collection pass when executed against action.

Declaration
public static void All<T>(IEnumerable<T> collection, Action<T> action)
Parameters
Type Name Description
IEnumerable<T> collection

The collection

Action<T> action

The action to test each item against

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
AllException

Thrown when the collection contains at least one non-matching element

| Improve this Doc View Source

Collection<T>(IEnumerable<T>, Action<T>[])

Verifies that a collection contains exactly a given number of elements, which meet the criteria provided by the element inspectors.

Declaration
public static void Collection<T>(IEnumerable<T> collection, params Action<T>[] elementInspectors)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to be inspected

Action<T>[] elementInspectors

The element inspectors, which inspect each element in turn. The total number of element inspectors must exactly match the number of elements in the collection.

Type Parameters
Name Description
T

The type of the object to be verified

| Improve this Doc View Source

Contains(String, String)

Verifies that a string contains a given sub-string, using the current culture.

Declaration
public static void Contains(string expectedSubstring, string actualString)
Parameters
Type Name Description
String expectedSubstring

The sub-string expected to be in the string

String actualString

The string to be inspected

Exceptions
Type Condition
ContainsException

Thrown when the sub-string is not present inside the string

| Improve this Doc View Source

Contains(String, String, StringComparison)

Verifies that a string contains a given sub-string, using the given comparison type.

Declaration
public static void Contains(string expectedSubstring, string actualString, StringComparison comparisonType)
Parameters
Type Name Description
String expectedSubstring

The sub-string expected to be in the string

String actualString

The string to be inspected

StringComparison comparisonType

The type of string comparison to perform

Exceptions
Type Condition
ContainsException

Thrown when the sub-string is not present inside the string

| Improve this Doc View Source

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

Verifies that a collection contains a given object.

Declaration
public static void Contains<T>(T expected, IEnumerable<T> collection)
Parameters
Type Name Description
T expected

The object expected to be in the collection

IEnumerable<T> collection

The collection to be inspected

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the object is not present in the collection

| Improve this Doc View Source

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

Verifies that a collection contains a given object, using an equality comparer.

Declaration
public static void Contains<T>(T expected, IEnumerable<T> collection, IEqualityComparer<T> comparer)
Parameters
Type Name Description
T expected

The object expected to be in the collection

IEnumerable<T> collection

The collection to be inspected

IEqualityComparer<T> comparer

The comparer used to equate objects in the collection with the expected object

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the object is not present in the collection

| Improve this Doc View Source

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

Verifies that a collection contains a given object.

Declaration
public static void Contains<T>(IEnumerable<T> collection, Predicate<T> filter)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to be inspected

Predicate<T> filter

The filter used to find the item you're ensuring the collection contains

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the object is not present in the collection

| Improve this Doc View Source

Contains<TKey, TValue>(TKey, IDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

Declaration
public static TValue Contains<TKey, TValue>(TKey expected, IDictionary<TKey, TValue> collection)
Parameters
Type Name Description
TKey expected

The object expected to be in the collection.

IDictionary<TKey, TValue> collection

The collection to be inspected.

Returns
Type Description
TValue

The value associated with expected.

Type Parameters
Name Description
TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions
Type Condition
ContainsException

Thrown when the object is not present in the collection

| Improve this Doc View Source

Contains<TKey, TValue>(TKey, IReadOnlyDictionary<TKey, TValue>)

Verifies that a dictionary contains a given key.

Declaration
public static TValue Contains<TKey, TValue>(TKey expected, IReadOnlyDictionary<TKey, TValue> collection)
Parameters
Type Name Description
TKey expected

The object expected to be in the collection.

IReadOnlyDictionary<TKey, TValue> collection

The collection to be inspected.

Returns
Type Description
TValue

The value associated with expected.

Type Parameters
Name Description
TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions
Type Condition
ContainsException

Thrown when the object is not present in the collection

| Improve this Doc View Source

DoesNotContain(String, String)

Verifies that a string does not contain a given sub-string, using the current culture.

Declaration
public static void DoesNotContain(string expectedSubstring, string actualString)
Parameters
Type Name Description
String expectedSubstring

The sub-string which is expected not to be in the string

String actualString

The string to be inspected

Exceptions
Type Condition
DoesNotContainException

Thrown when the sub-string is present inside the string

| Improve this Doc View Source

DoesNotContain(String, String, StringComparison)

Verifies that a string does not contain a given sub-string, using the current culture.

Declaration
public static void DoesNotContain(string expectedSubstring, string actualString, StringComparison comparisonType)
Parameters
Type Name Description
String expectedSubstring

The sub-string which is expected not to be in the string

String actualString

The string to be inspected

StringComparison comparisonType

The type of string comparison to perform

Exceptions
Type Condition
DoesNotContainException

Thrown when the sub-string is present inside the given string

| Improve this Doc View Source

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

Verifies that a collection does not contain a given object.

Declaration
public static void DoesNotContain<T>(T expected, IEnumerable<T> collection)
Parameters
Type Name Description
T expected

The object that is expected not to be in the collection

IEnumerable<T> collection

The collection to be inspected

Type Parameters
Name Description
T

The type of the object to be compared

Exceptions
Type Condition
DoesNotContainException

Thrown when the object is present inside the container

| Improve this Doc View Source

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

Verifies that a collection does not contain a given object, using an equality comparer.

Declaration
public static void DoesNotContain<T>(T expected, IEnumerable<T> collection, IEqualityComparer<T> comparer)
Parameters
Type Name Description
T expected

The object that is expected not to be in the collection

IEnumerable<T> collection

The collection to be inspected

IEqualityComparer<T> comparer

The comparer used to equate objects in the collection with the expected object

Type Parameters
Name Description
T

The type of the object to be compared

Exceptions
Type Condition
DoesNotContainException

Thrown when the object is present inside the container

| Improve this Doc View Source

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

Verifies that a collection does not contain a given object.

Declaration
public static void DoesNotContain<T>(IEnumerable<T> collection, Predicate<T> filter)
Parameters
Type Name Description
IEnumerable<T> collection

The collection to be inspected

Predicate<T> filter

The filter used to find the item you're ensuring the collection does not contain

Type Parameters
Name Description
T

The type of the object to be compared

Exceptions
Type Condition
DoesNotContainException

Thrown when the object is present inside the container

| Improve this Doc View Source

DoesNotContain<TKey, TValue>(TKey, IDictionary<TKey, TValue>)

Verifies that a dictionary does not contain a given key.

Declaration
public static void DoesNotContain<TKey, TValue>(TKey expected, IDictionary<TKey, TValue> collection)
Parameters
Type Name Description
TKey expected

The object expected to be in the collection.

IDictionary<TKey, TValue> collection

The collection to be inspected.

Type Parameters
Name Description
TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions
Type Condition
DoesNotContainException

Thrown when the object is present in the collection

| Improve this Doc View Source

DoesNotContain<TKey, TValue>(TKey, IReadOnlyDictionary<TKey, TValue>)

Verifies that a dictionary does not contain a given key.

Declaration
public static void DoesNotContain<TKey, TValue>(TKey expected, IReadOnlyDictionary<TKey, TValue> collection)
Parameters
Type Name Description
TKey expected

The object expected to be in the collection.

IReadOnlyDictionary<TKey, TValue> collection

The collection to be inspected.

Type Parameters
Name Description
TKey

The type of the keys of the object to be verified.

TValue

The type of the values of the object to be verified.

Exceptions
Type Condition
DoesNotContainException

Thrown when the object is present in the collection

| Improve this Doc View Source

DoesNotMatch(Regex, String)

Verifies that a string does not match a regular expression.

Declaration
public static void DoesNotMatch(Regex expectedRegex, string actualString)
Parameters
Type Name Description
Regex expectedRegex

The regex expected not to match

String actualString

The string to be inspected

Exceptions
Type Condition
DoesNotMatchException

Thrown when the string matches the regex

| Improve this Doc View Source

DoesNotMatch(String, String)

Verifies that a string does not match a regular expression.

Declaration
public static void DoesNotMatch(string expectedRegexPattern, string actualString)
Parameters
Type Name Description
String expectedRegexPattern

The regex pattern expected not to match

String actualString

The string to be inspected

Exceptions
Type Condition
DoesNotMatchException

Thrown when the string matches the regex pattern

| Improve this Doc View Source

Empty(IEnumerable)

Verifies that a collection is empty.

Declaration
public static void Empty(IEnumerable collection)
Parameters
Type Name Description
IEnumerable collection

The collection to be inspected

Exceptions
Type Condition
EmptyException

Thrown when the collection is not empty

| Improve this Doc View Source

EndsWith(String, String)

Verifies that a string ends with a given string, using the current culture.

Declaration
public static void EndsWith(string expectedEndString, string actualString)
Parameters
Type Name Description
String expectedEndString

The string expected to be at the end of the string

String actualString

The string to be inspected

Exceptions
Type Condition
ContainsException

Thrown when the string does not end with the expected string

| Improve this Doc View Source

EndsWith(String, String, StringComparison)

Verifies that a string ends with a given string, using the given comparison type.

Declaration
public static void EndsWith(string expectedEndString, string actualString, StringComparison comparisonType)
Parameters
Type Name Description
String expectedEndString

The string expected to be at the end of the string

String actualString

The string to be inspected

StringComparison comparisonType

The type of string comparison to perform

Exceptions
Type Condition
ContainsException

Thrown when the string does not end with the expected string

| Improve this Doc View Source

Equal(DateTime, DateTime, TimeSpan)

Verifies that two values are equal, within the precision given by precision.

Declaration
public static void Equal(DateTime expected, DateTime actual, TimeSpan precision)
Parameters
Type Name Description
DateTime expected

The expected value

DateTime actual

The value to be compared against

TimeSpan precision

The allowed difference in time where the two dates are considered equal

Exceptions
Type Condition
EqualException

Thrown when the values are not equal

| Improve this Doc View Source

Equal(Decimal, Decimal, Int32)

Verifies that two values are equal, within the number of decimal places given by precision. The values are rounded before comparison.

Declaration
public static void Equal(decimal expected, decimal actual, int precision)
Parameters
Type Name Description
Decimal expected

The expected value

Decimal actual

The value to be compared against

Int32 precision

The number of decimal places (valid values: 0-28)

Exceptions
Type Condition
EqualException

Thrown when the values are not equal

| Improve this Doc View Source

Equal(Double, Double, Int32)

Verifies that two values are equal, within the number of decimal places given by precision. The values are rounded before comparison.

Declaration
public static void Equal(double expected, double actual, int precision)
Parameters
Type Name Description
Double expected

The expected value

Double actual

The value to be compared against

Int32 precision

The number of decimal places (valid values: 0-15)

Exceptions
Type Condition
EqualException

Thrown when the values are not equal

| Improve this Doc View Source

Equal(String, String)

Verifies that two strings are equivalent.

Declaration
public static void Equal(string expected, string actual)
Parameters
Type Name Description
String expected

The expected string value.

String actual

The actual string value.

Exceptions
Type Condition
EqualException

Thrown when the strings are not equivalent.

| Improve this Doc View Source

Equal(String, String, Boolean, Boolean, Boolean)

Verifies that two strings are equivalent.

Declaration
public static void Equal(string expected, string actual, bool ignoreCase = false, bool ignoreLineEndingDifferences = false, bool ignoreWhiteSpaceDifferences = false)
Parameters
Type Name Description
String expected

The expected string value.

String actual

The actual string value.

Boolean ignoreCase

If set to true, ignores cases differences. The invariant culture is used.

Boolean ignoreLineEndingDifferences

If set to true, treats \r\n, \r, and \n as equivalent.

Boolean ignoreWhiteSpaceDifferences

If set to true, treats spaces and tabs (in any non-zero quantity) as equivalent.

Exceptions
Type Condition
EqualException

Thrown when the strings are not equivalent.

| Improve this Doc View Source

Equal<T>(T, T)

Verifies that two objects are equal, using a default comparer.

Declaration
public static void Equal<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The expected value

T actual

The value to be compared against

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
EqualException

Thrown when the objects are not equal

| Improve this Doc View Source

Equal<T>(T, T, IEqualityComparer<T>)

Verifies that two objects are equal, using a custom equatable comparer.

Declaration
public static void Equal<T>(T expected, T actual, IEqualityComparer<T> comparer)
Parameters
Type Name Description
T expected

The expected value

T actual

The value to be compared against

IEqualityComparer<T> comparer

The comparer used to compare the two objects

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
EqualException

Thrown when the objects are not equal

| Improve this Doc View Source

Equal<T>(IEnumerable<T>, IEnumerable<T>)

Verifies that two sequences are equivalent, using a default comparer.

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

The expected value

IEnumerable<T> actual

The value to be compared against

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
EqualException

Thrown when the objects are not equal

| Improve this Doc View Source

Equal<T>(IEnumerable<T>, IEnumerable<T>, IEqualityComparer<T>)

Verifies that two sequences are equivalent, using a custom equatable comparer.

Declaration
public static void Equal<T>(IEnumerable<T> expected, IEnumerable<T> actual, IEqualityComparer<T> comparer)
Parameters
Type Name Description
IEnumerable<T> expected

The expected value

IEnumerable<T> actual

The value to be compared against

IEqualityComparer<T> comparer

The comparer used to compare the two objects

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
EqualException

Thrown when the objects are not equal

| Improve this Doc View Source

Equals(Object, Object)

Do not call this method.

Declaration
public static bool Equals(object a, object b)
Parameters
Type Name Description
Object a
Object b
Returns
Type Description
Boolean
| Improve this Doc View Source

False(Boolean)

Verifies that the condition is false.

Declaration
public static void False(bool condition)
Parameters
Type Name Description
Boolean condition

The condition to be tested

Exceptions
Type Condition
FalseException

Thrown if the condition is not false

| Improve this Doc View Source

False(Boolean, String)

Verifies that the condition is false.

Declaration
public static void False(bool condition, string userMessage)
Parameters
Type Name Description
Boolean condition

The condition to be tested

String userMessage

The message to show when the condition is not false

Exceptions
Type Condition
FalseException

Thrown if the condition is not false

| Improve this Doc View Source

False(Nullable<Boolean>)

Verifies that the condition is false.

Declaration
public static void False(bool? condition)
Parameters
Type Name Description
Nullable<Boolean> condition

The condition to be tested

Exceptions
Type Condition
FalseException

Thrown if the condition is not false

| Improve this Doc View Source

False(Nullable<Boolean>, String)

Verifies that the condition is false.

Declaration
public static void False(bool? condition, string userMessage)
Parameters
Type Name Description
Nullable<Boolean> condition

The condition to be tested

String userMessage

The message to show when the condition is not false

Exceptions
Type Condition
FalseException

Thrown if the condition is not false

| Improve this Doc View Source

InRange<T>(T, T, T)

Verifies that a value is within a given range.

Declaration
public static void InRange<T>(T actual, T low, T high)

    where T : IComparable
Parameters
Type Name Description
T actual

The actual value to be evaluated

T low

The (inclusive) low value of the range

T high

The (inclusive) high value of the range

Type Parameters
Name Description
T

The type of the value to be compared

Exceptions
Type Condition
InRangeException

Thrown when the value is not in the given range

| Improve this Doc View Source

InRange<T>(T, T, T, IComparer<T>)

Verifies that a value is within a given range, using a comparer.

Declaration
public static void InRange<T>(T actual, T low, T high, IComparer<T> comparer)
Parameters
Type Name Description
T actual

The actual value to be evaluated

T low

The (inclusive) low value of the range

T high

The (inclusive) high value of the range

IComparer<T> comparer

The comparer used to evaluate the value's range

Type Parameters
Name Description
T

The type of the value to be compared

Exceptions
Type Condition
InRangeException

Thrown when the value is not in the given range

| Improve this Doc View Source

IsAssignableFrom(Type, Object)

Verifies that an object is of the given type or a derived type.

Declaration
public static void IsAssignableFrom(Type expectedType, object object)
Parameters
Type Name Description
Type expectedType

The type the object should be

Object object

The object to be evaluated

Exceptions
Type Condition
IsAssignableFromException

Thrown when the object is not the given type

| Improve this Doc View Source

IsAssignableFrom<T>(Object)

Verifies that an object is of the given type or a derived type.

Declaration
public static T IsAssignableFrom<T>(object object)
Parameters
Type Name Description
Object object

The object to be evaluated

Returns
Type Description
T

The object, casted to type T when successful

Type Parameters
Name Description
T

The type the object should be

Exceptions
Type Condition
IsAssignableFromException

Thrown when the object is not the given type

| Improve this Doc View Source

IsNotType(Type, Object)

Verifies that an object is not exactly the given type.

Declaration
public static void IsNotType(Type expectedType, object object)
Parameters
Type Name Description
Type expectedType

The type the object should not be

Object object

The object to be evaluated

Exceptions
Type Condition
IsNotTypeException

Thrown when the object is the given type

| Improve this Doc View Source

IsNotType<T>(Object)

Verifies that an object is not exactly the given type.

Declaration
public static void IsNotType<T>(object object)
Parameters
Type Name Description
Object object

The object to be evaluated

Type Parameters
Name Description
T

The type the object should not be

Exceptions
Type Condition
IsNotTypeException

Thrown when the object is the given type

| Improve this Doc View Source

IsType(Type, Object)

Verifies that an object is exactly the given type (and not a derived type).

Declaration
public static void IsType(Type expectedType, object object)
Parameters
Type Name Description
Type expectedType

The type the object should be

Object object

The object to be evaluated

Exceptions
Type Condition
IsTypeException

Thrown when the object is not the given type

| Improve this Doc View Source

IsType<T>(Object)

Verifies that an object is exactly the given type (and not a derived type).

Declaration
public static T IsType<T>(object object)
Parameters
Type Name Description
Object object

The object to be evaluated

Returns
Type Description
T

The object, casted to type T when successful

Type Parameters
Name Description
T

The type the object should be

Exceptions
Type Condition
IsTypeException

Thrown when the object is not the given type

| Improve this Doc View Source

Matches(Regex, String)

Verifies that a string matches a regular expression.

Declaration
public static void Matches(Regex expectedRegex, string actualString)
Parameters
Type Name Description
Regex expectedRegex

The regex expected to match

String actualString

The string to be inspected

Exceptions
Type Condition
MatchesException

Thrown when the string does not match the regex

| Improve this Doc View Source

Matches(String, String)

Verifies that a string matches a regular expression.

Declaration
public static void Matches(string expectedRegexPattern, string actualString)
Parameters
Type Name Description
String expectedRegexPattern

The regex pattern expected to match

String actualString

The string to be inspected

Exceptions
Type Condition
MatchesException

Thrown when the string does not match the regex pattern

| Improve this Doc View Source

NotEmpty(IEnumerable)

Verifies that a collection is not empty.

Declaration
public static void NotEmpty(IEnumerable collection)
Parameters
Type Name Description
IEnumerable collection

The collection to be inspected

Exceptions
Type Condition
NotEmptyException

Thrown when the collection is empty

| Improve this Doc View Source

NotEqual(Decimal, Decimal, Int32)

Verifies that two values are not equal, within the number of decimal places given by precision.

Declaration
public static void NotEqual(decimal expected, decimal actual, int precision)
Parameters
Type Name Description
Decimal expected

The expected value

Decimal actual

The value to be compared against

Int32 precision

The number of decimal places (valid values: 0-28)

Exceptions
Type Condition
EqualException

Thrown when the values are equal

| Improve this Doc View Source

NotEqual(Double, Double, Int32)

Verifies that two values are not equal, within the number of decimal places given by precision.

Declaration
public static void NotEqual(double expected, double actual, int precision)
Parameters
Type Name Description
Double expected

The expected value

Double actual

The value to be compared against

Int32 precision

The number of decimal places (valid values: 0-15)

Exceptions
Type Condition
EqualException

Thrown when the values are equal

| Improve this Doc View Source

NotEqual<T>(T, T)

Verifies that two objects are not equal, using a default comparer.

Declaration
public static void NotEqual<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The expected object

T actual

The actual object

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
NotEqualException

Thrown when the objects are equal

| Improve this Doc View Source

NotEqual<T>(T, T, IEqualityComparer<T>)

Verifies that two objects are not equal, using a custom equality comparer.

Declaration
public static void NotEqual<T>(T expected, T actual, IEqualityComparer<T> comparer)
Parameters
Type Name Description
T expected

The expected object

T actual

The actual object

IEqualityComparer<T> comparer

The comparer used to examine the objects

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
NotEqualException

Thrown when the objects are equal

| Improve this Doc View Source

NotEqual<T>(IEnumerable<T>, IEnumerable<T>)

Verifies that two sequences are not equivalent, using a default comparer.

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

The expected object

IEnumerable<T> actual

The actual object

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
NotEqualException

Thrown when the objects are equal

| Improve this Doc View Source

NotEqual<T>(IEnumerable<T>, IEnumerable<T>, IEqualityComparer<T>)

Verifies that two sequences are not equivalent, using a custom equality comparer.

Declaration
public static void NotEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual, IEqualityComparer<T> comparer)
Parameters
Type Name Description
IEnumerable<T> expected

The expected object

IEnumerable<T> actual

The actual object

IEqualityComparer<T> comparer

The comparer used to compare the two objects

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
NotEqualException

Thrown when the objects are equal

| Improve this Doc View Source

NotInRange<T>(T, T, T)

Verifies that a value is not within a given range, using the default comparer.

Declaration
public static void NotInRange<T>(T actual, T low, T high)

    where T : IComparable
Parameters
Type Name Description
T actual

The actual value to be evaluated

T low

The (inclusive) low value of the range

T high

The (inclusive) high value of the range

Type Parameters
Name Description
T

The type of the value to be compared

Exceptions
Type Condition
NotInRangeException

Thrown when the value is in the given range

| Improve this Doc View Source

NotInRange<T>(T, T, T, IComparer<T>)

Verifies that a value is not within a given range, using a comparer.

Declaration
public static void NotInRange<T>(T actual, T low, T high, IComparer<T> comparer)
Parameters
Type Name Description
T actual

The actual value to be evaluated

T low

The (inclusive) low value of the range

T high

The (inclusive) high value of the range

IComparer<T> comparer

The comparer used to evaluate the value's range

Type Parameters
Name Description
T

The type of the value to be compared

Exceptions
Type Condition
NotInRangeException

Thrown when the value is in the given range

| Improve this Doc View Source

NotNull(Object)

Verifies that an object reference is not null.

Declaration
public static void NotNull(object object)
Parameters
Type Name Description
Object object

The object to be validated

Exceptions
Type Condition
NotNullException

Thrown when the object is not null

| Improve this Doc View Source

NotSame(Object, Object)

Verifies that two objects are not the same instance.

Declaration
public static void NotSame(object expected, object actual)
Parameters
Type Name Description
Object expected

The expected object instance

Object actual

The actual object instance

Exceptions
Type Condition
NotSameException

Thrown when the objects are the same instance

| Improve this Doc View Source

NotStrictEqual<T>(T, T)

Verifies that two objects are strictly not equal, using the type's default comparer.

Declaration
public static void NotStrictEqual<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The expected object

T actual

The actual object

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
NotEqualException

Thrown when the objects are equal

| Improve this Doc View Source

Null(Object)

Verifies that an object reference is null.

Declaration
public static void Null(object object)
Parameters
Type Name Description
Object object

The object to be inspected

Exceptions
Type Condition
NullException

Thrown when the object reference is not null

| Improve this Doc View Source

ProperSubset<T>(ISet<T>, ISet<T>)

Verifies that a set is a proper subset of another set.

Declaration
public static void ProperSubset<T>(ISet<T> expectedSuperset, ISet<T> actual)
Parameters
Type Name Description
ISet<T> expectedSuperset

The expected superset

ISet<T> actual

The set expected to be a proper subset

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the actual set is not a proper subset of the expected set

| Improve this Doc View Source

ProperSuperset<T>(ISet<T>, ISet<T>)

Verifies that a set is a proper superset of another set.

Declaration
public static void ProperSuperset<T>(ISet<T> expectedSubset, ISet<T> actual)
Parameters
Type Name Description
ISet<T> expectedSubset

The expected subset

ISet<T> actual

The set expected to be a proper superset

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the actual set is not a proper superset of the expected set

| Improve this Doc View Source

PropertyChanged(INotifyPropertyChanged, String, Action)

Verifies that the provided object raised as a result of executing the given test code.

Declaration
public static void PropertyChanged(INotifyPropertyChanged object, string propertyName, Action testCode)
Parameters
Type Name Description
INotifyPropertyChanged object

The object which should raise the notification

String propertyName

The property name for which the notification should be raised

Action testCode

The test code which should cause the notification to be raised

Exceptions
Type Condition
PropertyChangedException

Thrown when the notification is not raised

| Improve this Doc View Source

PropertyChanged(INotifyPropertyChanged, String, Func<Task>)

Declaration
public static void PropertyChanged(INotifyPropertyChanged object, string propertyName, Func<Task> testCode)
Parameters
Type Name Description
INotifyPropertyChanged object
String propertyName
Func<Task> testCode
| Improve this Doc View Source

PropertyChangedAsync(INotifyPropertyChanged, String, Func<Task>)

Verifies that the provided object raised as a result of executing the given test code.

Declaration
public static Task PropertyChangedAsync(INotifyPropertyChanged object, string propertyName, Func<Task> testCode)
Parameters
Type Name Description
INotifyPropertyChanged object

The object which should raise the notification

String propertyName

The property name for which the notification should be raised

Func<Task> testCode

The test code which should cause the notification to be raised

Returns
Type Description
Task
Exceptions
Type Condition
PropertyChangedException

Thrown when the notification is not raised

| Improve this Doc View Source

Raises<T>(Action<EventHandler<T>>, Action<EventHandler<T>>, Action)

Verifies that a event with the exact event args is raised.

Declaration
public static Assert.RaisedEvent<T> Raises<T>(Action<EventHandler<T>> attach, Action<EventHandler<T>> detach, Action testCode)

    where T : EventArgs
Parameters
Type Name Description
Action<EventHandler<T>> attach

Code to attach the event handler

Action<EventHandler<T>> detach

Code to detach the event handler

Action testCode

A delegate to the code to be tested

Returns
Type Description
Assert.RaisedEvent<T>

The event sender and arguments wrapped in an object

Type Parameters
Name Description
T

The type of the event arguments to expect

Exceptions
Type Condition
RaisesException

Thrown when the expected event was not raised.

| Improve this Doc View Source

RaisesAny<T>(Action<EventHandler<T>>, Action<EventHandler<T>>, Action)

Verifies that an event with the exact or a derived event args is raised.

Declaration
public static Assert.RaisedEvent<T> RaisesAny<T>(Action<EventHandler<T>> attach, Action<EventHandler<T>> detach, Action testCode)

    where T : EventArgs
Parameters
Type Name Description
Action<EventHandler<T>> attach

Code to attach the event handler

Action<EventHandler<T>> detach

Code to detach the event handler

Action testCode

A delegate to the code to be tested

Returns
Type Description
Assert.RaisedEvent<T>

The event sender and arguments wrapped in an object

Type Parameters
Name Description
T

The type of the event arguments to expect

Exceptions
Type Condition
RaisesException

Thrown when the expected event was not raised.

| Improve this Doc View Source

RaisesAnyAsync<T>(Action<EventHandler<T>>, Action<EventHandler<T>>, Func<Task>)

Verifies that an event with the exact or a derived event args is raised.

Declaration
public static Task<Assert.RaisedEvent<T>> RaisesAnyAsync<T>(Action<EventHandler<T>> attach, Action<EventHandler<T>> detach, Func<Task> testCode)

    where T : EventArgs
Parameters
Type Name Description
Action<EventHandler<T>> attach

Code to attach the event handler

Action<EventHandler<T>> detach

Code to detach the event handler

Func<Task> testCode

A delegate to the code to be tested

Returns
Type Description
Task<Assert.RaisedEvent<T>>

The event sender and arguments wrapped in an object

Type Parameters
Name Description
T

The type of the event arguments to expect

Exceptions
Type Condition
RaisesException

Thrown when the expected event was not raised.

| Improve this Doc View Source

RaisesAsync<T>(Action<EventHandler<T>>, Action<EventHandler<T>>, Func<Task>)

Verifies that a event with the exact event args (and not a derived type) is raised.

Declaration
public static Task<Assert.RaisedEvent<T>> RaisesAsync<T>(Action<EventHandler<T>> attach, Action<EventHandler<T>> detach, Func<Task> testCode)

    where T : EventArgs
Parameters
Type Name Description
Action<EventHandler<T>> attach

Code to attach the event handler

Action<EventHandler<T>> detach

Code to detach the event handler

Func<Task> testCode

A delegate to the code to be tested

Returns
Type Description
Task<Assert.RaisedEvent<T>>

The event sender and arguments wrapped in an object

Type Parameters
Name Description
T

The type of the event arguments to expect

Exceptions
Type Condition
RaisesException

Thrown when the expected event was not raised.

| Improve this Doc View Source

RecordException(Action)

Records any exception which is thrown by the given code.

Declaration
protected static Exception RecordException(Action testCode)
Parameters
Type Name Description
Action testCode

The code which may thrown an exception.

Returns
Type Description
Exception

Returns the exception that was thrown by the code; null, otherwise.

| Improve this Doc View Source

RecordException(Func<Object>)

Records any exception which is thrown by the given code that has a return value. Generally used for testing property accessors.

Declaration
protected static Exception RecordException(Func<object> testCode)
Parameters
Type Name Description
Func<Object> testCode

The code which may thrown an exception.

Returns
Type Description
Exception

Returns the exception that was thrown by the code; null, otherwise.

| Improve this Doc View Source

RecordException(Func<Task>)

Declaration
protected static Exception RecordException(Func<Task> testCode)
Parameters
Type Name Description
Func<Task> testCode
Returns
Type Description
Exception
| Improve this Doc View Source

RecordExceptionAsync(Func<Task>)

Records any exception which is thrown by the given task.

Declaration
protected static Task<Exception> RecordExceptionAsync(Func<Task> testCode)
Parameters
Type Name Description
Func<Task> testCode

The task which may thrown an exception.

Returns
Type Description
Task<Exception>

Returns the exception that was thrown by the code; null, otherwise.

| Improve this Doc View Source

ReferenceEquals(Object, Object)

Do not call this method.

Declaration
public static bool ReferenceEquals(object a, object b)
Parameters
Type Name Description
Object a
Object b
Returns
Type Description
Boolean
| Improve this Doc View Source

Same(Object, Object)

Verifies that two objects are the same instance.

Declaration
public static void Same(object expected, object actual)
Parameters
Type Name Description
Object expected

The expected object instance

Object actual

The actual object instance

Exceptions
Type Condition
SameException

Thrown when the objects are not the same instance

| Improve this Doc View Source

Single(IEnumerable)

Verifies that the given collection contains only a single element of the given type.

Declaration
public static object Single(IEnumerable collection)
Parameters
Type Name Description
IEnumerable collection

The collection.

Returns
Type Description
Object

The single item in the collection.

Exceptions
Type Condition
SingleException

Thrown when the collection does not contain exactly one element.

| Improve this Doc View Source

Single(IEnumerable, Object)

Verifies that the given collection contains only a single element of the given value. The collection may or may not contain other values.

Declaration
public static void Single(IEnumerable collection, object expected)
Parameters
Type Name Description
IEnumerable collection

The collection.

Object expected

The value to find in the collection.

Exceptions
Type Condition
SingleException

Thrown when the collection does not contain exactly one element.

| Improve this Doc View Source

Single<T>(IEnumerable<T>)

Verifies that the given collection contains only a single element of the given type.

Declaration
public static T Single<T>(IEnumerable<T> collection)
Parameters
Type Name Description
IEnumerable<T> collection

The collection.

Returns
Type Description
T

The single item in the collection.

Type Parameters
Name Description
T

The collection type.

Exceptions
Type Condition
SingleException

Thrown when the collection does not contain exactly one element.

| Improve this Doc View Source

Single<T>(IEnumerable<T>, Predicate<T>)

Verifies that the given collection contains only a single element of the given type which matches the given predicate. The collection may or may not contain other values which do not match the given predicate.

Declaration
public static T Single<T>(IEnumerable<T> collection, Predicate<T> predicate)
Parameters
Type Name Description
IEnumerable<T> collection

The collection.

Predicate<T> predicate

The item matching predicate.

Returns
Type Description
T

The single item in the filtered collection.

Type Parameters
Name Description
T

The collection type.

Exceptions
Type Condition
SingleException

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

| Improve this Doc View Source

StartsWith(String, String)

Verifies that a string starts with a given string, using the current culture.

Declaration
public static void StartsWith(string expectedStartString, string actualString)
Parameters
Type Name Description
String expectedStartString

The string expected to be at the start of the string

String actualString

The string to be inspected

Exceptions
Type Condition
ContainsException

Thrown when the string does not start with the expected string

| Improve this Doc View Source

StartsWith(String, String, StringComparison)

Verifies that a string starts with a given string, using the given comparison type.

Declaration
public static void StartsWith(string expectedStartString, string actualString, StringComparison comparisonType)
Parameters
Type Name Description
String expectedStartString

The string expected to be at the start of the string

String actualString

The string to be inspected

StringComparison comparisonType

The type of string comparison to perform

Exceptions
Type Condition
ContainsException

Thrown when the string does not start with the expected string

| Improve this Doc View Source

StrictEqual<T>(T, T)

Verifies that two objects are strictly equal, using the type's default comparer.

Declaration
public static void StrictEqual<T>(T expected, T actual)
Parameters
Type Name Description
T expected

The expected value

T actual

The value to be compared against

Type Parameters
Name Description
T

The type of the objects to be compared

Exceptions
Type Condition
EqualException

Thrown when the objects are not equal

| Improve this Doc View Source

Subset<T>(ISet<T>, ISet<T>)

Verifies that a set is a subset of another set.

Declaration
public static void Subset<T>(ISet<T> expectedSuperset, ISet<T> actual)
Parameters
Type Name Description
ISet<T> expectedSuperset

The expected superset

ISet<T> actual

The set expected to be a subset

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the actual set is not a subset of the expected set

| Improve this Doc View Source

Superset<T>(ISet<T>, ISet<T>)

Verifies that a set is a superset of another set.

Declaration
public static void Superset<T>(ISet<T> expectedSubset, ISet<T> actual)
Parameters
Type Name Description
ISet<T> expectedSubset

The expected subset

ISet<T> actual

The set expected to be a superset

Type Parameters
Name Description
T

The type of the object to be verified

Exceptions
Type Condition
ContainsException

Thrown when the actual set is not a superset of the expected set

| Improve this Doc View Source

Throws(Type, Action)

Verifies that the exact exception is thrown (and not a derived exception type).

Declaration
public static Exception Throws(Type exceptionType, Action testCode)
Parameters
Type Name Description
Type exceptionType

The type of the exception expected to be thrown

Action testCode

A delegate to the code to be tested

Returns
Type Description
Exception

The exception that was thrown, when successful

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws(Type, Func<Object>)

Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.

Declaration
public static Exception Throws(Type exceptionType, Func<object> testCode)
Parameters
Type Name Description
Type exceptionType

The type of the exception expected to be thrown

Func<Object> testCode

A delegate to the code to be tested

Returns
Type Description
Exception

The exception that was thrown, when successful

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws<T>(Action)

Verifies that the exact exception is thrown (and not a derived exception type).

Declaration
public static T Throws<T>(Action testCode)

    where T : Exception
Parameters
Type Name Description
Action testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws<T>(Func<Object>)

Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors.

Declaration
public static T Throws<T>(Func<object> testCode)

    where T : Exception
Parameters
Type Name Description
Func<Object> testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws<T>(Func<Task>)

Declaration
public static T Throws<T>(Func<Task> testCode)

    where T : Exception
Parameters
Type Name Description
Func<Task> testCode
Returns
Type Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source

Throws<T>(String, Action)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from and has the given parameter name.

Declaration
public static T Throws<T>(string paramName, Action testCode)

    where T : ArgumentException
Parameters
Type Name Description
String paramName

The parameter name that is expected to be in the exception

Action testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T
Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws<T>(String, Func<Object>)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from and has the given parameter name.

Declaration
public static T Throws<T>(string paramName, Func<object> testCode)

    where T : ArgumentException
Parameters
Type Name Description
String paramName

The parameter name that is expected to be in the exception

Func<Object> testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T
Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

Throws<T>(String, Func<Task>)

Declaration
public static T Throws<T>(string paramName, Func<Task> testCode)

    where T : ArgumentException
Parameters
Type Name Description
String paramName
Func<Task> testCode
Returns
Type Description
T
Type Parameters
Name Description
T
| Improve this Doc View Source

ThrowsAny<T>(Action)

Verifies that the exact exception or a derived exception type is thrown.

Declaration
public static T ThrowsAny<T>(Action testCode)

    where T : Exception
Parameters
Type Name Description
Action testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

ThrowsAny<T>(Func<Object>)

Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors.

Declaration
public static T ThrowsAny<T>(Func<object> testCode)

    where T : Exception
Parameters
Type Name Description
Func<Object> testCode

A delegate to the code to be tested

Returns
Type Description
T

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

ThrowsAnyAsync<T>(Func<Task>)

Verifies that the exact exception or a derived exception type is thrown.

Declaration
public static Task<T> ThrowsAnyAsync<T>(Func<Task> testCode)

    where T : Exception
Parameters
Type Name Description
Func<Task> testCode

A delegate to the task to be tested

Returns
Type Description
Task<T>

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

ThrowsAsync(Type, Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

Declaration
public static Task<Exception> ThrowsAsync(Type exceptionType, Func<Task> testCode)
Parameters
Type Name Description
Type exceptionType

The type of the exception expected to be thrown

Func<Task> testCode

A delegate to the task to be tested

Returns
Type Description
Task<Exception>

The exception that was thrown, when successful

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

ThrowsAsync<T>(Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type).

Declaration
public static Task<T> ThrowsAsync<T>(Func<Task> testCode)

    where T : Exception
Parameters
Type Name Description
Func<Task> testCode

A delegate to the task to be tested

Returns
Type Description
Task<T>

The exception that was thrown, when successful

Type Parameters
Name Description
T

The type of the exception expected to be thrown

Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

ThrowsAsync<T>(String, Func<Task>)

Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from and has the given parameter name.

Declaration
public static Task<T> ThrowsAsync<T>(string paramName, Func<Task> testCode)

    where T : ArgumentException
Parameters
Type Name Description
String paramName

The parameter name that is expected to be in the exception

Func<Task> testCode

A delegate to the task to be tested

Returns
Type Description
Task<T>

The exception that was thrown, when successful

Type Parameters
Name Description
T
Exceptions
Type Condition
ThrowsException

Thrown when an exception was not thrown, or when an exception of the incorrect type is thrown

| Improve this Doc View Source

True(Boolean)

Verifies that an expression is true.

Declaration
public static void True(bool condition)
Parameters
Type Name Description
Boolean condition

The condition to be inspected

Exceptions
Type Condition
TrueException

Thrown when the condition is false

| Improve this Doc View Source

True(Boolean, String)

Verifies that an expression is true.

Declaration
public static void True(bool condition, string userMessage)
Parameters
Type Name Description
Boolean condition

The condition to be inspected

String userMessage

The message to be shown when the condition is false

Exceptions
Type Condition
TrueException

Thrown when the condition is false

| Improve this Doc View Source

True(Nullable<Boolean>)

Verifies that an expression is true.

Declaration
public static void True(bool? condition)
Parameters
Type Name Description
Nullable<Boolean> condition

The condition to be inspected

Exceptions
Type Condition
TrueException

Thrown when the condition is false

| Improve this Doc View Source

True(Nullable<Boolean>, String)

Verifies that an expression is true.

Declaration
public static void True(bool? condition, string userMessage)
Parameters
Type Name Description
Nullable<Boolean> condition

The condition to be inspected

String userMessage

The message to be shown when the condition is false

Exceptions
Type Condition
TrueException

Thrown when the condition is false

  • Improve this Doc
  • View Source
Back to top Generated by DocFX