xUnit.net
Classes | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
Xunit.Assert Class Reference

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

Classes

class  RaisedEvent
 Represents a raised event after the fact. More...
 

Static Public Member Functions

static new bool Equals (object a, object b)
 Do not call this method. More...
 
static new bool ReferenceEquals (object a, object b)
 Do not call this method. More...
 
static void False (bool condition)
 Verifies that the condition is false. More...
 
static void False (bool? condition)
 Verifies that the condition is false. More...
 
static void False (bool condition, string userMessage)
 Verifies that the condition is false. More...
 
static void False (bool? condition, string userMessage)
 Verifies that the condition is false. More...
 
static void True (bool condition)
 Verifies that an expression is true. More...
 
static void True (bool? condition)
 Verifies that an expression is true. More...
 
static void True (bool condition, string userMessage)
 Verifies that an expression is true. More...
 
static void True (bool? condition, string userMessage)
 Verifies that an expression is true. More...
 
static void All< T > (IEnumerable< T > collection, Action< T > action)
 Verifies that all items in the collection pass when executed against action. More...
 
static void Collection< T > (IEnumerable< T > collection, params Action< T >[] elementInspectors)
 Verifies that a collection contains exactly a given number of elements, which meet the criteria provided by the element inspectors. More...
 
static void Contains< T > (T expected, IEnumerable< T > collection)
 Verifies that a collection contains a given object. More...
 
static void Contains< T > (T expected, IEnumerable< T > collection, IEqualityComparer< T > comparer)
 Verifies that a collection contains a given object, using an equality comparer. More...
 
static void Contains< T > (IEnumerable< T > collection, Predicate< T > filter)
 Verifies that a collection contains a given object. More...
 
static TValue Contains< TKey, TValue > (TKey expected, IReadOnlyDictionary< TKey, TValue > collection)
 Verifies that a dictionary contains a given key. More...
 
static TValue Contains< TKey, TValue > (TKey expected, IDictionary< TKey, TValue > collection)
 Verifies that a dictionary contains a given key. More...
 
static void DoesNotContain< T > (T expected, IEnumerable< T > collection)
 Verifies that a collection does not contain a given object. More...
 
static void DoesNotContain< T > (T expected, IEnumerable< T > collection, IEqualityComparer< T > comparer)
 Verifies that a collection does not contain a given object, using an equality comparer. More...
 
static void DoesNotContain< T > (IEnumerable< T > collection, Predicate< T > filter)
 Verifies that a collection does not contain a given object. More...
 
static void DoesNotContain< TKey, TValue > (TKey expected, IReadOnlyDictionary< TKey, TValue > collection)
 Verifies that a dictionary does not contain a given key. More...
 
static void DoesNotContain< TKey, TValue > (TKey expected, IDictionary< TKey, TValue > collection)
 Verifies that a dictionary does not contain a given key. More...
 
static void Empty (IEnumerable collection)
 Verifies that a collection is empty. More...
 
static void Equal< T > (IEnumerable< T > expected, IEnumerable< T > actual)
 Verifies that two sequences are equivalent, using a default comparer. More...
 
static void Equal< T > (IEnumerable< T > expected, IEnumerable< T > actual, IEqualityComparer< T > comparer)
 Verifies that two sequences are equivalent, using a custom equatable comparer. More...
 
static void NotEmpty (IEnumerable collection)
 Verifies that a collection is not empty. More...
 
static void NotEqual< T > (IEnumerable< T > expected, IEnumerable< T > actual)
 Verifies that two sequences are not equivalent, using a default comparer. More...
 
static void NotEqual< T > (IEnumerable< T > expected, IEnumerable< T > actual, IEqualityComparer< T > comparer)
 Verifies that two sequences are not equivalent, using a custom equality comparer. More...
 
static object Single (IEnumerable collection)
 Verifies that the given collection contains only a single element of the given type. More...
 
static void Single (IEnumerable collection, object expected)
 Verifies that the given collection contains only a single element of the given value. The collection may or may not contain other values. More...
 
static T Single< T > (IEnumerable< T > collection)
 Verifies that the given collection contains only a single element of the given type. More...
 
static T Single< T > (IEnumerable< T > collection, Predicate< T > predicate)
 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. More...
 
static void Equal< T > (T expected, T actual)
 Verifies that two objects are equal, using a default comparer. More...
 
static void Equal< T > (T expected, T actual, IEqualityComparer< T > comparer)
 Verifies that two objects are equal, using a custom equatable comparer. More...
 
static void Equal (double expected, double actual, int precision)
 Verifies that two double values are equal, within the number of decimal places given by precision . The values are rounded before comparison. More...
 
static void Equal (decimal expected, decimal actual, int precision)
 Verifies that two decimal values are equal, within the number of decimal places given by precision . The values are rounded before comparison. More...
 
static void Equal (DateTime expected, DateTime actual, TimeSpan precision)
 Verifies that two DateTime values are equal, within the precision given by precision . More...
 
static void StrictEqual< T > (T expected, T actual)
 Verifies that two objects are strictly equal, using the type's default comparer. More...
 
static void NotEqual< T > (T expected, T actual)
 Verifies that two objects are not equal, using a default comparer. More...
 
static void NotEqual< T > (T expected, T actual, IEqualityComparer< T > comparer)
 Verifies that two objects are not equal, using a custom equality comparer. More...
 
static void NotEqual (double expected, double actual, int precision)
 Verifies that two double values are not equal, within the number of decimal places given by precision . More...
 
static void NotEqual (decimal expected, decimal actual, int precision)
 Verifies that two decimal values are not equal, within the number of decimal places given by precision . More...
 
