Generic Assertions

These assertion extension methods can be applied to any type of object.

ShouldEqual

Asserts that this object is equal to another object.

Usage

public static T ShouldEqual<T>(this T source, T comparer)
public static T ShouldEqual<T>(this T source, T comparer, string message)
public static T ShouldEqual<T>(this T source, T comparer, string message, params object[] parameters)

Example

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

ShouldNotEqual

Asserts that this object is not equal to another object.

Usage

public static T ShouldNotEqual<T>(this T source, T comparer)
public static T ShouldNotEqual<T>(this T source, T comparer, string message)
public static T ShouldNotEqual<T>(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int number = 5;
   number.ShouldNotEqual(4);
   
   string foo = "foo";
   foo.ShouldNotEqual("bar");
}
Supported Releases: All

ShouldBeSameAs

Asserts that this object has the same reference as another object.

Usage

public static T ShouldBeSameAs<T>(this T source, T comparer)
public static T ShouldBeSameAs<T>(this T source, T comparer, string message)
public static T ShouldBeSameAs<T>(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int i = 4;
   object firstObject = i;
   object secondObject = firstObject;

   firstObject.ShouldBeSameAs(secondObject);
}
Supported Releases: All


ShouldNotBeSameAs

Asserts that this object does not have the same reference as another object.

Usage

public static T ShouldNotBeSameAs<T>(this T source, T comparer)
public static T ShouldNotBeSameAs<T>(this T source, T comparer, string message)
public static T ShouldNotBeSameAs<T>(this T source, T comparer, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   int i = 4;
   object firstObject = i;
   object secondObject = i;

   firstObject.ShouldNotBeSameAs(secondObject);
}
Supported Releases: All

ShouldBeNull

Asserts that this object is null.

Usage

public static T ShouldBeNull<T>(this T source)
public static T ShouldBeNull<T>(this T source, string message)
public static T ShouldBeNull<T>(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   object foo = null;
   foo.ShouldBeNull();
}
Supported Releases: All

ShouldNotBeNull

Asserts that this object is not null.

Usage

public static T ShouldNotBeNull<T>(this T source)
public static T ShouldNotBeNull<T>(this T source, string message)
public static T ShouldNotBeNull<T>(this T source, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   object foo = new object();
   foo.ShouldNotBeNull();
}
Supported Releases: All

ShouldBeOfType

Asserts that this object is a certain type.

Usage

public static T ShouldBeOfType<T>(this T source, Type type)
public static T ShouldBeOfType<T>(this T source, Type type, string message)
public static T ShouldBeOfType<T>(this T source, Type type, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   false.ShouldBeOfType(typeof(bool));
   "foo".ShouldBeOfType(typeof(string));
}
Supported Releases: All

ShouldNotBeOfType

Asserts that this object is not a certain type.

Usage

public static T ShouldNotBeOfType<T>(this T source, Type type)
public static T ShouldNotBeOfType<T>(this T source, Type type, string message)
public static T ShouldNotBeOfType<T>(this T source, Type type, string message, params object[] parameters)

Example

[TestMethod]
public void Test()
{
   false.ShouldNotBeOfType(typeof(string));
   "foo".ShouldNotBeOfType(typeof(bool));
}
Supported Releases: All

Last edited Dec 9, 2010 at 2:46 PM by jeremiahclark, version 5

Comments

No comments yet.