Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Public Types | Public static fields | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
Loyc.MiniTest.Assert Class Reference

The Assert class contains a collection of static methods that mirror the most common assertions used in NUnit. More...


Source file:
Inheritance diagram for Loyc.MiniTest.Assert:
Loyc.Collections.Impl.TestHelpers

Remarks

The Assert class contains a collection of static methods that mirror the most common assertions used in NUnit.

WORK IN PROGRESS. TEST RUNNER IS NOT FINISHED YET.

This class is mostly a drop-in replacement for "old-style" NUnit tests, i.e. those that do not use constraint classes or the "Is" class.

Some methods were dropped to keep this class small. Use the full NUnit framework if the remaining methods are not sufficient for you.

Public Types

enum  StopReason {
  Success, Fail, Ignore,
  Inconclusive
}
 

Public static fields

static ThreadLocalVariable
< StopTestDelegate > 
StopTestHandler = new ThreadLocalVariable<StopTestDelegate>(ThrowException)
 

Public Member Functions

delegate void StopTestDelegate (StopReason reason, string format, params object[] args)
 

Static Public Member Functions

static void Fail (string format, params object[] args)
 Fails a test via StopTestHandler, which, by default, throws an AssertionException. More...
 
static void Fail (string message)
 Fails a test by invoking StopTestHandler.Value(), which, by default, throws an AssertionException. More...
 
static void Ignore (string format, params object[] args)
 Stops a test via StopTestHandler, which, by default, throws an IgnoreException. This causes the test to be reported as ignored. More...
 
static void Inconclusive (string format, params object[] args)
 Stops a test via StopTestHandler, which, by default, throws an InconclusiveException. This causes the test to be reported as inconclusive. More...
 
static void Success (string format, params object[] args)
 Stops a test via StopTestHandler, which, by default, throws a SuccessException. More...
 
static void Fail ()
 Short for Fail(""). More...
 
static void Ignore ()
 Short for Ignore(""). More...
 
static void Inconclusive ()
 Short for Inconclusive(""). More...
 
static void Success ()
 Short for Success(""). More...
 
static new void Equals (object a, object b)
 Equals() is inherited from object; you probably want to call AreEqual instead. More...
 
static new void ReferenceEquals (object a, object b)
 Verifies that two references are equal. More...
 
static void That (bool condition, string message, params object[] args)
 Calls Fail(message, args) if condition is false. More...
 
static void That (bool condition, string message)
 Calls Fail(message) if condition is false. More...
 
static void That (bool condition)
 Calls Fail() if condition is false. More...
 
static void Expect (bool condition)
 Calls Fail() if condition is false. More...
 
static Exception Throws (Type expectedExceptionType, Action code, string message, params object[] args)
 Verifies that a delegate throws a particular exception when called. More...
 
static Exception Throws (Type expectedExceptionType, Action code)
 
static T Throws< T > (Action code, string message, params object[] args)
 
static T Throws< T > (Action code)
 
static Exception Catch (Action code, string message, params object[] args)
 Verifies that a delegate throws an exception when called and returns it. More...
 
static Exception Catch (Action code)
 Verifies that a delegate throws an exception when called and returns it. More...
 
static void DoesNotThrow (Action code, string message, params object[] args)
 Verifies that a delegate does not throw an exception More...
 
static void DoesNotThrow (Action code)
 Verifies that a delegate does not throw an exception. More...
 
static void IsTrue (bool condition, string message, params object[] args)
 
static void IsTrue (bool condition)
 
static void IsFalse (bool condition, string message, params object[] args)
 
static void IsFalse (bool condition)
 
static void IsNotNull (object anObject, string message, params object[] args)
 
static void IsNotNull (object anObject)
 
static void IsNull (object anObject, string message, params object[] args)
 
static void IsNull (object anObject)
 
static void IsNaN (double aDouble)
 
static void IsEmpty (string aString)
 
static void IsEmpty (System.Collections.IEnumerable collection)
 
static void IsNotEmpty (System.Collections.IEnumerable collection)
 
static void IsNullOrEmpty (string aString)
 
static void IsNotNullOrEmpty (string aString)
 
static void IsInstanceOf (Type expected, object actual)
 
static void IsNotInstanceOf (Type expected, object actual)
 
static void IsInstanceOf< T > (object actual)
 
static void IsNotInstanceOf< T > (object actual)
 
static void AreEqual (long expected, long actual, string message, params object[] args)
 
static void AreEqual (ulong expected, ulong actual, string message, params object[] args)
 
static void AreEqual (int expected, int actual)
 
static void AreEqual (long expected, long actual)
 
static void AreEqual (ulong expected, ulong actual)
 
static void AreEqual (decimal expected, decimal actual)
 
static void AreEqual (double expected, double actual, double delta, string message, params object[] args)
 
static void AreEqual (double expected, double actual, double delta)
 
static void AreEqual (double expected, double actual)
 
static void AreEqual (object expected, object actual, string message, params object[] args)
 
static void AreEqual (object expected, object actual)
 
static void AreNotEqual (long expected, long actual, string message, params object[] args)
 
static void AreNotEqual (ulong expected, ulong actual, string message, params object[] args)
 
static void AreNotEqual (int expected, int actual)
 
static void AreNotEqual (long expected, long actual)
 
static void AreNotEqual (ulong expected, ulong actual)
 
static void AreNotEqual (decimal expected, decimal actual)
 
static void AreNotEqual (double expected, double actual, double delta, string message, params object[] args)
 
static void AreNotEqual (double expected, double actual, double delta)
 
static void AreNotEqual (object expected, object actual, string message, params object[] args)
 
static void AreNotEqual (object expected, object actual)
 
static void AreSame (object expected, object actual, string message, params object[] args)
 
static void AreSame (object expected, object actual)
 
static void AreNotSame (object expected, object actual, string message, params object[] args)
 
static void AreNotSame (object expected, object actual)
 
static void Greater (long arg1, long arg2, string message, params object[] args)
 
static void Greater (double arg1, double arg2, string message, params object[] args)
 
static void Greater (IComparable arg1, IComparable arg2, string message, params object[] args)
 
static void Greater (int arg1, int arg2)
 
static void Greater (long arg1, long arg2)
 
static void Greater (double arg1, double arg2)
 
static void Greater (IComparable arg1, IComparable arg2)
 
static void Less (long arg1, long arg2, string message, params object[] args)
 
static void Less (double arg1, double arg2, string message, params object[] args)
 
static void Less (IComparable arg1, IComparable arg2, string message, params object[] args)
 
static void Less (int arg1, int arg2)
 
static void Less (long arg1, long arg2)
 
static void Less (double arg1, double arg2)
 
static void Less (IComparable arg1, IComparable arg2)
 
static void GreaterOrEqual (long arg1, long arg2, string message, params object[] args)
 
static void GreaterOrEqual (double arg1, double arg2, string message, params object[] args)
 
static void GreaterOrEqual (IComparable arg1, IComparable arg2, string message, params object[] args)
 
static void GreaterOrEqual (int arg1, int arg2)
 
static void GreaterOrEqual (long arg1, long arg2)
 
static void GreaterOrEqual (double arg1, double arg2)
 
static void GreaterOrEqual (IComparable arg1, IComparable arg2)
 
static void LessOrEqual (long arg1, long arg2, string message, params object[] args)
 
static void LessOrEqual (double arg1, double arg2, string message, params object[] args)
 
static void LessOrEqual (IComparable arg1, IComparable arg2, string message, params object[] args)
 
static void LessOrEqual (int arg1, int arg2)
 
static void LessOrEqual (long arg1, long arg2)
 
static void LessOrEqual (double arg1, double arg2)
 
static void LessOrEqual (IComparable arg1, IComparable arg2)
 
static void Contains (object expected, IEnumerable actual, string message, params object[] args)
 Asserts that an object is contained in a list. More...
 
static void Contains (object expected, IEnumerable actual)
 Asserts that an object is contained in a list. More...
 

Protected Member Functions

 Assert ()
 You may find it useful to derive a test fixture from Assert so that you do not need to prefix every test with "Assert." More...
 

Static Protected Member Functions

static void ThrowException (StopReason reason, string format, params object[] args)
 
static bool DoublesAreEqual (double expected, double actual, double delta)
 

Constructor & Destructor Documentation

Loyc.MiniTest.Assert.Assert ( )
inlineprotected

You may find it useful to derive a test fixture from Assert so that you do not need to prefix every test with "Assert."

Member Function Documentation

static Exception Loyc.MiniTest.Assert.Catch ( Action  code,
string  message,
params object[]  args 
)
inlinestatic

Verifies that a delegate throws an exception when called and returns it.

Parameters
codeA method to run
messageThe message that will be displayed on failure
argsArguments to be used in formatting the message
static Exception Loyc.MiniTest.Assert.Catch ( Action  code)
inlinestatic

Verifies that a delegate throws an exception when called and returns it.

Parameters
codeA TestDelegate
static void Loyc.MiniTest.Assert.Contains ( object  expected,
IEnumerable  actual,
string  message,
params object[]  args 
)
inlinestatic

Asserts that an object is contained in a list.

Parameters
expectedThe expected object
actualThe list to be examined
messageThe message to display in case of failure
argsArray of objects to be used in formatting the message
static void Loyc.MiniTest.Assert.Contains ( object  expected,
IEnumerable  actual 
)
inlinestatic

Asserts that an object is contained in a list.

Parameters
expectedThe expected object
actualThe list to be examined
static void Loyc.MiniTest.Assert.DoesNotThrow ( Action  code,
string  message,
params object[]  args 
)
inlinestatic

Verifies that a delegate does not throw an exception

Parameters
codeCode to run
messageThe message that will be displayed on failure
static void Loyc.MiniTest.Assert.DoesNotThrow ( Action  code)
inlinestatic

Verifies that a delegate does not throw an exception.

Parameters
codeCode to run
static new void Loyc.MiniTest.Assert.Equals ( object  a,
object  b 
)
inlinestatic

Equals() is inherited from object; you probably want to call AreEqual instead.

static void Loyc.MiniTest.Assert.Expect ( bool  condition)
inlinestatic

Calls Fail() if condition is false.

static void Loyc.MiniTest.Assert.Fail ( string  format,
params object[]  args 
)
inlinestatic

Fails a test via StopTestHandler, which, by default, throws an AssertionException.

static void Loyc.MiniTest.Assert.Fail ( string  message)
inlinestatic

Fails a test by invoking StopTestHandler.Value(), which, by default, throws an AssertionException.

static void Loyc.MiniTest.Assert.Fail ( )
inlinestatic

Short for Fail("").

static void Loyc.MiniTest.Assert.Ignore ( string  format,
params object[]  args 
)
inlinestatic

Stops a test via StopTestHandler, which, by default, throws an IgnoreException. This causes the test to be reported as ignored.

static void Loyc.MiniTest.Assert.Ignore ( )
inlinestatic

Short for Ignore("").

static void Loyc.MiniTest.Assert.Inconclusive ( string  format,
params object[]  args 
)
inlinestatic

Stops a test via StopTestHandler, which, by default, throws an InconclusiveException. This causes the test to be reported as inconclusive.

static void Loyc.MiniTest.Assert.Inconclusive ( )
inlinestatic

Short for Inconclusive("").

static new void Loyc.MiniTest.Assert.ReferenceEquals ( object  a,
object  b 
)
inlinestatic

Verifies that two references are equal.

static void Loyc.MiniTest.Assert.Success ( string  format,
params object[]  args 
)
inlinestatic

Stops a test via StopTestHandler, which, by default, throws a SuccessException.

static void Loyc.MiniTest.Assert.Success ( )
inlinestatic

Short for Success("").

static void Loyc.MiniTest.Assert.That ( bool  condition,
string  message,
params object[]  args 
)
inlinestatic

Calls Fail(message, args) if condition is false.

static void Loyc.MiniTest.Assert.That ( bool  condition,
string  message 
)
inlinestatic

Calls Fail(message) if condition is false.

static void Loyc.MiniTest.Assert.That ( bool  condition)
inlinestatic

Calls Fail() if condition is false.

static Exception Loyc.MiniTest.Assert.Throws ( Type  expectedExceptionType,
Action  code,
string  message,
params object[]  args 
)
inlinestatic

Verifies that a delegate throws a particular exception when called.

Parameters
expectedExceptionTypeThe exception Type expected
codeA method to run
messageThe message that will be displayed on failure
argsArguments to be used in formatting the message