Numeric Assertions

These assertion extension methods can be applied to only numeric object types (including char for the purposes of the documentation).

ShouldBeGreaterThan

Asserts that this value is greater than a certain value.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldBeGreaterThan(this T source, T comparer)
public static T ShouldBeGreaterThan(this T source, T comparer, string message)
public static T ShouldBeGreaterThan(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBeGreaterThan(4);
}
Supported Releases: All

ShouldBeGreaterThanOrEqualTo

Asserts that this value is greater than or equal to a certain value.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldBeGreaterThanOrEqualTo(this T source, T comparer)
public static T ShouldBeGreaterThanOrEqualTo(this T source, T comparer, string message)
public static T ShouldBeGreaterThanOrEqualTo(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBeGreaterThanOrEqualTo(4);
   number.ShouldBeGreaterThanOrEqualTo(5);
}
Supported Releases: All


ShouldBeLessThan

Asserts that this value is less than a certain value.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldBeLessThan(this T source, T comparer)
public static T ShouldBeLessThan(this T source, T comparer, string message)
public static T ShouldBeLessThan(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBeLessThan(6);
}
Supported Releases: All

ShouldBeLessThanOrEqualTo

Asserts that this value is less than or equal to a certain value.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldBeLessThanOrEqualTo(this T source, T comparer)
public static T ShouldBeLessThanOrEqualTo(this T source, T comparer, string message)
public static T ShouldBeLessThanOrEqualTo(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBeLessThanOrEqualTo(5);
   number.ShouldBeLessThanOrEqualTo(6);
}
Supported Releases: All

ShouldBeBetween

Asserts that this value is between two values.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldBeBetween(this T source, T lowerInclusive, T upperInclusive)
public static T ShouldBeBetween(this T source, T lowerInclusive, T upperInclusive, string message)
public static T ShouldBeBetween(this T source, T lowerInclusive, T upperInclusive, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBeBetween(4, 6);
}
Supported Releases: All

ShouldNotBeBetween

Asserts that this value is not between two values.

Usage

Where T is: short, int, long, ushort, uint, ulong, byte, sbyte, char, float, double, or decimal
public static T ShouldNotBeBetween(this T source, T lowerExclusive, T upperExclusive)
public static T ShouldNotBeBetween(this T source, T lowerExclusive, T upperExclusive, string message)
public static T ShouldNotBeBetween(this T source, T lowerExclusive, T upperExclusive, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldNotBeBetween(6, 9);
}
Supported Releases: All

ShouldBePositive

Asserts that this value is positive or zero.

Usage

Where T is: short, int, long, sbyte, float, double, or decimal
public static T ShouldBePositive(this T source)
public static T ShouldBePositive(this T source, string message)
public static T ShouldBePositive(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldBePositive();
}
Supported Releases: All

ShouldBeNegative

Asserts that this value is negative.

Usage

Where T is: short, int, long, sbyte, float, double, or decimal
public static T ShouldBeNegative(this T source)
public static T ShouldBeNegative(this T source, string message)
public static T ShouldBeNegative(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = -5;
   number.ShouldBeNegative();
}
Supported Releases: All

ShouldBeIntegral

Asserts that this value is integral (does not have a fractional component).

Usage

Where T is: float, double, or decimal
public static T ShouldBeIntegral(this T source)
public static T ShouldBeIntegral(this T source, string message)
public static T ShouldBeIntegral(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   double number = 3.0;
   number.ShouldBeIntegral();
}
Supported Releases: All

ShouldBeFractional

Asserts that this value is has a fractional component.

Usage

Where T is: float, double, or decimal
public static T ShouldBeFractional(this T source)
public static T ShouldBeFractional(this T source, string message)
public static T ShouldBeFractional(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   double number = 3.34;
   number.ShouldBeFractional();
}
Supported Releases: All

ShouldRoundTo

Asserts that this value rounds to a specified value.

Usage

Where T is: float, double, or decimal
public static T ShouldRoundTo(this T source, T comparer)
public static T ShouldRoundTo(this T source, T comparer, string message)
public static T ShouldRoundTo(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   double number = 3.34;
   number.ShouldRoundTo(3);
}
Supported Releases: All

Last edited Dec 9, 2010 at 2:50 PM by jeremiahclark, version 3

Comments

No comments yet.