Class Asserts
Provides assertion helpers for validating conditions and values.
public static class Asserts
- Inheritance
-
Asserts
- Inherited Members
Methods
Default<T>(T, string)
Asserts that the specified value is equal to its default value.
public static void Default<T>(T value, string expression = "")
Parameters
valueTThe value to evaluate.
expressionstringThe expression text of the asserted value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
valueis not the default value.
Equal<T>(T, T, string, string)
Asserts that two values are equal.
public static void Equal<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "")
Parameters
actualTThe actual value.
expectedTThe expected value.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualandexpectedare not equal.
False(bool, string)
Asserts that the specified condition is false.
public static void False(bool condition, string expression = "")
Parameters
conditionboolThe condition to evaluate.
expressionstringThe expression text of the asserted condition.
Exceptions
- AssertionException
Thrown when
conditionis true.
GreaterThanOrEqual<T>(T, T, string, string)
Asserts that the actual value is greater than or equal to the expected value.
public static void GreaterThanOrEqual<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "") where T : IComparisonOperators<T, T, bool>
Parameters
actualTThe actual value.
expectedTThe value that the actual value must be greater than or equal to.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualis less thanexpected.
GreaterThan<T>(T, T, string, string)
Asserts that the actual value is greater than the expected value.
public static void GreaterThan<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "") where T : IComparisonOperators<T, T, bool>
Parameters
actualTThe actual value.
expectedTThe value that the actual value must be greater than.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualis not greater thanexpected.
LessThanOrEqual<T>(T, T, string, string)
Asserts that the actual value is less than or equal to the expected value.
public static void LessThanOrEqual<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "") where T : IComparisonOperators<T, T, bool>
Parameters
actualTThe actual value.
expectedTThe value that the actual value must be less than or equal to.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualis greater thanexpected.
LessThan<T>(T, T, string, string)
Asserts that the actual value is less than the expected value.
public static void LessThan<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "") where T : IComparisonOperators<T, T, bool>
Parameters
actualTThe actual value.
expectedTThe value that the actual value must be less than.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualis not less thanexpected.
NotDefault<T>(T, string)
Asserts that the specified value is not equal to its default value.
public static void NotDefault<T>(T value, string expression = "")
Parameters
valueTThe value to evaluate.
expressionstringThe expression text of the asserted value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
valueis the default value.
NotEqual<T>(T, T, string, string)
Asserts that two values are not equal.
public static void NotEqual<T>(T actual, T expected, string actualExpression = "", string expectedExpression = "")
Parameters
actualTThe actual value.
expectedTThe value that should not match the actual value.
actualExpressionstringThe expression text of the actual value.
expectedExpressionstringThe expression text of the expected value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
actualandexpectedare equal.
NotNull<T>(T?, string)
Asserts that the specified value is not null.
public static void NotNull<T>(T? value, string expression = "")
Parameters
valueTThe value to evaluate.
expressionstringThe expression text of the asserted value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
valueis null.
Null<T>(T?, string)
Asserts that the specified value is null.
public static void Null<T>(T? value, string expression = "")
Parameters
valueTThe value to evaluate.
expressionstringThe expression text of the asserted value.
Type Parameters
TThe value type.
Exceptions
- AssertionException
Thrown when
valueis not null.
OfType<T>(object?, string)
Asserts that the specified value is of the specified type.
public static T OfType<T>(object? value, string expression = "")
Parameters
Returns
- T
Type Parameters
TThe expected type.
Exceptions
- AssertionException
Thrown when
valueis not of typeT.
True(bool, string)
Asserts that the specified condition is true.
public static void True(bool condition, string expression = "")
Parameters
conditionboolThe condition to evaluate.
expressionstringThe expression text of the asserted condition.
Exceptions
- AssertionException
Thrown when
conditionis false.