#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig /************************************************************************************ ' ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole ' Copyright © 2000-2003 Philip A. Craig ' ' This software is provided 'as-is', without any express or implied warranty. In no ' event will the authors be held liable for any damages arising from the use of this ' software. ' ' Permission is granted to anyone to use this software for any purpose, including ' commercial applications, and to alter it and redistribute it freely, subject to the ' following restrictions: ' ' 1. The origin of this software must not be misrepresented; you must not claim that ' you wrote the original software. If you use this software in a product, an ' acknowledgment (see the following) in the product documentation is required. ' ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole ' or Copyright © 2000-2003 Philip A. Craig ' ' 2. Altered source versions must be plainly marked as such, and must not be ' misrepresented as being the original software. ' ' 3. This notice may not be removed or altered from any source distribution. ' '***********************************************************************************/ #endregion using System; using System.Collections; using System.ComponentModel; namespace NUnit.Framework { /// /// A set of Assert methods /// public class Assert { #region Assert Counting private static int counter = 0; /// /// Gets the number of assertions executed so far and /// resets the counter to zero. /// public static int Counter { get { int cnt = counter; counter = 0; return cnt; } } private static void IncrementAssertCount() { ++counter; } #endregion #region Constructor /// /// 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. /// protected Assert() {} #endregion #region Equals and ReferenceEquals #if ! FX1_1 //andyh /// /// The Equals method throws an AssertionException. This is done /// to make sure there is no mistake by calling this function. /// /// /// [EditorBrowsable(EditorBrowsableState.Never)] public static new bool Equals(object a, object b) { throw new AssertionException("Assert.Equals should not be used for Assertions"); } /// /// override the default ReferenceEquals to throw an AssertionException. This /// implementation makes sure there is no mistake in calling this function /// as part of Assert. /// /// /// public static new void ReferenceEquals(object a, object b) { throw new AssertionException("Assert.ReferenceEquals should not be used for Assertions"); } #endif #endregion #region IsTrue /// /// Asserts that a condition is true. If the condition is false the method throws /// an . /// /// The evaluated condition /// The message to display if the condition is false /// Arguments to be used in formatting the message static public void IsTrue(bool condition, string message, params object[] args) { DoAssert( new TrueAsserter( condition, message, args ) ); } /// /// Asserts that a condition is true. If the condition is false the method throws /// an . /// /// The evaluated condition /// The message to display if the condition is false static public void IsTrue(bool condition, string message) { Assert.IsTrue(condition, message, null); } /// /// Asserts that a condition is true. If the condition is false the method throws /// an . /// /// The evaluated condition static public void IsTrue(bool condition) { Assert.IsTrue(condition, string.Empty, null); } #endregion #region IsFalse /// /// Asserts that a condition is false. If the condition is true the method throws /// an . /// /// The evaluated condition /// The message to display if the condition is true /// Arguments to be used in formatting the message static public void IsFalse(bool condition, string message, params object[] args) { DoAssert( new FalseAsserter( condition, message, args ) ); } /// /// Asserts that a condition is false. If the condition is true the method throws /// an . /// /// The evaluated condition /// The message to display if the condition is true static public void IsFalse(bool condition, string message) { Assert.IsFalse( condition, message, null ); } /// /// Asserts that a condition is false. If the condition is true the method throws /// an . /// /// The evaluated condition static public void IsFalse(bool condition) { Assert.IsFalse(condition, string.Empty, null); } #endregion #region IsNotNull /// /// Verifies that the object that is passed in is not equal to null /// If the object is null then an /// is thrown. /// /// The object that is to be tested /// The message to be displayed when the object is null /// Arguments to be used in formatting the message static public void IsNotNull(Object anObject, string message, params object[] args) { DoAssert( new NotNullAsserter( anObject, message, args ) ); } /// /// Verifies that the object that is passed in is not equal to null /// If the object is null then an /// is thrown. /// /// The object that is to be tested /// The message to be displayed when the object is null static public void IsNotNull(Object anObject, string message) { Assert.IsNotNull(anObject, message, null); } /// /// Verifies that the object that is passed in is not equal to null /// If the object is null then an /// is thrown. /// /// The object that is to be tested static public void IsNotNull(Object anObject) { Assert.IsNotNull(anObject, string.Empty, null); } #endregion #region IsNull /// /// Verifies that the object that is passed in is equal to null /// If the object is not null then an /// is thrown. /// /// The object that is to be tested /// The message to be displayed when the object is not null /// Arguments to be used in formatting the message static public void IsNull(Object anObject, string message, params object[] args) { DoAssert( new NullAsserter( anObject, message, args ) ); } /// /// Verifies that the object that is passed in is equal to null /// If the object is not null then an /// is thrown. /// /// The object that is to be tested /// The message to be displayed when the object is not null static public void IsNull(Object anObject, string message) { Assert.IsNull(anObject, message, null); } /// /// Verifies that the object that is passed in is equal to null /// If the object is not null null then an /// is thrown. /// /// The object that is to be tested static public void IsNull(Object anObject) { Assert.IsNull(anObject, string.Empty, null); } #endregion #region IsNaN /// /// Verifies that the double is passed is an NaN value. /// If the object is not NaN then an /// is thrown. /// /// The value that is to be tested /// The message to be displayed when the object is not null /// Arguments to be used in formatting the message static public void IsNaN(double aDouble, string message, params object[] args) { DoAssert( new NaNAsserter( aDouble, message, args ) ); } /// /// Verifies that the double is passed is an NaN value. /// If the object is not NaN then an /// is thrown. /// /// The object that is to be tested /// The message to be displayed when the object is not null static public void IsNaN(double aDouble, string message) { Assert.IsNaN(aDouble, message, null); } /// /// Verifies that the double is passed is an NaN value. /// If the object is not NaN then an /// is thrown. /// /// The object that is to be tested static public void IsNaN(double aDouble) { Assert.IsNaN(aDouble, string.Empty, null); } #endregion #region IsEmpty /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested /// The message to be displayed on failure /// Arguments to be used in formatting the message public static void IsEmpty( string aString, string message, params object[] args ) { DoAssert( new EmptyAsserter( aString, message, args ) ); } /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested /// The message to be displayed on failure public static void IsEmpty( string aString, string message ) { IsEmpty( aString, message, null ); } /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested public static void IsEmpty( string aString ) { IsEmpty( aString, string.Empty, null ); } /// /// Assert that an array, list or other collection is empty /// /// An array, list or other collection implementing ICollection /// The message to be displayed on failure /// Arguments to be used in formatting the message public static void IsEmpty( ICollection collection, string message, params object[] args ) { DoAssert( new EmptyAsserter( collection, message, args ) ); } /// /// Assert that an array, list or other collection is empty /// /// An array, list or other collection implementing ICollection /// The message to be displayed on failure public static void IsEmpty( ICollection collection, string message ) { IsEmpty( collection, message, null ); } /// /// Assert that an array,list or other collection is empty /// /// An array, list or other collection implementing ICollection public static void IsEmpty( ICollection collection ) { IsEmpty( collection, string.Empty, null ); } #endregion #region IsNotEmpty /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested /// The message to be displayed on failure /// Arguments to be used in formatting the message public static void IsNotEmpty( string aString, string message, params object[] args ) { DoAssert( new NotEmptyAsserter( aString, message, args ) ); } /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested /// The message to be displayed on failure public static void IsNotEmpty( string aString, string message ) { IsNotEmpty( aString, message, null ); } /// /// Assert that a string is empty - that is equal to string.Emtpy /// /// The string to be tested public static void IsNotEmpty( string aString ) { IsNotEmpty( aString, string.Empty, null ); } /// /// Assert that an array, list or other collection is empty /// /// An array, list or other collection implementing ICollection /// The message to be displayed on failure /// Arguments to be used in formatting the message public static void IsNotEmpty( ICollection collection, string message, params object[] args ) { DoAssert( new NotEmptyAsserter( collection, message, args ) ); } /// /// Assert that an array, list or other collection is empty /// /// An array, list or other collection implementing ICollection /// The message to be displayed on failure public static void IsNotEmpty( ICollection collection, string message ) { IsNotEmpty( collection, message, null ); } /// /// Assert that an array,list or other collection is empty /// /// An array, list or other collection implementing ICollection public static void IsNotEmpty( ICollection collection ) { IsNotEmpty( collection, string.Empty, null ); } #endregion #region IsAssignableFrom /// /// Asserts that an object may be assigned a value of a given Type. /// /// The expected Type. /// The object under examination static public void IsAssignableFrom( System.Type expected, object actual ) { IsAssignableFrom(expected, actual, ""); } /// /// Asserts that an object may be assigned a value of a given Type. /// /// The expected Type. /// The object under examination /// The messge to display in case of failure static public void IsAssignableFrom( System.Type expected, object actual, string message ) { IsAssignableFrom(expected, actual, message, null); } /// /// Asserts that an object may be assigned a value of a given Type. /// /// The expected Type. /// The object under examination /// The message to display in case of failure /// Array of objects to be used in formatting the message static public void IsAssignableFrom( System.Type expected, object actual, string message, params object[] args ) { Assert.DoAssert( new AssignableFromAsserter( expected, actual, message, args ) ); } #endregion #region IsNotAssignableFrom /// /// Asserts that an object may not be assigned a value of a given Type. /// /// The expected Type. /// The object under examination static public void IsNotAssignableFrom( System.Type expected, object actual ) { IsNotAssignableFrom(expected, actual, ""); } /// /// Asserts that an object may not be assigned a value of a given Type. /// /// The expected Type. /// The object under examination /// The messge to display in case of failure static public void IsNotAssignableFrom( System.Type expected, object actual, string message ) { IsNotAssignableFrom(expected, actual, message, null); } /// /// Asserts that an object may not be assigned a value of a given Type. /// /// The expected Type. /// The object under examination /// The message to display in case of failure /// Array of objects to be used in formatting the message static public void IsNotAssignableFrom( System.Type expected, object actual, string message, params object[] args ) { Assert.DoAssert( new NotAssignableFromAsserter( expected, actual, message, args ) ); } #endregion #region IsInstanceOfType /// /// Asserts that an object is an instance of a given type. /// /// The expected Type /// The object being examined public static void IsInstanceOfType( System.Type expected, object actual ) { IsInstanceOfType( expected, actual, string.Empty, null ); } /// /// Asserts that an object is an instance of a given type. /// /// The expected Type /// The object being examined /// A message to display in case of failure public static void IsInstanceOfType( System.Type expected, object actual, string message ) { IsInstanceOfType( expected, actual, message, null ); } /// /// Asserts that an object is an instance of a given type. /// /// The expected Type /// The object being examined /// A message to display in case of failure /// An array of objects to be used in formatting the message public static void IsInstanceOfType( System.Type expected, object actual, string message, params object[] args ) { Assert.DoAssert( new InstanceOfTypeAsserter( expected, actual, message, args ) ); } #endregion #region IsNotInstanceOfType /// /// Asserts that an object is not an instance of a given type. /// /// The expected Type /// The object being examined public static void IsNotInstanceOfType( System.Type expected, object actual ) { IsNotInstanceOfType( expected, actual, string.Empty, null ); } /// /// Asserts that an object is not an instance of a given type. /// /// The expected Type /// The object being examined /// A message to display in case of failure public static void IsNotInstanceOfType( System.Type expected, object actual, string message ) { IsNotInstanceOfType( expected, actual, message, null ); } /// /// Asserts that an object is not an instance of a given type. /// /// The expected Type /// The object being examined /// A message to display in case of failure /// An array of objects to be used in formatting the message public static void IsNotInstanceOfType( System.Type expected, object actual, string message, params object[] args ) { Assert.DoAssert( new NotInstanceOfTypeAsserter( expected, actual, message, args ) ); } #endregion #region AreEqual #region Ints /// /// Verifies that two ints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void AreEqual(int expected, int actual, string message, params object[] args) { DoAssert( new EqualAsserter( expected, actual, message, args ) ); } /// /// Verifies that two ints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure static public void AreEqual(int expected, int actual, string message) { Assert.AreEqual( expected, actual, message, null ); } /// /// Verifies that two ints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value static public void AreEqual(int expected, int actual ) { Assert.AreEqual( expected, actual, string.Empty, null ); } #endregion #region UInts /// /// Verifies that two uints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void AreEqual(uint expected, uint actual, string message, params object[] args) { DoAssert( new EqualAsserter( expected, actual, message, args ) ); } /// /// Verifies that two uints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure static public void AreEqual(uint expected, uint actual, string message) { Assert.AreEqual( expected, actual, message, null ); } /// /// Verifies that two uints are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value static public void AreEqual(uint expected, uint actual ) { Assert.AreEqual( expected, actual, string.Empty, null ); } #endregion #region Decimals /// /// Verifies that two decimals are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void AreEqual(decimal expected, decimal actual, string message, params object[] args) { DoAssert( new EqualAsserter( expected, actual, message, args ) ); } /// /// Verifies that two decimal are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value /// The message that will be displayed on failure static public void AreEqual(decimal expected, decimal actual, string message) { Assert.AreEqual( expected, actual, message, null ); } /// /// Verifies that two decimals are equal. If they are not, then an /// is thrown. /// /// The expected value /// The actual value static public void AreEqual(decimal expected, decimal actual ) { Assert.AreEqual( expected, actual, string.Empty, null ); } #endregion #region Doubles /// /// Verifies that two doubles are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void AreEqual(double expected, double actual, double delta, string message, params object[] args) { DoAssert( new EqualAsserter( expected, actual, delta, message, args ) ); } /// /// Verifies that two doubles are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual /// The message that will be displayed on failure static public void AreEqual(double expected, double actual, double delta, string message) { Assert.AreEqual( expected, actual, delta, message, null ); } /// /// Verifies that two doubles are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual static public void AreEqual(double expected, double actual, double delta) { Assert.AreEqual(expected, actual, delta, string.Empty, null); } #endregion #region Floats /// /// Verifies that two floats are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual /// The message displayed upon failure /// Arguments to be used in formatting the message static public void AreEqual(float expected, float actual, float delta, string message, params object[] args) { DoAssert( new EqualAsserter( expected, actual, delta, message, args ) ); } /// /// Verifies that two floats are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual /// The message displayed upon failure static public void AreEqual(float expected, float actual, float delta, string message) { Assert.AreEqual(expected, actual, delta, message, null); } /// /// Verifies that two floats are equal considering a delta. If the /// expected value is infinity then the delta value is ignored. If /// they are not equals then an is /// thrown. /// /// The expected value /// The actual value /// The maximum acceptable difference between the /// the expected and the actual static public void AreEqual(float expected, float actual, float delta) { Assert.AreEqual(expected, actual, delta, string.Empty, null); } #endregion #region Objects /// /// Verifies that two objects are equal. Two objects are considered /// equal if both are null, or if both have the same value. All /// non-numeric types are compared by using the Equals method. /// Arrays are compared by comparing each element using the same rules. /// If they are not equal an is thrown. /// /// The value that is expected /// The actual value /// The message to display if objects are not equal /// Arguments to be used in formatting the message static public void AreEqual(Object expected, Object actual, string message, params object[] args) { DoAssert( new EqualAsserter(expected, actual, message, args) ); } /// /// Verifies that two objects are equal. Two objects are considered /// equal if both are null, or if both have the same value. All /// non-numeric types are compared by using the Equals method. /// If they are not equal an is thrown. /// /// The value that is expected /// The actual value /// The message to display if objects are not equal static public void AreEqual(Object expected, Object actual, string message) { Assert.AreEqual(expected, actual, message, null); } /// /// Verifies that two objects are equal. Two objects are considered /// equal if both are null, or if both have the same value. All /// non-numeric types are compared by using the Equals method. /// If they are not equal an is thrown. /// /// The value that is expected /// The actual value static public void AreEqual(Object expected, Object actual) { Assert.AreEqual(expected, actual, string.Empty, null); } #endregion #endregion #region AreNotEqual #region Objects /// /// Asserts that two objects are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( Object expected, Object actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two objects are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(Object expected, Object actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two objects are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(Object expected, Object actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #region Ints /// /// Asserts that two ints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( int expected, int actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two ints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(int expected, int actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two ints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(int expected, int actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #region UInts /// /// Asserts that two uints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( uint expected, uint actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two uints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(uint expected, uint actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two uints are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(uint expected, uint actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #region Decimals /// /// Asserts that two decimals are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( decimal expected, decimal actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two decimals are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(decimal expected, decimal actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two decimals are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(decimal expected, decimal actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #region Floats /// /// Asserts that two floats are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( float expected, float actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two floats are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(float expected, float actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two floats are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(float expected, float actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #region Doubles /// /// Asserts that two doubles are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotEqual( double expected, double actual, string message, params object[] args) { DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); } /// /// Asserts that two doubles are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotEqual(double expected, double actual, string message) { Assert.AreNotEqual(expected, actual, message, null); } /// /// Asserts that two doubles are not equal. If they are equal /// an is thrown. /// /// The expected object /// The actual object static public void AreNotEqual(double expected, double actual) { Assert.AreNotEqual(expected, actual, string.Empty, null); } #endregion #endregion #region AreSame /// /// Asserts that two objects refer to the same object. If they /// are not the same an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are not the same object. /// Arguments to be used in formatting the message static public void AreSame(Object expected, Object actual, string message, params object[] args) { DoAssert( new SameAsserter( expected, actual, message, args ) ); } /// /// Asserts that two objects refer to the same object. If they /// are not the same an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the object is null static public void AreSame(Object expected, Object actual, string message) { Assert.AreSame(expected, actual, message, null); } /// /// Asserts that two objects refer to the same object. If they /// are not the same an is thrown. /// /// The expected object /// The actual object static public void AreSame(Object expected, Object actual) { Assert.AreSame(expected, actual, string.Empty, null); } #endregion #region AreNotSame /// /// Asserts that two objects do not refer to the same object. If they /// are the same an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the two objects are the same object. /// Arguments to be used in formatting the message static public void AreNotSame(Object expected, Object actual, string message, params object[] args) { DoAssert( new NotSameAsserter( expected, actual, message, args ) ); } /// /// Asserts that two objects do not refer to the same object. If they /// are the same an is thrown. /// /// The expected object /// The actual object /// The message to be displayed when the objects are the same static public void AreNotSame(Object expected, Object actual, string message) { Assert.AreNotSame(expected, actual, message, null); } /// /// Asserts that two objects do not refer to the same object. If they /// are the same an is thrown. /// /// The expected object /// The actual object static public void AreNotSame(Object expected, Object actual) { Assert.AreNotSame(expected, actual, string.Empty, null); } #endregion #region Greater #region Ints /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(int arg1, int arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(int arg1, int arg2, string message) { Assert.Greater( arg1, arg2, message, null ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(int arg1, int arg2 ) { Assert.Greater( arg1, arg2, string.Empty, null ); } #endregion #region UInts /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(uint arg1, uint arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(uint arg1, uint arg2, string message) { Assert.Greater( arg1, arg2, message, null ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(uint arg1, uint arg2 ) { Assert.Greater( arg1, arg2, string.Empty, null ); } #endregion #region Decimals /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(decimal arg1, decimal arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(decimal arg1, decimal arg2, string message) { Assert.Greater( arg1, arg2, message, null ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(decimal arg1, decimal arg2 ) { Assert.Greater( arg1, arg2, string.Empty, null ); } #endregion #region Doubles /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(double arg1, double arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(double arg1, double arg2, string message) { Assert.Greater( arg1, arg2, message, null ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(double arg1, double arg2) { Assert.Greater(arg1, arg2, string.Empty, null); } #endregion #region Floats /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(float arg1, float arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(float arg1, float arg2, string message) { Assert.Greater(arg1, arg2, message, null); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(float arg1, float arg2) { Assert.Greater(arg1, arg2, string.Empty, null); } #endregion #region IComparables /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Greater(IComparable arg1, IComparable arg2, string message, params object[] args) { DoAssert( new GreaterAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less /// The message that will be displayed on failure static public void Greater(IComparable arg1, IComparable arg2, string message) { Assert.Greater(arg1, arg2, message, null); } /// /// Verifies that the first value is greater than the second /// value. If they are not, then an /// is thrown. /// /// The first value, expected to be greater /// The second value, expected to be less static public void Greater(IComparable arg1, IComparable arg2) { Assert.Greater(arg1, arg2, string.Empty, null); } #endregion #endregion #region Less #region Ints /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(int arg1, int arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(int arg1, int arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(int arg1, int arg2) { Assert.Less( arg1, arg2, string.Empty, null); } #endregion #region UInts /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(uint arg1, uint arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(uint arg1, uint arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(uint arg1, uint arg2) { Assert.Less( arg1, arg2, string.Empty, null); } #endregion #region Decimals /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(decimal arg1, decimal arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(decimal arg1, decimal arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(decimal arg1, decimal arg2) { Assert.Less(arg1, arg2, string.Empty, null); } #endregion #region Doubles /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(double arg1, double arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(double arg1, double arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(double arg1, double arg2) { Assert.Less(arg1, arg2, string.Empty, null); } #endregion #region Floats /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(float arg1, float arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(float arg1, float arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(float arg1, float arg2) { Assert.Less(arg1, arg2, string.Empty, null); } #endregion #region IComparables /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure /// Arguments to be used in formatting the message static public void Less(IComparable arg1, IComparable arg2, string message, params object[] args) { DoAssert( new LessAsserter( arg2, arg1, message, args ) ); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater /// The message that will be displayed on failure static public void Less(IComparable arg1, IComparable arg2, string message) { Assert.Less(arg1, arg2, message, null); } /// /// Verifies that the first value is less than the second /// value. If it is not, then an /// is thrown. /// /// The first value, expected to be less /// The second value, expected to be greater static public void Less(IComparable arg1, IComparable arg2) { Assert.Less(arg1, arg2, string.Empty, null); } #endregion #endregion #region List Containment /// /// Asserts that an object is contained in a list. /// /// The expected object /// The list to be examined /// The message to display in case of failure /// Arguments used in formatting the message static public void Contains( object expected, IList actual, string message, params object[] args ) { Assert.DoAssert( new ListContentsAsserter( expected, actual, message, args ) ); } /// /// Asserts that an object is contained in a list. /// /// The expected object /// The list to be examined /// The message to display in case of failure static public void Contains( object expected, IList actual, string message ) { Contains( expected, actual, message, null ); } /// /// Asserts that an object is contained in a list. /// /// The expected object /// The list to be examined static public void Contains( object expected, IList actual ) { Contains( expected, actual, string.Empty, null ); } #endregion #region Fail /// /// Throws an with the message and arguments /// that are passed in. This is used by the other Assert functions. /// /// The message to initialize the with. /// Arguments to be used in formatting the message 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); } /// /// Throws an with the message that is /// passed in. This is used by the other Assert functions. /// /// The message to initialize the with. static public void Fail(string message) { Assert.Fail(message, null); } /// /// Throws an . /// This is used by the other Assert functions. /// static public void Fail() { Assert.Fail(string.Empty, null); } #endregion #region Ignore /// /// Throws an with the message and arguments /// that are passed in. This causes the test to be reported as ignored. /// /// The message to initialize the with. /// Arguments to be used in formatting the message 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); } /// /// Throws an with the message that is /// passed in. This causes the test to be reported as ignored. /// /// The message to initialize the with. static public void Ignore( string message ) { Assert.Ignore( message, null ); } /// /// Throws an . /// This causes the test to be reported as ignored. /// static public void Ignore() { Assert.Ignore( string.Empty, null ); } #endregion #region DoAssert /// /// Test the condition asserted by an asserter and throw /// an assertion exception using provided message on failure. /// /// An object that implements IAsserter static public void DoAssert( IAsserter asserter ) { Assert.IncrementAssertCount(); if ( !asserter.Test() ) throw new AssertionException( asserter.Message ); } #endregion } }