Class NumericAssertExtensions
Provides fluent assertion extension methods for numeric values.
Inherited Members
Namespace: Benday.Common.Testing
Assembly: Benday.Common.Testing.dll
Syntax
public static class NumericAssertExtensions
Methods
| Edit this page View SourceShouldBeApproximatelyEqualTo(decimal, decimal, decimal, string)
Verifies that two decimal values are approximately equal within the specified tolerance.
Declaration
public static decimal ShouldBeApproximatelyEqualTo(this decimal actual, decimal expected, decimal tolerance, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| decimal | actual | The actual value. |
| decimal | expected | The expected value. |
| decimal | tolerance | The tolerance for comparison. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| decimal | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the values are not approximately equal. |
ShouldBeApproximatelyEqualTo(double, double, double, string)
Verifies that two floating-point values are approximately equal within the specified tolerance.
Declaration
public static double ShouldBeApproximatelyEqualTo(this double actual, double expected, double tolerance, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| double | actual | The actual value. |
| double | expected | The expected value. |
| double | tolerance | The tolerance for comparison. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| double | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the values are not approximately equal. |
ShouldBeApproximatelyEqualTo(float, float, float, string)
Verifies that two floating-point values are approximately equal within the specified tolerance.
Declaration
public static float ShouldBeApproximatelyEqualTo(this float actual, float expected, float tolerance, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| float | actual | The actual value. |
| float | expected | The expected value. |
| float | tolerance | The tolerance for comparison. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| float | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the values are not approximately equal. |
ShouldBeFinite(double, string)
Verifies that a double value is finite (not infinity or NaN).
Declaration
public static double ShouldBeFinite(this double actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| double | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| double | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is not finite. |
ShouldBeFinite(float, string)
Verifies that a float value is finite (not infinity or NaN).
Declaration
public static float ShouldBeFinite(this float actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| float | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| float | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is not finite. |
ShouldBeGreaterThanOrEqualTo<T>(T, T, string)
Verifies that a value is greater than or equal to the specified minimum.
Declaration
public static T ShouldBeGreaterThanOrEqualTo<T>(this T actual, T minimum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | minimum | The minimum value (inclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is not greater than or equal to the minimum. |
ShouldBeGreaterThan<T>(T, T, string)
Verifies that a value is greater than the specified minimum.
Declaration
public static T ShouldBeGreaterThan<T>(this T actual, T minimum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | minimum | The minimum value (exclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is not greater than the minimum. |
ShouldBeInRange<T>(T, T, T, string)
Verifies that a value is within the specified range (inclusive).
Declaration
public static T ShouldBeInRange<T>(this T actual, T minimum, T maximum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | minimum | The minimum value (inclusive). |
| T | maximum | The maximum value (inclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is not within the range. |
ShouldBeLessThanOrEqualTo<T>(T, T, string)
Verifies that a value is less than or equal to the specified maximum.
Declaration
public static T ShouldBeLessThanOrEqualTo<T>(this T actual, T maximum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | maximum | The maximum value (inclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is not less than or equal to the maximum. |
ShouldBeLessThan<T>(T, T, string)
Verifies that a value is less than the specified maximum.
Declaration
public static T ShouldBeLessThan<T>(this T actual, T maximum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | maximum | The maximum value (exclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is not less than the maximum. |
ShouldBeNegative<T>(T, string)
Verifies that a value is negative (less than zero).
Declaration
public static T ShouldBeNegative<T>(this T actual, string message) where T : IComparable<T>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is not negative. |
ShouldBePositive<T>(T, string)
Verifies that a value is positive (greater than zero).
Declaration
public static T ShouldBePositive<T>(this T actual, string message) where T : IComparable<T>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is not positive. |
ShouldBeZero<T>(T, string)
Verifies that a value is zero.
Declaration
public static T ShouldBeZero<T>(this T actual, string message) where T : IComparable<T>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is not zero. |
ShouldNotBeInRange<T>(T, T, T, string)
Verifies that a value is not within the specified range (inclusive).
Declaration
public static T ShouldNotBeInRange<T>(this T actual, T minimum, T maximum, string message) where T : IComparable<T>
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| T | minimum | The minimum value (inclusive). |
| T | maximum | The maximum value (inclusive). |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of values to compare. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the actual value is within the range. |
ShouldNotBeNaN(double, string)
Verifies that a double value is not NaN (Not a Number).
Declaration
public static double ShouldNotBeNaN(this double actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| double | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| double | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is NaN. |
ShouldNotBeNaN(float, string)
Verifies that a float value is not NaN (Not a Number).
Declaration
public static float ShouldNotBeNaN(this float actual, string message)
Parameters
| Type | Name | Description |
|---|---|---|
| float | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| float | The actual value for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is NaN. |
ShouldNotBeZero<T>(T, string)
Verifies that a value is not zero.
Declaration
public static T ShouldNotBeZero<T>(this T actual, string message) where T : IComparable<T>, new()
Parameters
| Type | Name | Description |
|---|---|---|
| T | actual | The actual value. |
| string | message | The message to display if the assertion fails. |
Returns
| Type | Description |
|---|---|
| T | The actual value for method chaining. |
Type Parameters
| Name | Description |
|---|---|
| T | The type of the value. |
Exceptions
| Type | Condition |
|---|---|
| AssertionException | Thrown when the value is zero. |