static void NotStrictEqual< T > (T expected, T actual)
 Verifies that two objects are strictly not equal, using the type's default comparer. More...
 
static RaisedEvent< T > Raises< T > (Action< EventHandler< T >> attach, Action< EventHandler< T >> detach, Action testCode)
 Verifies that a event with the exact event args is raised. More...
 
static RaisedEvent< T > RaisesAny< T > (Action< EventHandler< T >> attach, Action< EventHandler< T >> detach, Action testCode)
 Verifies that an event with the exact or a derived event args is raised. More...
 
static async Task< RaisedEvent< T > > RaisesAsync< T > (Action< EventHandler< T >> attach, Action< EventHandler< T >> detach, Func< Task > testCode)
 Verifies that a event with the exact event args (and not a derived type) is raised. More...
 
static async Task< RaisedEvent< T > > RaisesAnyAsync< T > (Action< EventHandler< T >> attach, Action< EventHandler< T >> detach, Func< Task > testCode)
 Verifies that an event with the exact or a derived event args is raised. More...
 
static T Throws< T > (Action testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). More...
 
static T Throws< T > (Func< object > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors. More...
 
static T Throws< T > (Func< Task > testCode)
 
static async Task< T > ThrowsAsync< T > (Func< Task > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). More...
 
static T ThrowsAny< T > (Action testCode)
 Verifies that the exact exception or a derived exception type is thrown. More...
 
static T ThrowsAny< T > (Func< object > testCode)
 Verifies that the exact exception or a derived exception type is thrown. Generally used to test property accessors. More...
 
static async Task< T > ThrowsAnyAsync< T > (Func< Task > testCode)
 Verifies that the exact exception or a derived exception type is thrown. More...
 
static Exception Throws (Type exceptionType, Action testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). More...
 
static Exception Throws (Type exceptionType, Func< object > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). Generally used to test property accessors. More...
 
static async Task< Exception > ThrowsAsync (Type exceptionType, Func< Task > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type). More...
 
static T Throws< T > (string paramName, Action testCode)
 Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name. More...
 
static T Throws< T > (string paramName, Func< object > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name. More...
 
static T Throws< T > (string paramName, Func< Task > testCode)
 
static async Task< T > ThrowsAsync< T > (string paramName, Func< Task > testCode)
 Verifies that the exact exception is thrown (and not a derived exception type), where the exception derives from ArgumentException and has the given parameter name. More...
 
static void NotSame (object expected, object actual)
 Verifies that two objects are not the same instance. More...
 
static void Same (object expected, object actual)
 Verifies that two objects are the same instance. More...
 
static void NotNull (object @object)
 Verifies that an object reference is not null. More...
 
static void Null (object @object)
 Verifies that an object reference is null. More...
 
static void PropertyChanged (INotifyPropertyChanged @object, string propertyName, Action testCode)
 Verifies that the provided object raised INotifyPropertyChanged.PropertyChanged as a result of executing the given test code. More...
 
static void PropertyChanged (INotifyPropertyChanged @object, string propertyName, Func< Task > testCode)
 
static async Task PropertyChangedAsync (INotifyPropertyChanged @object, string propertyName, Func< Task > testCode)
 Verifies that the provided object raised INotifyPropertyChanged.PropertyChanged as a result of executing the given test code. More...
 
static void InRange< T > (T actual, T low, T high)
 Verifies that a value is within a given range. More...
 
static void InRange< T > (T actual, T low, T high, IComparer< T > comparer)
 Verifies that a value is within a given range, using a comparer. More...
 
static void NotInRange< T > (T actual, T low, T high)
 Verifies that a value is not within a given range, using the default comparer. More...
 
static void NotInRange< T > (T actual, T low, T high, IComparer< T > comparer)
 Verifies that a value is not within a given range, using a comparer. More...
 
static void ProperSubset< T > (ISet< T > expectedSuperset, ISet< T > actual)
 Verifies that a set is a proper subset of another set. More...
 
static void ProperSuperset< T > (ISet< T > expectedSubset, ISet< T > actual)
 Verifies that a set is a proper superset of another set. More...
 
static void Subset< T > (ISet< T > expectedSuperset, ISet< T > actual)
 Verifies that a set is a subset of another set. More...
 
static void Superset< T > (ISet< T > expectedSubset, ISet< T > actual)
 Verifies that a set is a superset of another set. More...
 
static void Contains (string expectedSubstring, string actualString)
 Verifies that a string contains a given sub-string, using the current culture. More...
 
static void Contains (string expectedSubstring, string actualString, StringComparison comparisonType)
 Verifies that a string contains a given sub-string, using the given comparison type. More...
 
static void DoesNotContain (string expectedSubstring, string actualString)
 Verifies that a string does not contain a given sub-string, using the current culture. More...
 
static void DoesNotContain (string expectedSubstring, string actualString, StringComparison comparisonType)
 Verifies that a string does not contain a given sub-string, using the current culture. More...
 
static void StartsWith (string expectedStartString, string actualString)
 Verifies that a string starts with a given string, using the current culture. More...
 
static void StartsWith (string expectedStartString, string actualString, StringComparison comparisonType)
 Verifies that a string starts with a given string, using the given comparison type. More...
 
static void EndsWith (string expectedEndString, string actualString)
 Verifies that a string ends with a given string, using the current culture. More...
 
static void EndsWith (string expectedEndString, string actualString, StringComparison comparisonType)
 Verifies that a string ends with a given string, using the given comparison type. More...
 
static void Matches (string expectedRegexPattern, string actualString)
 Verifies that a string matches a regular expression. More...
 
static void Matches (Regex expectedRegex, string actualString)
 Verifies that a string matches a regular expression. More...
 
static void DoesNotMatch (string expectedRegexPattern, string actualString)
 Verifies that a string does not match a regular expression. More...
 
static void DoesNotMatch (Regex expectedRegex, string actualString)
 Verifies that a string does not match a regular expression. More...
 
static void Equal (string expected, string actual)
 Verifies that two strings are equivalent. More...
 
static void Equal (string expected, string actual, bool ignoreCase=false, bool ignoreLineEndingDifferences=false, bool ignoreWhiteSpaceDifferences=false)
 Verifies that two strings are equivalent. More...
 
static T IsAssignableFrom< T > (object @object)
 Verifies that an object is of the given type or a derived type. More...
 
static void IsAssignableFrom (Type expectedType, object @object)
 Verifies that an object is of the given type or a derived type. More...
 
static void IsNotType< T > (object @object)
 Verifies that an object is not exactly the given type. More...
 
static void IsNotType (Type expectedType, object @object)
 Verifies that an object is not exactly the given type. More...
 
static T IsType< T > (object @object)
 Verifies that an object is exactly the given type (and not a derived type). More...
 
static void IsType (Type expectedType, object @object)
 Verifies that an object is exactly the given type (and not a derived type). More...
 

Protected Member Functions

 Assert ()
 Initializes a new instance of the Assert class. More...
 

Static Protected Member Functions

static Exception RecordException (Action testCode)
 Records any exception which is thrown by the given code. More...
 
static Exception RecordException (Func< object > testCode)
 Records any exception which is thrown by the given code that has a return value. Generally used for testing property accessors. More...
 
static Exception RecordException (Func< Task > testCode)
 
static async Task< Exception > RecordExceptionAsync (Func< Task > testCode)
 Records any exception which is thrown by the given task. More...
 

Detailed Description

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

Constructor & Destructor Documentation

◆ Assert()

Xunit.Assert.Assert ( )
inlineprotected

Initializes a new instance of the Assert class.

Member Function Documentation

◆ All< T >()

static void Xunit.Assert.All< T > ( IEnumerable< T >  collection,
Action< T >  action 
)
inlinestatic

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

Template Parameters
TThe type of the object to be verified
Parameters
collectionThe collection
actionThe action to test each item against
Exceptions
AllExceptionThrown when the collection contains at least one non-matching element

◆ Collection< T >()

static void Xunit.Assert.Collection< T > ( IEnumerable< T >  collection,
params Action< T > []  elementInspectors 
)
inlinestatic

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

Template Parameters
TThe type of the object to be verified
Parameters
collectionThe collection to be inspected
elementInspectorsThe element inspectors, which inspect each element in turn. The total number of element inspectors must exactly match the number of elements in the collection.

◆ Contains() [1/2]

static void Xunit.Assert.Contains ( string  expectedSubstring,
string  actualString 
)
inlinestatic

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

Parameters
expectedSubstringThe sub-string expected to be in the string
actualStringThe string to be inspected
Exceptions
ContainsExceptionThrown when the sub-string is not present inside the string

◆ Contains() [2/2]

static void Xunit.Assert.Contains ( string  expectedSubstring,
string  actualString,
StringComparison  comparisonType 
)
inlinestatic

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

Parameters
expectedSubstringThe sub-string expected to be in the string
actualStringThe string to be inspected
comparisonTypeThe type of string comparison to perform
Exceptions
ContainsExceptionThrown when the sub-string is not present inside the string

◆ Contains< T >() [1/3]

static void Xunit.Assert.Contains< T > ( expected,
IEnumerable< T >  collection 
)
inlinestatic

Verifies that a collection contains a given object.

Template Parameters
TThe type of the object to be verified
Parameters
expectedThe object expected to be in the collection
collectionThe collection to be inspected
Exceptions
ContainsExceptionThrown when the object is not present in the collection

◆ Contains< T >() [2/3]

static void Xunit.Assert.Contains< T > ( expected,
IEnumerable< T >  collection,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the object to be verified
Parameters
expectedThe object expected to be in the collection
collectionThe collection to be inspected
comparerThe comparer used to equate objects in the collection with the expected object
Exceptions
ContainsExceptionThrown when the object is not present in the collection

◆ Contains< T >() [3/3]

static void Xunit.Assert.Contains< T > ( IEnumerable< T >  collection,
Predicate< T >  filter 
)
inlinestatic

Verifies that a collection contains a given object.

Template Parameters
TThe type of the object to be verified
Parameters
collectionThe collection to be inspected
filterThe filter used to find the item you're ensuring the collection contains
Exceptions
ContainsExceptionThrown when the object is not present in the collection

◆ Contains< TKey, TValue >() [1/2]

static TValue Xunit.Assert.Contains< TKey, TValue > ( TKey  expected,
IReadOnlyDictionary< TKey, TValue >  collection 
)
inlinestatic

Verifies that a dictionary contains a given key.

Template Parameters
TKeyThe type of the keys of the object to be verified.
TValueThe type of the values of the object to be verified.
Parameters
expectedThe object expected to be in the collection.
collectionThe collection to be inspected.
Returns
The value associated with expected .
Exceptions
ContainsExceptionThrown when the object is not present in the collection

◆ Contains< TKey, TValue >() [2/2]

static TValue Xunit.Assert.Contains< TKey, TValue > ( TKey  expected,
IDictionary< TKey, TValue >  collection 
)
inlinestatic

Verifies that a dictionary contains a given key.

Template Parameters
TKeyThe type of the keys of the object to be verified.
TValueThe type of the values of the object to be verified.
Parameters
expectedThe object expected to be in the collection.
collectionThe collection to be inspected.
Returns
The value associated with expected .
Exceptions
ContainsExceptionThrown when the object is not present in the collection

◆ DoesNotContain() [1/2]

static void Xunit.Assert.DoesNotContain ( string  expectedSubstring,
string  actualString 
)
inlinestatic

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

Parameters
expectedSubstringThe sub-string which is expected not to be in the string
actualStringThe string to be inspected
Exceptions
DoesNotContainExceptionThrown when the sub-string is present inside the string

◆ DoesNotContain() [2/2]

static void Xunit.Assert.DoesNotContain ( string  expectedSubstring,
string  actualString,
StringComparison  comparisonType 
)
inlinestatic

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

Parameters
expectedSubstringThe sub-string which is expected not to be in the string
actualStringThe string to be inspected
comparisonTypeThe type of string comparison to perform
Exceptions
DoesNotContainExceptionThrown when the sub-string is present inside the given string

◆ DoesNotContain< T >() [1/3]

static void Xunit.Assert.DoesNotContain< T > ( expected,
IEnumerable< T >  collection 
)
inlinestatic

Verifies that a collection does not contain a given object.

Template Parameters
TThe type of the object to be compared
Parameters
expectedThe object that is expected not to be in the collection
collectionThe collection to be inspected
Exceptions
DoesNotContainExceptionThrown when the object is present inside the container

◆ DoesNotContain< T >() [2/3]

static void Xunit.Assert.DoesNotContain< T > ( expected,
IEnumerable< T >  collection,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the object to be compared
Parameters
expectedThe object that is expected not to be in the collection
collectionThe collection to be inspected
comparerThe comparer used to equate objects in the collection with the expected object
Exceptions
DoesNotContainExceptionThrown when the object is present inside the container

◆ DoesNotContain< T >() [3/3]

static void Xunit.Assert.DoesNotContain< T > ( IEnumerable< T >  collection,
Predicate< T >  filter 
)
inlinestatic

Verifies that a collection does not contain a given object.

Template Parameters
TThe type of the object to be compared
Parameters
collectionThe collection to be inspected
filterThe filter used to find the item you're ensuring the collection does not contain
Exceptions
DoesNotContainExceptionThrown when the object is present inside the container

◆ DoesNotContain< TKey, TValue >() [1/2]

static void Xunit.Assert.DoesNotContain< TKey, TValue > ( TKey  expected,
IReadOnlyDictionary< TKey, TValue >  collection 
)
inlinestatic

Verifies that a dictionary does not contain a given key.

Template Parameters
TKeyThe type of the keys of the object to be verified.
TValueThe type of the values of the object to be verified.
Parameters
expectedThe object expected to be in the collection.
collectionThe collection to be inspected.
Exceptions
DoesNotContainExceptionThrown when the object is present in the collection

◆ DoesNotContain< TKey, TValue >() [2/2]

static void Xunit.Assert.DoesNotContain< TKey, TValue > ( TKey  expected,
IDictionary< TKey, TValue >  collection 
)
inlinestatic

Verifies that a dictionary does not contain a given key.

Template Parameters
TKeyThe type of the keys of the object to be verified.
TValueThe type of the values of the object to be verified.
Parameters
expectedThe object expected to be in the collection.
collectionThe collection to be inspected.
Exceptions
DoesNotContainExceptionThrown when the object is present in the collection

◆ DoesNotMatch() [1/2]

static void Xunit.Assert.DoesNotMatch ( string  expectedRegexPattern,
string  actualString 
)
inlinestatic

Verifies that a string does not match a regular expression.

Parameters
expectedRegexPatternThe regex pattern expected not to match
actualStringThe string to be inspected
Exceptions
DoesNotMatchExceptionThrown when the string matches the regex pattern

◆ DoesNotMatch() [2/2]

static void Xunit.Assert.DoesNotMatch ( Regex  expectedRegex,
string  actualString 
)
inlinestatic

Verifies that a string does not match a regular expression.

Parameters
expectedRegexThe regex expected not to match
actualStringThe string to be inspected
Exceptions
DoesNotMatchExceptionThrown when the string matches the regex

◆ Empty()

static void Xunit.Assert.Empty ( IEnumerable  collection)
inlinestatic

Verifies that a collection is empty.

Parameters
collectionThe collection to be inspected
Exceptions
ArgumentNullExceptionThrown when the collection is null
EmptyExceptionThrown when the collection is not empty

◆ EndsWith() [1/2]

static void Xunit.Assert.EndsWith ( string  expectedEndString,
string  actualString 
)
inlinestatic

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

Parameters
expectedEndStringThe string expected to be at the end of the string
actualStringThe string to be inspected
Exceptions
ContainsExceptionThrown when the string does not end with the expected string

◆ EndsWith() [2/2]

static void Xunit.Assert.EndsWith ( string  expectedEndString,
string  actualString,
StringComparison  comparisonType 
)
inlinestatic

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

Parameters
expectedEndStringThe string expected to be at the end of the string
actualStringThe string to be inspected
comparisonTypeThe type of string comparison to perform
Exceptions
ContainsExceptionThrown when the string does not end with the expected string

◆ Equal() [1/5]

static void Xunit.Assert.Equal ( double  expected,
double  actual,
int  precision 
)
inlinestatic

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

Parameters
expectedThe expected value
actualThe value to be compared against
precisionThe number of decimal places (valid values: 0-15)
Exceptions
EqualExceptionThrown when the values are not equal

◆ Equal() [2/5]

static void Xunit.Assert.Equal ( decimal  expected,
decimal  actual,
int  precision 
)
inlinestatic

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

Parameters
expectedThe expected value
actualThe value to be compared against
precisionThe number of decimal places (valid values: 0-28)
Exceptions
EqualExceptionThrown when the values are not equal

◆ Equal() [3/5]

static void Xunit.Assert.Equal ( DateTime  expected,
DateTime  actual,
TimeSpan  precision 
)
inlinestatic

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

Parameters
expectedThe expected value
actualThe value to be compared against
precisionThe allowed difference in time where the two dates are considered equal
Exceptions
EqualExceptionThrown when the values are not equal

◆ Equal() [4/5]

static void Xunit.Assert.Equal ( string  expected,
string  actual 
)
inlinestatic

Verifies that two strings are equivalent.

Parameters
expectedThe expected string value.
actualThe actual string value.
Exceptions
EqualExceptionThrown when the strings are not equivalent.

◆ Equal() [5/5]

static void Xunit.Assert.Equal ( string  expected,
string  actual,
bool  ignoreCase = false,
bool  ignoreLineEndingDifferences = false,
bool  ignoreWhiteSpaceDifferences = false 
)
inlinestatic

Verifies that two strings are equivalent.

Parameters
expectedThe expected string value.
actualThe actual string value.
ignoreCaseIf set to true, ignores cases differences. The invariant culture is used.
ignoreLineEndingDifferencesIf set to true, treats \r
, \r, and
as equivalent.
ignoreWhiteSpaceDifferencesIf set to true, treats spaces and tabs (in any non-zero quantity) as equivalent.
Exceptions
EqualExceptionThrown when the strings are not equivalent.

◆ Equal< T >() [1/4]

static void Xunit.Assert.Equal< T > ( expected,
actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected value
actualThe value to be compared against
Exceptions
EqualExceptionThrown when the objects are not equal

◆ Equal< T >() [2/4]

static void Xunit.Assert.Equal< T > ( expected,
actual,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected value
actualThe value to be compared against
comparerThe comparer used to compare the two objects
Exceptions
EqualExceptionThrown when the objects are not equal

◆ Equal< T >() [3/4]

static void Xunit.Assert.Equal< T > ( IEnumerable< T >  expected,
IEnumerable< T >  actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected value
actualThe value to be compared against
Exceptions
EqualExceptionThrown when the objects are not equal

◆ Equal< T >() [4/4]

static void Xunit.Assert.Equal< T > ( IEnumerable< T >  expected,
IEnumerable< T >  actual,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected value
actualThe value to be compared against
comparerThe comparer used to compare the two objects
Exceptions
EqualExceptionThrown when the objects are not equal

◆ Equals()

static new bool Xunit.Assert.Equals ( object  a,
object  b 
)
inlinestatic

Do not call this method.

◆ False() [1/4]

static void Xunit.Assert.False ( bool  condition)
inlinestatic

Verifies that the condition is false.

Parameters
conditionThe condition to be tested
Exceptions
FalseExceptionThrown if the condition is not false

◆ False() [2/4]

static void Xunit.Assert.False ( bool?  condition)
inlinestatic

Verifies that the condition is false.

Parameters
conditionThe condition to be tested
Exceptions
FalseExceptionThrown if the condition is not false

◆ False() [3/4]

static void Xunit.Assert.False ( bool  condition,
string  userMessage 
)
inlinestatic

Verifies that the condition is false.

Parameters
conditionThe condition to be tested
userMessageThe message to show when the condition is not false
Exceptions
FalseExceptionThrown if the condition is not false

◆ False() [4/4]

static void Xunit.Assert.False ( bool?  condition,
string  userMessage 
)
inlinestatic

Verifies that the condition is false.

Parameters
conditionThe condition to be tested
userMessageThe message to show when the condition is not false
Exceptions
FalseExceptionThrown if the condition is not false

◆ InRange< T >() [1/2]

static void Xunit.Assert.InRange< T > ( actual,
low,
high 
)
inlinestatic

Verifies that a value is within a given range.

Template Parameters
TThe type of the value to be compared
Parameters
actualThe actual value to be evaluated
lowThe (inclusive) low value of the range
highThe (inclusive) high value of the range
Exceptions
InRangeExceptionThrown when the value is not in the given range
Type Constraints
T :IComparable 

◆ InRange< T >() [2/2]

static void Xunit.Assert.InRange< T > ( actual,
low,
high,
IComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the value to be compared
Parameters
actualThe actual value to be evaluated
lowThe (inclusive) low value of the range
highThe (inclusive) high value of the range
comparerThe comparer used to evaluate the value's range
Exceptions
InRangeExceptionThrown when the value is not in the given range

◆ IsAssignableFrom()

static void Xunit.Assert.IsAssignableFrom ( Type  expectedType,
object @  object 
)
inlinestatic

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

Parameters
expectedTypeThe type the object should be
objectThe object to be evaluated
Exceptions
IsAssignableFromExceptionThrown when the object is not the given type

◆ IsAssignableFrom< T >()

static T Xunit.Assert.IsAssignableFrom< T > ( object @  object)
inlinestatic

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

Template Parameters
TThe type the object should be
Parameters
objectThe object to be evaluated
Returns
The object, casted to type T when successful
Exceptions
IsAssignableFromExceptionThrown when the object is not the given type

◆ IsNotType()

static void Xunit.Assert.IsNotType ( Type  expectedType,
object @  object 
)
inlinestatic

Verifies that an object is not exactly the given type.

Parameters
expectedTypeThe type the object should not be
objectThe object to be evaluated
Exceptions
IsNotTypeExceptionThrown when the object is the given type

◆ IsNotType< T >()

static void Xunit.Assert.IsNotType< T > ( object @  object)
inlinestatic

Verifies that an object is not exactly the given type.

Template Parameters
TThe type the object should not be
Parameters
objectThe object to be evaluated
Exceptions
IsNotTypeExceptionThrown when the object is the given type

◆ IsType()

static void Xunit.Assert.IsType ( Type  expectedType,
object @  object 
)
inlinestatic

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

Parameters
expectedTypeThe type the object should be
objectThe object to be evaluated
Exceptions
IsTypeExceptionThrown when the object is not the given type

◆ IsType< T >()

static T Xunit.Assert.IsType< T > ( object @  object)
inlinestatic

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

Template Parameters
TThe type the object should be
Parameters
objectThe object to be evaluated
Returns
The object, casted to type T when successful
Exceptions
IsTypeExceptionThrown when the object is not the given type

◆ Matches() [1/2]

static void Xunit.Assert.Matches ( string  expectedRegexPattern,
string  actualString 
)
inlinestatic

Verifies that a string matches a regular expression.

Parameters
expectedRegexPatternThe regex pattern expected to match
actualStringThe string to be inspected
Exceptions
MatchesExceptionThrown when the string does not match the regex pattern

◆ Matches() [2/2]

static void Xunit.Assert.Matches ( Regex  expectedRegex,
string  actualString 
)
inlinestatic

Verifies that a string matches a regular expression.

Parameters
expectedRegexThe regex expected to match
actualStringThe string to be inspected
Exceptions
MatchesExceptionThrown when the string does not match the regex

◆ NotEmpty()

static void Xunit.Assert.NotEmpty ( IEnumerable  collection)
inlinestatic

Verifies that a collection is not empty.

Parameters
collectionThe collection to be inspected
Exceptions
ArgumentNullExceptionThrown when a null collection is passed
NotEmptyExceptionThrown when the collection is empty

◆ NotEqual() [1/2]

static void Xunit.Assert.NotEqual ( double  expected,
double  actual,
int  precision 
)
inlinestatic

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

Parameters
expectedThe expected value
actualThe value to be compared against
precisionThe number of decimal places (valid values: 0-15)
Exceptions
EqualExceptionThrown when the values are equal

◆ NotEqual() [2/2]

static void Xunit.Assert.NotEqual ( decimal  expected,
decimal  actual,
int  precision 
)
inlinestatic

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

Parameters
expectedThe expected value
actualThe value to be compared against
precisionThe number of decimal places (valid values: 0-28)
Exceptions
EqualExceptionThrown when the values are equal

◆ NotEqual< T >() [1/4]

static void Xunit.Assert.NotEqual< T > ( expected,
actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected object
actualThe actual object
Exceptions
NotEqualExceptionThrown when the objects are equal

◆ NotEqual< T >() [2/4]

static void Xunit.Assert.NotEqual< T > ( expected,
actual,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected object
actualThe actual object
comparerThe comparer used to examine the objects
Exceptions
NotEqualExceptionThrown when the objects are equal

◆ NotEqual< T >() [3/4]

static void Xunit.Assert.NotEqual< T > ( IEnumerable< T >  expected,
IEnumerable< T >  actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected object
actualThe actual object
Exceptions
NotEqualExceptionThrown when the objects are equal

◆ NotEqual< T >() [4/4]

static void Xunit.Assert.NotEqual< T > ( IEnumerable< T >  expected,
IEnumerable< T >  actual,
IEqualityComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected object
actualThe actual object
comparerThe comparer used to compare the two objects
Exceptions
NotEqualExceptionThrown when the objects are equal

◆ NotInRange< T >() [1/2]

static void Xunit.Assert.NotInRange< T > ( actual,
low,
high 
)
inlinestatic

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

Template Parameters
TThe type of the value to be compared
Parameters
actualThe actual value to be evaluated
lowThe (inclusive) low value of the range
highThe (inclusive) high value of the range
Exceptions
NotInRangeExceptionThrown when the value is in the given range
Type Constraints
T :IComparable 

◆ NotInRange< T >() [2/2]

static void Xunit.Assert.NotInRange< T > ( actual,
low,
high,
IComparer< T >  comparer 
)
inlinestatic

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

Template Parameters
TThe type of the value to be compared
Parameters
actualThe actual value to be evaluated
lowThe (inclusive) low value of the range
highThe (inclusive) high value of the range
comparerThe comparer used to evaluate the value's range
Exceptions
NotInRangeExceptionThrown when the value is in the given range

◆ NotNull()

static void Xunit.Assert.NotNull ( object @  object)
inlinestatic

Verifies that an object reference is not null.

Parameters
objectThe object to be validated
Exceptions
NotNullExceptionThrown when the object is not null

◆ NotSame()

static void Xunit.Assert.NotSame ( object  expected,
object  actual 
)
inlinestatic

Verifies that two objects are not the same instance.

Parameters
expectedThe expected object instance
actualThe actual object instance
Exceptions
NotSameExceptionThrown when the objects are the same instance

◆ NotStrictEqual< T >()

static void Xunit.Assert.NotStrictEqual< T > ( expected,
actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected object
actualThe actual object
Exceptions
NotEqualExceptionThrown when the objects are equal

◆ Null()

static void Xunit.Assert.Null ( object @  object)
inlinestatic

Verifies that an object reference is null.

Parameters
objectThe object to be inspected
Exceptions
NullExceptionThrown when the object reference is not null

◆ ProperSubset< T >()

static void Xunit.Assert.ProperSubset< T > ( ISet< T >  expectedSuperset,
ISet< T >  actual 
)
inlinestatic

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

Template Parameters
TThe type of the object to be verified
Parameters
expectedSupersetThe expected superset
actualThe set expected to be a proper subset
Exceptions
ContainsExceptionThrown when the actual set is not a proper subset of the expected set

◆ ProperSuperset< T >()

static void Xunit.Assert.ProperSuperset< T > ( ISet< T >  expectedSubset,
ISet< T >  actual 
)
inlinestatic

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

Template Parameters
TThe type of the object to be verified
Parameters
expectedSubsetThe expected subset
actualThe set expected to be a proper superset
Exceptions
ContainsExceptionThrown when the actual set is not a proper superset of the expected set

◆ PropertyChanged()

static void Xunit.Assert.PropertyChanged ( INotifyPropertyChanged @  object,
string  propertyName,
Action  testCode 
)
inlinestatic

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

Parameters
objectThe object which should raise the notification
propertyNameThe property name for which the notification should be raised
testCodeThe test code which should cause the notification to be raised
Exceptions
PropertyChangedExceptionThrown when the notification is not raised

◆ PropertyChangedAsync()

static async Task Xunit.Assert.PropertyChangedAsync ( INotifyPropertyChanged @  object,
string  propertyName,
Func< Task >  testCode 
)
inlinestatic

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

Parameters
objectThe object which should raise the notification
propertyNameThe property name for which the notification should be raised
testCodeThe test code which should cause the notification to be raised
Exceptions
PropertyChangedExceptionThrown when the notification is not raised

◆ Raises< T >()

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

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

Template Parameters
TThe type of the event arguments to expect
Parameters
attachCode to attach the event handler
detachCode to detach the event handler
testCodeA delegate to the code to be tested
Returns
The event sender and arguments wrapped in an object
Exceptions
RaisesExceptionThrown when the expected event was not raised.
Type Constraints
T :EventArgs 

◆ RaisesAny< T >()

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

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

Template Parameters
TThe type of the event arguments to expect
Parameters
attachCode to attach the event handler
detachCode to detach the event handler
testCodeA delegate to the code to be tested
Returns
The event sender and arguments wrapped in an object
Exceptions
RaisesExceptionThrown when the expected event was not raised.
Type Constraints
T :EventArgs 

◆ RaisesAnyAsync< T >()

static async Task<RaisedEvent<T> > Xunit.Assert.RaisesAnyAsync< T > ( Action< EventHandler< T >>  attach,
Action< EventHandler< T >>  detach,
Func< Task >  testCode 
)
inlinestatic

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

Template Parameters
TThe type of the event arguments to expect
Parameters
attachCode to attach the event handler
detachCode to detach the event handler
testCodeA delegate to the code to be tested
Returns
The event sender and arguments wrapped in an object
Exceptions
RaisesExceptionThrown when the expected event was not raised.
Type Constraints
T :EventArgs 

◆ RaisesAsync< T >()

static async Task<RaisedEvent<T> > Xunit.Assert.RaisesAsync< T > ( Action< EventHandler< T >>  attach,
Action< EventHandler< T >>  detach,
Func< Task >  testCode 
)
inlinestatic

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

Template Parameters
TThe type of the event arguments to expect
Parameters
attachCode to attach the event handler
detachCode to detach the event handler
testCodeA delegate to the code to be tested
Returns
The event sender and arguments wrapped in an object
Exceptions
RaisesExceptionThrown when the expected event was not raised.
Type Constraints
T :EventArgs 

◆ RecordException() [1/2]

static Exception Xunit.Assert.RecordException ( Action  testCode)
inlinestaticprotected

Records any exception which is thrown by the given code.

Parameters
testCodeThe code which may thrown an exception.
Returns
Returns the exception that was thrown by the code; null, otherwise.

◆ RecordException() [2/2]

static Exception Xunit.Assert.RecordException ( Func< object >  testCode)
inlinestaticprotected

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

Parameters
testCodeThe code which may thrown an exception.
Returns
Returns the exception that was thrown by the code; null, otherwise.

◆ RecordExceptionAsync()

static async Task<Exception> Xunit.Assert.RecordExceptionAsync ( Func< Task >  testCode)
inlinestaticprotected

Records any exception which is thrown by the given task.

Parameters
testCodeThe task which may thrown an exception.
Returns
Returns the exception that was thrown by the code; null, otherwise.

◆ ReferenceEquals()

static new bool Xunit.Assert.ReferenceEquals ( object  a,
object  b 
)
inlinestatic

Do not call this method.

◆ Same()

static void Xunit.Assert.Same ( object  expected,
object  actual 
)
inlinestatic

Verifies that two objects are the same instance.

Parameters
expectedThe expected object instance
actualThe actual object instance
Exceptions
SameExceptionThrown when the objects are not the same instance

◆ Single() [1/2]

static object Xunit.Assert.Single ( IEnumerable  collection)
inlinestatic

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

Parameters
collectionThe collection.
Returns
The single item in the collection.
Exceptions
SingleExceptionThrown when the collection does not contain exactly one element.

◆ Single() [2/2]

static void Xunit.Assert.Single ( IEnumerable  collection,
object  expected 
)
inlinestatic

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

Parameters
collectionThe collection.
expectedThe value to find in the collection.
Returns
The single item in the collection.
Exceptions
SingleExceptionThrown when the collection does not contain exactly one element.

◆ Single< T >() [1/2]

static T Xunit.Assert.Single< T > ( IEnumerable< T >  collection)
inlinestatic

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

Template Parameters
TThe collection type.
Parameters
collectionThe collection.
Returns
The single item in the collection.
Exceptions
SingleExceptionThrown when the collection does not contain exactly one element.

◆ Single< T >() [2/2]

static T Xunit.Assert.Single< T > ( IEnumerable< T >  collection,
Predicate< T >  predicate 
)
inlinestatic

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.

Template Parameters
TThe collection type.
Parameters
collectionThe collection.
predicateThe item matching predicate.
Returns
The single item in the filtered collection.
Exceptions
SingleExceptionThrown when the filtered collection does not contain exactly one element.

◆ StartsWith() [1/2]

static void Xunit.Assert.StartsWith ( string  expectedStartString,
string  actualString 
)
inlinestatic

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

Parameters
expectedStartStringThe string expected to be at the start of the string
actualStringThe string to be inspected
Exceptions
ContainsExceptionThrown when the string does not start with the expected string

◆ StartsWith() [2/2]

static void Xunit.Assert.StartsWith ( string  expectedStartString,
string  actualString,
StringComparison  comparisonType 
)
inlinestatic

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

Parameters
expectedStartStringThe string expected to be at the start of the string
actualStringThe string to be inspected
comparisonTypeThe type of string comparison to perform
Exceptions
ContainsExceptionThrown when the string does not start with the expected string

◆ StrictEqual< T >()

static void Xunit.Assert.StrictEqual< T > ( expected,
actual 
)
inlinestatic

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

Template Parameters
TThe type of the objects to be compared
Parameters
expectedThe expected value
actualThe value to be compared against
Exceptions
EqualExceptionThrown when the objects are not equal

◆ Subset< T >()

static void Xunit.Assert.Subset< T > ( ISet< T >  expectedSuperset,
ISet< T >  actual 
)
inlinestatic

Verifies that a set is a subset of another set.

Template Parameters
TThe type of the object to be verified
Parameters
expectedSupersetThe expected superset
actualThe set expected to be a subset
Exceptions
ContainsExceptionThrown when the actual set is not a subset of the expected set

◆ Superset< T >()

static void Xunit.Assert.Superset< T > ( ISet< T >  expectedSubset,
ISet< T >  actual 
)
inlinestatic

Verifies that a set is a superset of another set.

Template Parameters
TThe type of the object to be verified
Parameters
expectedSubsetThe expected subset
actualThe set expected to be a superset
Exceptions
ContainsExceptionThrown when the actual set is not a superset of the expected set

◆ Throws() [1/2]

static Exception Xunit.Assert.Throws ( Type  exceptionType,
Action  testCode 
)
inlinestatic

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

Parameters
exceptionTypeThe type of the exception expected to be thrown
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown

◆ Throws() [2/2]

static Exception Xunit.Assert.Throws ( Type  exceptionType,
Func< object >  testCode 
)
inlinestatic

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

Parameters
exceptionTypeThe type of the exception expected to be thrown
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown

◆ Throws< T >() [1/4]

static T Xunit.Assert.Throws< T > ( Action  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ Throws< T >() [2/4]

static T Xunit.Assert.Throws< T > ( Func< object >  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ Throws< T >() [3/4]

static T Xunit.Assert.Throws< T > ( string  paramName,
Action  testCode 
)
inlinestatic

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

Parameters
paramNameThe parameter name that is expected to be in the exception
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :ArgumentException 

◆ Throws< T >() [4/4]

static T Xunit.Assert.Throws< T > ( string  paramName,
Func< object >  testCode 
)
inlinestatic

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

Parameters
paramNameThe parameter name that is expected to be in the exception
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :ArgumentException 

◆ ThrowsAny< T >() [1/2]

static T Xunit.Assert.ThrowsAny< T > ( Action  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ ThrowsAny< T >() [2/2]

static T Xunit.Assert.ThrowsAny< T > ( Func< object >  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the code to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ ThrowsAnyAsync< T >()

static async Task<T> Xunit.Assert.ThrowsAnyAsync< T > ( Func< Task >  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the task to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ ThrowsAsync()

static async Task<Exception> Xunit.Assert.ThrowsAsync ( Type  exceptionType,
Func< Task >  testCode 
)
inlinestatic

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

Parameters
exceptionTypeThe type of the exception expected to be thrown
testCodeA delegate to the task to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown

◆ ThrowsAsync< T >() [1/2]

static async Task<T> Xunit.Assert.ThrowsAsync< T > ( Func< Task >  testCode)
inlinestatic

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

Template Parameters
TThe type of the exception expected to be thrown
Parameters
testCodeA delegate to the task to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :Exception 

◆ ThrowsAsync< T >() [2/2]

static async Task<T> Xunit.Assert.ThrowsAsync< T > ( string  paramName,
Func< Task >  testCode 
)
inlinestatic

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

Parameters
paramNameThe parameter name that is expected to be in the exception
testCodeA delegate to the task to be tested
Returns
The exception that was thrown, when successful
Exceptions
ThrowsExceptionThrown when an exception was not thrown, or when an exception of the incorrect type is thrown
Type Constraints
T :ArgumentException 

◆ True() [1/4]

static void Xunit.Assert.True ( bool  condition)
inlinestatic

Verifies that an expression is true.

Parameters
conditionThe condition to be inspected
Exceptions
TrueExceptionThrown when the condition is false

◆ True() [2/4]

static void Xunit.Assert.True ( bool?  condition)
inlinestatic

Verifies that an expression is true.

Parameters
conditionThe condition to be inspected
Exceptions
TrueExceptionThrown when the condition is false

◆ True() [3/4]

static void Xunit.Assert.True ( bool  condition,
string  userMessage 
)
inlinestatic

Verifies that an expression is true.

Parameters
conditionThe condition to be inspected
userMessageThe message to be shown when the condition is false
Exceptions
TrueExceptionThrown when the condition is false

◆ True() [4/4]

static void Xunit.Assert.True ( bool?  condition,
string  userMessage 
)
inlinestatic

Verifies that an expression is true.

Parameters
conditionThe condition to be inspected
userMessageThe message to be shown when the condition is false
Exceptions
TrueExceptionThrown when the condition is false

The documentation for this class was generated from the following files: