/src/NUnit.Silverlight.Framework/Assert.cs
C# | 3789 lines | 1384 code | 384 blank | 2021 comment | 30 complexity | 1ff03d0813cd4880e65ee6333c1ea8ed MD5 | raw file
Large files files are truncated, but you can click here to view the full file
- // ****************************************************************
- // Copyright 2009, Charlie Poole
- // This is free software licensed under the NUnit license. You may
- // obtain a copy of the license at http://nunit.org
- // ****************************************************************
-
- // ****************************************************************
- // Generated by the NUnit Syntax Generator
- //
- // Command Line: GenSyntax.exe SyntaxElements.txt
- //
- // DO NOT MODIFY THIS FILE DIRECTLY
- // ****************************************************************
-
- using System;
- using System.Collections;
- using System.ComponentModel;
- using NUnit.Framework.Constraints;
-
- namespace NUnit.Framework
- {
- /// <summary>
- /// Delegate used by tests that execute code and
- /// capture any thrown exception.
- /// </summary>
- public delegate void TestDelegate();
-
- /// <summary>
- /// The Assert class contains a collection of static methods that
- /// implement the most common assertions used in NUnit.
- /// </summary>
- public class Assert
- {
- #region Constructor
-
- /// <summary>
- /// We don't actually want any instances of this object, but some people
- /// like to inherit from it to add other static methods. Hence, the
- /// protected constructor disallows any instances of this object.
- /// </summary>
- protected Assert() { }
-
- #endregion
-
- #region Assert Counting
-
- private static int counter = 0;
-
- /// <summary>
- /// Gets the number of assertions executed so far and
- /// resets the counter to zero.
- /// </summary>
- public static int Counter
- {
- get
- {
- int cnt = counter;
- counter = 0;
- return cnt;
- }
- }
-
- private static void IncrementAssertCount()
- {
- ++counter;
- }
-
- #endregion
-
- #region Equals and ReferenceEquals
-
- /// <summary>
- /// The Equals method throws an AssertionException. This is done
- /// to make sure there is no mistake by calling this function.
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- [EditorBrowsable(EditorBrowsableState.Never)]
- public static new bool Equals(object a, object b)
- {
- // TODO: This should probably be InvalidOperationException
- throw new AssertionException("Assert.Equals should not be used for Assertions");
- }
-
- /// <summary>
- /// override the default ReferenceEquals to throw an AssertionException. This
- /// implementation makes sure there is no mistake in calling this function
- /// as part of Assert.
- /// </summary>
- /// <param name="a"></param>
- /// <param name="b"></param>
- public static new void ReferenceEquals(object a, object b)
- {
- throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions");
- }
-
- #endregion
-
- #region Helper Methods
- /// <summary>
- /// Helper for Assert.AreEqual(double expected, double actual, ...)
- /// allowing code generation to work consistently.
- /// </summary>
- /// <param name="expected">The expected value</param>
- /// <param name="actual">The actual value</param>
- /// <param name="delta">The maximum acceptable difference between the
- /// the expected and the actual</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- protected static void AssertDoublesAreEqual(double expected, double actual, double delta, string message, object[] args)
- {
- if (double.IsNaN(expected) || double.IsInfinity(expected))
- Assert.That(actual, Is.EqualTo(expected), message, args);
- else
- Assert.That(actual, Is.EqualTo(expected).Within(delta), message, args);
- }
- #endregion
-
- #region Utility Asserts
-
- #region Pass
-
- /// <summary>
- /// Throws a <see cref="SuccessException"/> with the message and arguments
- /// that are passed in. This allows a test to be cut short, with a result
- /// of success returned to NUnit.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void Pass(string message, params object[] args)
- {
- if (message == null) message = string.Empty;
- else if (args != null && args.Length > 0)
- message = string.Format(message, args);
-
- throw new SuccessException(message);
- }
-
- /// <summary>
- /// Throws a <see cref="SuccessException"/> with the message and arguments
- /// that are passed in. This allows a test to be cut short, with a result
- /// of success returned to NUnit.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- static public void Pass(string message)
- {
- Assert.Pass(message, null);
- }
-
- /// <summary>
- /// Throws a <see cref="SuccessException"/> with the message and arguments
- /// that are passed in. This allows a test to be cut short, with a result
- /// of success returned to NUnit.
- /// </summary>
- static public void Pass()
- {
- Assert.Pass(string.Empty, null);
- }
-
- #endregion
-
- #region Fail
-
- /// <summary>
- /// Throws an <see cref="AssertionException"/> with the message and arguments
- /// that are passed in. This is used by the other Assert functions.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void Fail(string message, params object[] args)
- {
- if (message == null) message = string.Empty;
- else if (args != null && args.Length > 0)
- message = string.Format(message, args);
-
- throw new AssertionException(message);
- }
-
- /// <summary>
- /// Throws an <see cref="AssertionException"/> with the message that is
- /// passed in. This is used by the other Assert functions.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- static public void Fail(string message)
- {
- Assert.Fail(message, null);
- }
-
- /// <summary>
- /// Throws an <see cref="AssertionException"/>.
- /// This is used by the other Assert functions.
- /// </summary>
- static public void Fail()
- {
- Assert.Fail(string.Empty, null);
- }
-
- #endregion
-
- #region Ignore
-
- /// <summary>
- /// Throws an <see cref="IgnoreException"/> with the message and arguments
- /// that are passed in. This causes the test to be reported as ignored.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void Ignore(string message, params object[] args)
- {
- if (message == null) message = string.Empty;
- else if (args != null && args.Length > 0)
- message = string.Format(message, args);
-
- throw new IgnoreException(message);
- }
-
- /// <summary>
- /// Throws an <see cref="IgnoreException"/> with the message that is
- /// passed in. This causes the test to be reported as ignored.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="AssertionException"/> with.</param>
- static public void Ignore(string message)
- {
- Assert.Ignore(message, null);
- }
-
- /// <summary>
- /// Throws an <see cref="IgnoreException"/>.
- /// This causes the test to be reported as ignored.
- /// </summary>
- static public void Ignore()
- {
- Assert.Ignore(string.Empty, null);
- }
-
- #endregion
-
- #region InConclusive
- /// <summary>
- /// Throws an <see cref="InconclusiveException"/> with the message and arguments
- /// that are passed in. This causes the test to be reported as inconclusive.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="InconclusiveException"/> with.</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void Inconclusive(string message, params object[] args)
- {
- if (message == null) message = string.Empty;
- else if (args != null && args.Length > 0)
- message = string.Format(message, args);
-
- throw new InconclusiveException(message);
- }
-
- /// <summary>
- /// Throws an <see cref="InconclusiveException"/> with the message that is
- /// passed in. This causes the test to be reported as inconclusive.
- /// </summary>
- /// <param name="message">The message to initialize the <see cref="InconclusiveException"/> with.</param>
- static public void Inconclusive(string message)
- {
- Assert.Inconclusive(message, null);
- }
-
- /// <summary>
- /// Throws an <see cref="InconclusiveException"/>.
- /// This causes the test to be reported as Inconclusive.
- /// </summary>
- static public void Inconclusive()
- {
- Assert.Inconclusive(string.Empty, null);
- }
-
- #endregion
-
- #endregion
-
- #region Assert.That
-
- #region Object
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- static public void That(object actual, IResolveConstraint expression)
- {
- Assert.That(actual, expression, null, null);
- }
-
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- static public void That(object actual, IResolveConstraint expression, string message)
- {
- Assert.That(actual, expression, message, null);
- }
-
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint expression to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void That(object actual, IResolveConstraint expression, string message, params object[] args)
- {
- Constraint constraint = expression.Resolve();
-
- Assert.IncrementAssertCount();
- if (!constraint.Matches(actual))
- {
- MessageWriter writer = new TextMessageWriter(message, args);
- constraint.WriteMessageTo(writer);
- throw new AssertionException(writer.ToString());
- }
- }
- #endregion
-
- #region ActualValueDelegate
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expr">A Constraint expression to be applied</param>
- /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
- static public void That(ActualValueDelegate del, IResolveConstraint expr)
- {
- Assert.That(del, expr.Resolve(), null, null);
- }
-
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expr">A Constraint expression to be applied</param>
- /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
- /// <param name="message">The message that will be displayed on failure</param>
- static public void That(ActualValueDelegate del, IResolveConstraint expr, string message)
- {
- Assert.That(del, expr.Resolve(), message, null);
- }
-
- /// <summary>
- /// Apply a constraint to an actual value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="del">An ActualValueDelegate returning the value to be tested</param>
- /// <param name="expr">A Constraint expression to be applied</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void That(ActualValueDelegate del, IResolveConstraint expr, string message, params object[] args)
- {
- Constraint constraint = expr.Resolve();
-
- Assert.IncrementAssertCount();
- if (!constraint.Matches(del))
- {
- MessageWriter writer = new TextMessageWriter(message, args);
- constraint.WriteMessageTo(writer);
- throw new AssertionException(writer.ToString());
- }
- }
- #endregion
-
- #region ref Object
- #if NET_2_0
- /// <summary>
- /// Apply a constraint to a referenced value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- static public void That<T>(ref T actual, IResolveConstraint expression)
- {
- Assert.That(ref actual, expression.Resolve(), null, null);
- }
-
- /// <summary>
- /// Apply a constraint to a referenced value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- static public void That<T>(ref T actual, IResolveConstraint expression, string message)
- {
- Assert.That(ref actual, expression.Resolve(), message, null);
- }
-
- /// <summary>
- /// Apply a constraint to a referenced value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="expression">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void That<T>(ref T actual, IResolveConstraint expression, string message, params object[] args)
- {
- Constraint constraint = expression.Resolve();
-
- Assert.IncrementAssertCount();
- if (!constraint.Matches(ref actual))
- {
- MessageWriter writer = new TextMessageWriter(message, args);
- constraint.WriteMessageTo(writer);
- throw new AssertionException(writer.ToString());
- }
- }
- #else
- /// <summary>
- /// Apply a constraint to a referenced boolean, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="constraint">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- static public void That(ref bool actual, IResolveConstraint constraint)
- {
- Assert.That(ref actual, constraint.Resolve(), null, null);
- }
-
- /// <summary>
- /// Apply a constraint to a referenced value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="constraint">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- static public void That(ref bool actual, IResolveConstraint constraint, string message)
- {
- Assert.That(ref actual, constraint.Resolve(), message, null);
- }
-
- /// <summary>
- /// Apply a constraint to a referenced value, succeeding if the constraint
- /// is satisfied and throwing an assertion exception on failure.
- /// </summary>
- /// <param name="constraint">A Constraint to be applied</param>
- /// <param name="actual">The actual value to test</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void That(ref bool actual, IResolveConstraint expression, string message, params object[] args)
- {
- Constraint constraint = expression.Resolve();
-
- Assert.IncrementAssertCount();
- if (!constraint.Matches(ref actual))
- {
- MessageWriter writer = new TextMessageWriter(message, args);
- constraint.WriteMessageTo(writer);
- throw new AssertionException(writer.ToString());
- }
- }
- #endif
- #endregion
-
- #region Boolean
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display if the condition is false</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- static public void That(bool condition, string message, params object[] args)
- {
- Assert.That(condition, Is.True, message, args);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display if the condition is false</param>
- static public void That(bool condition, string message)
- {
- Assert.That(condition, Is.True, message, null);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- static public void That(bool condition)
- {
- Assert.That(condition, Is.True, null, null);
- }
- #endregion
-
- /// <summary>
- /// Asserts that the code represented by a delegate throws an exception
- /// that satisfies the constraint provided.
- /// </summary>
- /// <param name="code">A TestDelegate to be executed</param>
- /// <param name="constraint">A ThrowsConstraint used in the test</param>
- static public void That(TestDelegate code, IResolveConstraint constraint)
- {
- Assert.That((object)code, constraint);
- }
- #endregion
-
- #region Throws, Catch and DoesNotThrow
-
- #region Throws
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expression">A constraint to be satisfied by the exception</param>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static Exception Throws(IResolveConstraint expression, TestDelegate code, string message, params object[] args)
- {
- Exception caughtException = null;
-
- try
- {
- code();
- }
- catch (Exception ex)
- {
- caughtException = ex;
- }
-
- Assert.That(caughtException, expression, message, args);
-
- return caughtException;
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expression">A constraint to be satisfied by the exception</param>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static Exception Throws(IResolveConstraint expression, TestDelegate code, string message)
- {
- return Throws(expression, code, message, null);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expression">A constraint to be satisfied by the exception</param>
- /// <param name="code">A TestSnippet delegate</param>
- public static Exception Throws(IResolveConstraint expression, TestDelegate code)
- {
- return Throws(expression, code, string.Empty, null);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expectedExceptionType">The exception Type expected</param>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static Exception Throws(Type expectedExceptionType, TestDelegate code, string message, params object[] args)
- {
- return Throws(new ExactTypeConstraint(expectedExceptionType), code, message, args);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expectedExceptionType">The exception Type expected</param>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static Exception Throws(Type expectedExceptionType, TestDelegate code, string message)
- {
- return Throws(new ExactTypeConstraint(expectedExceptionType), code, message, null);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <param name="expectedExceptionType">The exception Type expected</param>
- /// <param name="code">A TestSnippet delegate</param>
- public static Exception Throws(Type expectedExceptionType, TestDelegate code)
- {
- return Throws(new ExactTypeConstraint(expectedExceptionType), code, string.Empty, null);
- }
-
- #endregion
-
- #region Throws<T>
- #if NET_2_0
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <typeparam name="T">Type of the expected exception</typeparam>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static T Throws<T>(TestDelegate code, string message, params object[] args) where T : Exception
- {
- return (T)Throws(typeof(T), code, message, args);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <typeparam name="T">Type of the expected exception</typeparam>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static T Throws<T>(TestDelegate code, string message) where T : Exception
- {
- return Throws<T>(code, message, null);
- }
-
- /// <summary>
- /// Verifies that a delegate throws a particular exception when called.
- /// </summary>
- /// <typeparam name="T">Type of the expected exception</typeparam>
- /// <param name="code">A TestSnippet delegate</param>
- public static T Throws<T>(TestDelegate code) where T : Exception
- {
- return Throws<T>(code, string.Empty, null);
- }
- #endif
- #endregion
-
- #region Catch
- /// <summary>
- /// Verifies that a delegate throws an exception when called
- /// and returns it.
- /// </summary>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static Exception Catch(TestDelegate code, string message, params object[] args)
- {
- return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code, message, args);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception when called
- /// and returns it.
- /// </summary>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static Exception Catch(TestDelegate code, string message)
- {
- return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code, message);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception when called
- /// and returns it.
- /// </summary>
- /// <param name="code">A TestDelegate</param>
- public static Exception Catch(TestDelegate code)
- {
- return Throws(new InstanceOfTypeConstraint(typeof(Exception)), code);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <param name="expectedExceptionType">The expected Exception Type</param>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static Exception Catch(Type expectedExceptionType, TestDelegate code, string message, params object[] args)
- {
- return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code, message, args);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <param name="expectedExceptionType">The expected Exception Type</param>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static Exception Catch(Type expectedExceptionType, TestDelegate code, string message)
- {
- return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code, message);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <param name="expectedExceptionType">The expected Exception Type</param>
- /// <param name="code">A TestDelegate</param>
- public static Exception Catch(Type expectedExceptionType, TestDelegate code)
- {
- return Throws(new InstanceOfTypeConstraint(expectedExceptionType), code);
- }
- #endregion
-
- #region Catch<T>
- #if NET_2_0
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <typeparam name="T">The expected Exception Type</typeparam>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static T Catch<T>(TestDelegate code, string message, params object[] args) where T : System.Exception
- {
- return (T)Throws(new InstanceOfTypeConstraint(typeof(T)), code, message, args);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <typeparam name="T">The expected Exception Type</typeparam>
- /// <param name="code">A TestDelegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static T Catch<T>(TestDelegate code, string message) where T : System.Exception
- {
- return (T)Throws(new InstanceOfTypeConstraint(typeof(T)), code, message);
- }
-
- /// <summary>
- /// Verifies that a delegate throws an exception of a certain Type
- /// or one derived from it when called and returns it.
- /// </summary>
- /// <typeparam name="T">The expected Exception Type</typeparam>
- /// <param name="code">A TestDelegate</param>
- public static T Catch<T>(TestDelegate code) where T : System.Exception
- {
- return (T)Throws(new InstanceOfTypeConstraint(typeof(T)), code);
- }
- #endif
- #endregion
-
- #region DoesNotThrow
-
- /// <summary>
- /// Verifies that a delegate does not throw an exception
- /// </summary>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- /// <param name="args">Arguments to be used in formatting the message</param>
- public static void DoesNotThrow(TestDelegate code, string message, params object[] args)
- {
- try
- {
- code();
- }
- catch (Exception ex)
- {
- TextMessageWriter writer = new TextMessageWriter(message, args);
- writer.WriteLine("Unexpected exception: {0}", ex.GetType());
- Assert.Fail(writer.ToString());
- }
- }
-
- /// <summary>
- /// Verifies that a delegate does not throw an exception.
- /// </summary>
- /// <param name="code">A TestSnippet delegate</param>
- /// <param name="message">The message that will be displayed on failure</param>
- public static void DoesNotThrow(TestDelegate code, string message)
- {
- DoesNotThrow(code, message, null);
- }
-
- /// <summary>
- /// Verifies that a delegate does not throw an exception.
- /// </summary>
- /// <param name="code">A TestSnippet delegate</param>
- public static void DoesNotThrow(TestDelegate code)
- {
- DoesNotThrow(code, string.Empty, null);
- }
-
- #endregion
-
- #endregion
-
- #region True
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void True(bool condition, string message, params object[] args)
- {
- Assert.That(condition, Is.True, message, args);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void True(bool condition, string message)
- {
- Assert.That(condition, Is.True, message, null);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- public static void True(bool condition)
- {
- Assert.That(condition, Is.True, null, null);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsTrue(bool condition, string message, params object[] args)
- {
- Assert.That(condition, Is.True, message, args);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsTrue(bool condition, string message)
- {
- Assert.That(condition, Is.True, message, null);
- }
-
- /// <summary>
- /// Asserts that a condition is true. If the condition is false the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- public static void IsTrue(bool condition)
- {
- Assert.That(condition, Is.True, null, null);
- }
-
- #endregion
-
- #region False
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void False(bool condition, string message, params object[] args)
- {
- Assert.That(condition, Is.False, message, args);
- }
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void False(bool condition, string message)
- {
- Assert.That(condition, Is.False, message, null);
- }
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- public static void False(bool condition)
- {
- Assert.That(condition, Is.False, null, null);
- }
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsFalse(bool condition, string message, params object[] args)
- {
- Assert.That(condition, Is.False, message, args);
- }
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsFalse(bool condition, string message)
- {
- Assert.That(condition, Is.False, message, null);
- }
-
- /// <summary>
- /// Asserts that a condition is false. If the condition is true the method throws
- /// an <see cref="AssertionException"/>.
- /// </summary>
- /// <param name="condition">The evaluated condition</param>
- public static void IsFalse(bool condition)
- {
- Assert.That(condition, Is.False, null, null);
- }
-
- #endregion
-
- #region NotNull
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void NotNull(object anObject, string message, params object[] args)
- {
- Assert.That(anObject, Is.Not.Null, message, args);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void NotNull(object anObject, string message)
- {
- Assert.That(anObject, Is.Not.Null, message, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- public static void NotNull(object anObject)
- {
- Assert.That(anObject, Is.Not.Null, null, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsNotNull(object anObject, string message, params object[] args)
- {
- Assert.That(anObject, Is.Not.Null, message, args);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsNotNull(object anObject, string message)
- {
- Assert.That(anObject, Is.Not.Null, message, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is not equal to <code>null</code>
- /// If the object is <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- public static void IsNotNull(object anObject)
- {
- Assert.That(anObject, Is.Not.Null, null, null);
- }
-
- #endregion
-
- #region Null
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void Null(object anObject, string message, params object[] args)
- {
- Assert.That(anObject, Is.Null, message, args);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void Null(object anObject, string message)
- {
- Assert.That(anObject, Is.Null, message, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- public static void Null(object anObject)
- {
- Assert.That(anObject, Is.Null, null, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsNull(object anObject, string message, params object[] args)
- {
- Assert.That(anObject, Is.Null, message, args);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsNull(object anObject, string message)
- {
- Assert.That(anObject, Is.Null, message, null);
- }
-
- /// <summary>
- /// Verifies that the object that is passed in is equal to <code>null</code>
- /// If the object is not <code>null</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="anObject">The object that is to be tested</param>
- public static void IsNull(object anObject)
- {
- Assert.That(anObject, Is.Null, null, null);
- }
-
- #endregion
-
- #region IsNaN
-
- /// <summary>
- /// Verifies that the double that is passed in is an <code>NaN</code> value.
- /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="aDouble">The value that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsNaN(double aDouble, string message, params object[] args)
- {
- Assert.That(aDouble, Is.NaN, message, args);
- }
-
- /// <summary>
- /// Verifies that the double that is passed in is an <code>NaN</code> value.
- /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="aDouble">The value that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsNaN(double aDouble, string message)
- {
- Assert.That(aDouble, Is.NaN, message, null);
- }
-
- /// <summary>
- /// Verifies that the double that is passed in is an <code>NaN</code> value.
- /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="aDouble">The value that is to be tested</param>
- public static void IsNaN(double aDouble)
- {
- Assert.That(aDouble, Is.NaN, null, null);
- }
-
- #if NET_2_0
- /// <summary>
- /// Verifies that the double that is passed in is an <code>NaN</code> value.
- /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="aDouble">The value that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- /// <param name="args">Array of objects to be used in formatting the message</param>
- public static void IsNaN(double? aDouble, string message, params object[] args)
- {
- Assert.That(aDouble, Is.NaN, message, args);
- }
-
- /// <summary>
- /// Verifies that the double that is passed in is an <code>NaN</code> value.
- /// If the object is not <code>NaN</code> then an <see cref="AssertionException"/>
- /// is thrown.
- /// </summary>
- /// <param name="aDouble">The value that is to be tested</param>
- /// <param name="message">The message to display in case of failure</param>
- public static void IsNaN(double? aDouble, string message)
- {
- Assert.That(aDouble, Is.NaN, message, null);
- }
-
- /// <summary>
- /// Ve…
Large files files are truncated, but you can click here to view the full file