Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@383 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
37 changed files with 2905 additions and 2 deletions
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// AbstractAsserter is the base class for all asserters.
|
||||
/// Asserters encapsulate a condition test and generation
|
||||
/// of an AssertionException with a tailored message. They
|
||||
/// are used by the Assert class as helper objects.
|
||||
///
|
||||
/// User-defined asserters may be passed to the
|
||||
/// Assert.DoAssert method in order to implement
|
||||
/// extended asserts.
|
||||
/// </summary>
|
||||
public abstract class AbstractAsserter : IAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// The user-defined message for this asserter.
|
||||
/// </summary>
|
||||
protected readonly string message; |
||||
|
||||
/// <summary>
|
||||
/// Arguments to use in formatting the user-defined message.
|
||||
/// </summary>
|
||||
protected readonly object[] args; |
||||
|
||||
/// <summary>
|
||||
/// Constructs an AbstractAsserter
|
||||
/// </summary>
|
||||
/// <param name="message">The message issued upon failure</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
public AbstractAsserter( string message, params object[] args ) |
||||
{ |
||||
this.message = message; |
||||
this.args = args; |
||||
} |
||||
|
||||
protected string FormattedMessage |
||||
{ |
||||
get |
||||
{ |
||||
if ( message == null ) |
||||
return string.Empty; |
||||
|
||||
if ( args != null && args.Length > 0 ) |
||||
return string.Format( message, args ); |
||||
|
||||
return message; |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Assert on the condition this object is designed
|
||||
/// to handle, throwing an exception if it fails.
|
||||
/// </summary>
|
||||
public abstract void Assert(); |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@
@@ -0,0 +1,31 @@
|
||||
using System; |
||||
using System.Reflection; |
||||
using System.Runtime.CompilerServices; |
||||
|
||||
[assembly: CLSCompliant(true)] |
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("")] |
||||
[assembly: AssemblyDescription("")] |
||||
[assembly: AssemblyConfiguration("")] |
||||
[assembly: AssemblyCompany("")] |
||||
[assembly: AssemblyProduct("")] |
||||
[assembly: AssemblyCopyright("")] |
||||
[assembly: AssemblyTrademark("")] |
||||
[assembly: AssemblyCulture("")] |
||||
|
||||
//
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Revision and Build Numbers
|
||||
// by using the '*' as shown below:
|
||||
|
||||
[assembly: AssemblyVersion("2.2.2.0")] |
||||
@ -0,0 +1,623 @@
@@ -0,0 +1,623 @@
|
||||
#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 |
||||
{ |
||||
/// <summary>
|
||||
/// A set of Assert methods
|
||||
/// </summary>
|
||||
public class Assert |
||||
{ |
||||
#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 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 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) |
||||
{ |
||||
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 IsTrue
|
||||
|
||||
/// <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 IsTrue(bool condition, string message, params object[] args) |
||||
{ |
||||
DoAssert( new TrueAsserter( condition, 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 IsTrue(bool condition, string message) |
||||
{ |
||||
Assert.IsTrue(condition, 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 IsTrue(bool condition) |
||||
{ |
||||
Assert.IsTrue(condition, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IsFalse
|
||||
|
||||
/// <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 if the condition is true</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void IsFalse(bool condition, string message, params object[] args) |
||||
{ |
||||
DoAssert( new FalseAsserter( condition, 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 if the condition is true</param>
|
||||
static public void IsFalse(bool condition, string message) |
||||
{ |
||||
Assert.IsFalse( condition, 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>
|
||||
static public void IsFalse(bool condition) |
||||
{ |
||||
Assert.IsFalse(condition, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IsNotNull
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is not 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 be printed when the object is null</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void IsNotNull(Object anObject, string message, params object[] args) |
||||
{ |
||||
DoAssert( new NotNullAsserter( anObject, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is not 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"></param>
|
||||
static public void IsNotNull(Object anObject, string message) |
||||
{ |
||||
Assert.IsNotNull(anObject, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is not 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>
|
||||
static public void IsNotNull(Object anObject) |
||||
{ |
||||
Assert.IsNotNull(anObject, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region IsNull
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is 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 be printed when the object is not null</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void IsNull(Object anObject, string message, params object[] args) |
||||
{ |
||||
DoAssert( new NullAsserter( anObject, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is 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"></param>
|
||||
static public void IsNull(Object anObject, string message) |
||||
{ |
||||
Assert.IsNull(anObject, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Verifies that the object that is passed in is 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>
|
||||
static public void IsNull(Object anObject) |
||||
{ |
||||
Assert.IsNull(anObject, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region AreEqual
|
||||
|
||||
#region Doubles
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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 that will be printed on failure</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreEqual(double expected, |
||||
double actual, double delta, string message, params object[] args) |
||||
{ |
||||
DoAssert( new EqualAsserter( expected, actual, delta, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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 that will be printed on failure</param>
|
||||
static public void AreEqual(double expected, |
||||
double actual, double delta, string message) |
||||
{ |
||||
Assert.AreEqual( expected, actual, delta, message, null ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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>
|
||||
static public void AreEqual(double expected, double actual, double delta) |
||||
{ |
||||
Assert.AreEqual(expected, actual, delta, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region Floats
|
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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 printed out upon failure</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreEqual(float expected, |
||||
float actual, float delta, string message, params object[] args) |
||||
{ |
||||
DoAssert( new EqualAsserter( expected, actual, delta, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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 printed out upon failure</param>
|
||||
static public void AreEqual(float expected, float actual, float delta, string message) |
||||
{ |
||||
Assert.AreEqual(expected, actual, delta, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <see cref="AssertionException"/> is
|
||||
/// thrown.
|
||||
/// </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>
|
||||
static public void AreEqual(float expected, float actual, float delta) |
||||
{ |
||||
Assert.AreEqual(expected, actual, delta, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region Objects
|
||||
|
||||
/// <summary>
|
||||
/// 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 <c>Equals</c> method.
|
||||
/// Arrays are compared by comparing each element using the same rules.
|
||||
/// If they are not equal an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The value that is expected</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">The message to display if objects are not equal</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreEqual(Object expected, Object actual, string message, params object[] args) |
||||
{ |
||||
DoAssert( new EqualAsserter(expected, actual, message, args) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <c>Equals</c> method.
|
||||
/// If they are not equal an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The value that is expected</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">The message to display if objects are not equal</param>
|
||||
static public void AreEqual(Object expected, Object actual, string message) |
||||
{ |
||||
Assert.AreEqual(expected, actual, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// 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 <c>Equals</c> method.
|
||||
/// If they are not equal an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The value that is expected</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
static public void AreEqual(Object expected, Object actual) |
||||
{ |
||||
Assert.AreEqual(expected, actual, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
|
||||
#region AreNotEqual
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects are not equal. If they are equal
|
||||
/// an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the two objects are the same object.</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreNotEqual( Object expected, Object actual, string message, params object[] args) |
||||
{ |
||||
DoAssert( new NotEqualAsserter( expected, actual, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects are not equal. If they are equal
|
||||
/// an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the objects are the same</param>
|
||||
static public void AreNotEqual(Object expected, Object actual, string message) |
||||
{ |
||||
Assert.AreNotEqual(expected, actual, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects are not equal. If they are equal
|
||||
/// an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
static public void AreNotEqual(Object expected, Object actual) |
||||
{ |
||||
Assert.AreNotEqual(expected, actual, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region AreSame
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects refer to the same object. If they
|
||||
/// are not the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the two objects are not the same object.</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreSame(Object expected, Object actual, string message, params object[] args) |
||||
{ |
||||
DoAssert( new SameAsserter( expected, actual, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects refer to the same object. If they
|
||||
/// are not the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the object is null</param>
|
||||
static public void AreSame(Object expected, Object actual, string message) |
||||
{ |
||||
Assert.AreSame(expected, actual, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects refer to the same object. If they
|
||||
/// are not the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
static public void AreSame(Object expected, Object actual) |
||||
{ |
||||
Assert.AreSame(expected, actual, string.Empty, null); |
||||
} |
||||
|
||||
#endregion
|
||||
|
||||
#region AreNotSame
|
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects do not refer to the same object. If they
|
||||
/// are the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the two objects are the same object.</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
static public void AreNotSame(Object expected, Object actual, string message, params object[] args) |
||||
{ |
||||
DoAssert( new NotSameAsserter( expected, actual, message, args ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects do not refer to the same object. If they
|
||||
/// are the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
/// <param name="message">The message to be printed when the objects are the same</param>
|
||||
static public void AreNotSame(Object expected, Object actual, string message) |
||||
{ |
||||
Assert.AreNotSame(expected, actual, message, null); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects do not refer to the same object. If they
|
||||
/// are the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected object</param>
|
||||
/// <param name="actual">The actual object</param>
|
||||
static public void AreNotSame(Object expected, Object actual) |
||||
{ |
||||
Assert.AreNotSame(expected, actual, 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, 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 DoAssert
|
||||
|
||||
static public void DoAssert( IAsserter asserter ) |
||||
{ |
||||
Assert.IncrementAssertCount(); |
||||
asserter.Assert(); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -0,0 +1,190 @@
@@ -0,0 +1,190 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>A set of Assert methods.</summary>
|
||||
///
|
||||
[Obsolete("Use Assert class instead")] |
||||
public class Assertion |
||||
{ |
||||
/// <summary>
|
||||
/// Asserts that a condition is true. If it isn't it throws
|
||||
/// an <see cref="AssertionException"/>.
|
||||
/// </summary>
|
||||
/// <param name="message">The message to display is the condition
|
||||
/// is false</param>
|
||||
/// <param name="condition">The evaluated condition</param>
|
||||
static public void Assert(string message, bool condition) |
||||
{ |
||||
NUnit.Framework.Assert.IsTrue(condition, message); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that a condition is true. If it isn't it throws
|
||||
/// an <see cref="AssertionException"/>.
|
||||
/// </summary>
|
||||
/// <param name="condition">The evaluated condition</param>
|
||||
static public void Assert(bool condition) |
||||
{ |
||||
Assertion.Assert(string.Empty, condition); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// /// Asserts that two doubles are equal concerning a delta. If the
|
||||
/// expected value is infinity then the delta value is ignored.
|
||||
/// </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>
|
||||
static public void AssertEquals(double expected, double actual, double delta) |
||||
{ |
||||
Assertion.AssertEquals(string.Empty, expected, actual, delta); |
||||
} |
||||
/// <summary>
|
||||
/// /// Asserts that two singles are equal concerning a delta. If the
|
||||
/// expected value is infinity then the delta value is ignored.
|
||||
/// </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>
|
||||
static public void AssertEquals(float expected, float actual, float delta) |
||||
{ |
||||
Assertion.AssertEquals(string.Empty, expected, actual, delta); |
||||
} |
||||
|
||||
/// <summary>Asserts that two objects are equal. If they are not
|
||||
/// an <see cref="AssertionException"/> is thrown.</summary>
|
||||
static public void AssertEquals(Object expected, Object actual) |
||||
{ |
||||
Assertion.AssertEquals(string.Empty, expected, actual); |
||||
} |
||||
|
||||
/// <summary>Asserts that two ints are equal. If they are not
|
||||
/// an <see cref="AssertionException"/> is thrown.</summary>
|
||||
static public void AssertEquals(int expected, int actual) |
||||
{ |
||||
Assertion.AssertEquals(string.Empty, expected, actual); |
||||
} |
||||
|
||||
/// <summary>Asserts that two ints are equal. If they are not
|
||||
/// an <see cref="AssertionException"/> is thrown.</summary>
|
||||
static public void AssertEquals(string message, int expected, int actual) |
||||
{ |
||||
NUnit.Framework.Assert.AreEqual(expected, actual, message); |
||||
} |
||||
|
||||
/// <summary>Asserts that two doubles are equal concerning a delta.
|
||||
/// If the expected value is infinity then the delta value is ignored.
|
||||
/// </summary>
|
||||
static public void AssertEquals(string message, double expected, |
||||
double actual, double delta) |
||||
{ |
||||
NUnit.Framework.Assert.AreEqual(expected, actual, delta, message); |
||||
} |
||||
|
||||
/// <summary>Asserts that two floats are equal concerning a delta.
|
||||
/// If the expected value is infinity then the delta value is ignored.
|
||||
/// </summary>
|
||||
static public void AssertEquals(string message, float expected, |
||||
float actual, float delta) |
||||
{ |
||||
NUnit.Framework.Assert.AreEqual(expected, actual, delta, message); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Asserts that two objects are equal. Two objects are considered
|
||||
/// equal if both are null, or if both have the same value. Numeric
|
||||
/// types are compared via string comparision on their contents to
|
||||
/// avoid problems comparing values between different types. All
|
||||
/// non-numeric types are compared by using the <c>Equals</c> method.
|
||||
/// If they are not equal an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
static public void AssertEquals(string message, Object expected, Object actual) |
||||
{ |
||||
NUnit.Framework.Assert.AreEqual(expected, actual, message); |
||||
} |
||||
|
||||
/// <summary>Asserts that an object isn't null.</summary>
|
||||
static public void AssertNotNull(Object anObject) |
||||
{ |
||||
NUnit.Framework.Assert.IsNotNull(anObject, string.Empty); |
||||
} |
||||
|
||||
/// <summary>Asserts that an object isn't null.</summary>
|
||||
static public void AssertNotNull(string message, Object anObject) |
||||
{ |
||||
NUnit.Framework.Assert.IsNotNull(anObject, message); |
||||
} |
||||
|
||||
/// <summary>Asserts that an object is null.</summary>
|
||||
static public void AssertNull(Object anObject) |
||||
{ |
||||
NUnit.Framework.Assert.IsNull(anObject, string.Empty); |
||||
} |
||||
|
||||
/// <summary>Asserts that an object is null.</summary>
|
||||
static public void AssertNull(string message, Object anObject) |
||||
{ |
||||
NUnit.Framework.Assert.IsNull(anObject, message); |
||||
} |
||||
|
||||
/// <summary>Asserts that two objects refer to the same object. If they
|
||||
/// are not the same an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
static public void AssertSame(Object expected, Object actual) |
||||
{ |
||||
NUnit.Framework.Assert.AreSame(expected, actual, string.Empty); |
||||
} |
||||
|
||||
/// <summary>Asserts that two objects refer to the same object.
|
||||
/// If they are not an <see cref="AssertionException"/> is thrown.
|
||||
/// </summary>
|
||||
static public void AssertSame(string message, Object expected, Object actual) |
||||
{ |
||||
NUnit.Framework.Assert.AreSame(expected, actual, message); |
||||
} |
||||
|
||||
/// <summary>Fails a test with no message.</summary>
|
||||
static public void Fail() |
||||
{ |
||||
NUnit.Framework.Assert.Fail(); |
||||
} |
||||
|
||||
/// <summary>Fails a test with the given message.</summary>
|
||||
static public void Fail(string message) |
||||
{ |
||||
NUnit.Framework.Assert.Fail(message); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
using System.Runtime.Serialization; |
||||
|
||||
/// <summary>
|
||||
/// Thrown when an assertion failed.
|
||||
/// </summary>
|
||||
///
|
||||
[Serializable] |
||||
public class AssertionException : System.Exception |
||||
{ |
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public AssertionException (string message) : base(message) |
||||
{} |
||||
|
||||
/// <summary>
|
||||
/// Standard constructor
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains
|
||||
/// the reason for the exception</param>
|
||||
/// <param name="inner">The exception that caused the
|
||||
/// current exception</param>
|
||||
public AssertionException(string message, Exception inner) : |
||||
base(message, inner) |
||||
{} |
||||
|
||||
/// <summary>
|
||||
/// Serialization Constructor
|
||||
/// </summary>
|
||||
protected AssertionException(SerializationInfo info, |
||||
StreamingContext context) : base(info,context) |
||||
{} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,430 @@
@@ -0,0 +1,430 @@
|
||||
#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig, Douglas de la Torre
|
||||
/************************************************************************************ |
||||
' |
||||
' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole |
||||
' Copyright 2000-2002 Philip A. Craig |
||||
' Copyright 2001 Douglas de la Torre |
||||
' |
||||
' 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 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov |
||||
' Copyright 2000-2002 Philip A. Craig, or Copyright 2001 Douglas de la Torre |
||||
' |
||||
' 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.Text; |
||||
using System.IO; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Summary description for AssertionFailureMessage.
|
||||
/// </summary>
|
||||
public class AssertionFailureMessage : StringWriter |
||||
{ |
||||
#region Static Constants
|
||||
|
||||
/// <summary>
|
||||
/// Number of characters before a highlighted position before
|
||||
/// clipping will occur. Clipped text is replaced with an
|
||||
/// elipsis "..."
|
||||
/// </summary>
|
||||
static public readonly int PreClipLength = 35; |
||||
|
||||
/// <summary>
|
||||
/// Number of characters after a highlighted position before
|
||||
/// clipping will occur. Clipped text is replaced with an
|
||||
/// elipsis "..."
|
||||
/// </summary>
|
||||
static public readonly int PostClipLength = 35; |
||||
|
||||
static protected readonly string ExpectedText = "expected:<"; |
||||
static protected readonly string ButWasText = " but was:<"; |
||||
|
||||
static private readonly string expectedFmt = "\texpected:<{0}>"; |
||||
static private readonly string butWasFmt = "\t but was:<{0}>"; |
||||
static private readonly string diffStringLengthsFmt |
||||
= "\tString lengths differ. Expected length={0}, but was length={1}."; |
||||
static private readonly string sameStringLengthsFmt |
||||
= "\tString lengths are both {0}."; |
||||
static private readonly string diffArrayLengthsFmt |
||||
= "Array lengths differ. Expected length={0}, but was length={1}."; |
||||
static private readonly string sameArrayLengthsFmt |
||||
= "Array lengths are both {0}."; |
||||
static private readonly string stringsDifferAtIndexFmt |
||||
= "\tStrings differ at index {0}."; |
||||
static private readonly string arraysDifferAtIndexFmt |
||||
= "Arrays differ at index {0}."; |
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Construct an AssertionFailureMessage with a message
|
||||
/// and optional arguments.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
public AssertionFailureMessage( string message, params object[] args ) |
||||
: base( CreateStringBuilder( message, args ) ) { } |
||||
|
||||
/// <summary>
|
||||
/// Construct an empty AssertionFailureMessage
|
||||
/// </summary>
|
||||
public AssertionFailureMessage() : this( null, null ) { } |
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Display two lines that communicate the expected value, and the actual value
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value found</param>
|
||||
public void DisplayExpectedAndActual( Object expected, Object actual ) |
||||
{ |
||||
WriteLine(); |
||||
Write( expectedFmt, DisplayString( expected ) ); |
||||
WriteLine(); |
||||
Write( butWasFmt, DisplayString( actual ) ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Draws a marker under the expected/actual strings that highlights
|
||||
/// where in the string a mismatch occurred.
|
||||
/// </summary>
|
||||
/// <param name="iPosition">The position of the mismatch</param>
|
||||
public void DisplayPositionMarker( int iPosition ) |
||||
{ |
||||
WriteLine(); |
||||
Write( "\t" + new String( '-', ButWasText.Length + 1 ) ); |
||||
if( iPosition > 0 ) |
||||
{ |
||||
Write( new string( '-', iPosition ) ); |
||||
} |
||||
Write( "^" ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Reports whether the string lengths are the same or different, and
|
||||
/// what the string lengths are.
|
||||
/// </summary>
|
||||
/// <param name="sExpected">The expected string</param>
|
||||
/// <param name="sActual">The actual string value</param>
|
||||
protected void BuildStringLengthReport( string sExpected, string sActual ) |
||||
{ |
||||
WriteLine(); |
||||
if( sExpected.Length != sActual.Length ) |
||||
Write( diffStringLengthsFmt, sExpected.Length, sActual.Length ); |
||||
else |
||||
Write( sameStringLengthsFmt, sExpected.Length ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called to create additional message lines when two objects have been
|
||||
/// found to be unequal. If the inputs are strings, a special message is
|
||||
/// rendered that can help track down where the strings are different,
|
||||
/// based on differences in length, or differences in content.
|
||||
///
|
||||
/// If the inputs are not strings, the ToString method of the objects
|
||||
/// is used to show what is different about them.
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="caseInsensitive">True if a case-insensitive comparison is being performed</param>
|
||||
public void DisplayDifferences( object expected, object actual, bool caseInsensitive ) |
||||
{ |
||||
if( InputsAreStrings( expected, actual ) ) |
||||
{ |
||||
DisplayStringDifferences( |
||||
(string)expected, |
||||
(string)actual, |
||||
caseInsensitive ); |
||||
} |
||||
else |
||||
{ |
||||
DisplayExpectedAndActual( expected, actual ); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructs a message that can be displayed when the content of two
|
||||
/// strings are different, but the string lengths are the same. The
|
||||
/// message will clip the strings to a reasonable length, centered
|
||||
/// around the first position where they are mismatched, and draw
|
||||
/// a line marking the position of the difference to make comparison
|
||||
/// quicker.
|
||||
/// </summary>
|
||||
/// <param name="sExpected">The expected string value</param>
|
||||
/// <param name="sActual">The actual string value</param>
|
||||
/// <param name="caseInsensitive">True if a case-insensitive comparison is being performed</param>
|
||||
protected void DisplayStringDifferences( string sExpected, string sActual, bool caseInsensitive ) |
||||
{ |
||||
//
|
||||
// If they mismatch at a specified position, report the
|
||||
// difference.
|
||||
//
|
||||
int iPosition = caseInsensitive |
||||
? FindMismatchPosition( sExpected.ToLower(), sActual.ToLower(), 0 ) |
||||
: FindMismatchPosition( sExpected, sActual, 0 ); |
||||
//
|
||||
// If the lengths differ, but they match up to the length,
|
||||
// show the difference just past the length of the shorter
|
||||
// string
|
||||
//
|
||||
if( iPosition == -1 ) |
||||
iPosition = Math.Min( sExpected.Length, sActual.Length ); |
||||
|
||||
BuildStringLengthReport( sExpected, sActual ); |
||||
|
||||
WriteLine(); |
||||
Write( stringsDifferAtIndexFmt, iPosition ); |
||||
|
||||
//
|
||||
// Clips the strings, then turns any hidden whitespace into visible
|
||||
// characters
|
||||
//
|
||||
string sClippedExpected = ConvertWhitespace(ClipAroundPosition( sExpected, iPosition )); |
||||
string sClippedActual = ConvertWhitespace(ClipAroundPosition( sActual, iPosition )); |
||||
|
||||
DisplayExpectedAndActual( |
||||
sClippedExpected, |
||||
sClippedActual ); |
||||
|
||||
// Add a line showing where they differ. If the string lengths are
|
||||
// different, they start differing just past the length of the
|
||||
// shorter string
|
||||
DisplayPositionMarker( caseInsensitive |
||||
? FindMismatchPosition( sClippedExpected.ToLower(), sClippedActual.ToLower(), 0 ) |
||||
: FindMismatchPosition( sClippedExpected, sClippedActual, 0 ) ); |
||||
} |
||||
|
||||
private void DisplayAdditionalElements( string label, Array array, int index, int max ) |
||||
{ |
||||
WriteLine(); |
||||
Write( "{0}<", label ); |
||||
|
||||
for( int i = 0; i < max; i++ ) |
||||
{ |
||||
Write( DisplayString( array.GetValue(index++) ) ); |
||||
|
||||
if ( index >= array.Length ) |
||||
break; |
||||
|
||||
Write( "," ); |
||||
} |
||||
|
||||
if ( index < array.Length ) |
||||
Write( "..." ); |
||||
|
||||
Write( ">" ); |
||||
} |
||||
|
||||
#region Static Methods
|
||||
|
||||
/// <summary>
|
||||
/// Display an object as a string
|
||||
/// </summary>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
static protected string DisplayString( object obj ) |
||||
{ |
||||
if ( obj == null ) |
||||
return "(null)"; |
||||
else if ( obj is string ) |
||||
return Quoted( (string)obj ); |
||||
else |
||||
return obj.ToString(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Quote a string
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
static protected string Quoted( string text ) |
||||
{ |
||||
return string.Format( "\"{0}\"", text ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Tests two objects to determine if they are strings.
|
||||
/// </summary>
|
||||
/// <param name="expected"></param>
|
||||
/// <param name="actual"></param>
|
||||
/// <returns></returns>
|
||||
static protected bool InputsAreStrings( Object expected, Object actual ) |
||||
{ |
||||
return expected != null && actual != null && |
||||
expected is string && actual is string; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Used to create a StringBuilder that is used for constructing
|
||||
/// the output message when text is different. Handles initialization
|
||||
/// when a message is provided. If message is null, an empty
|
||||
/// StringBuilder is returned.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
static protected StringBuilder CreateStringBuilder( string message, params object[] args ) |
||||
{ |
||||
if (message != null) |
||||
if ( args != null && args.Length > 0 ) |
||||
return new StringBuilder( string.Format( message, args ) ); |
||||
else |
||||
return new StringBuilder( message ); |
||||
else |
||||
return new StringBuilder(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Renders up to M characters before, and up to N characters after
|
||||
/// the specified index position. If leading or trailing text is
|
||||
/// clipped, and elipses "..." is added where the missing text would
|
||||
/// be.
|
||||
///
|
||||
/// Clips strings to limit previous or post newline characters,
|
||||
/// since these mess up the comparison
|
||||
/// </summary>
|
||||
/// <param name="sString"></param>
|
||||
/// <param name="iPosition"></param>
|
||||
/// <returns></returns>
|
||||
static protected string ClipAroundPosition( string sString, int iPosition ) |
||||
{ |
||||
if( sString == null || sString.Length == 0 ) |
||||
return ""; |
||||
|
||||
bool preClip = iPosition > PreClipLength; |
||||
bool postClip = iPosition + PostClipLength < sString.Length; |
||||
|
||||
int start = preClip |
||||
? iPosition - PreClipLength : 0; |
||||
int length = postClip |
||||
? iPosition + PostClipLength - start : sString.Length - start; |
||||
|
||||
if ( start + length > iPosition + PostClipLength ) |
||||
length = iPosition + PostClipLength - start; |
||||
|
||||
StringBuilder sb = new StringBuilder(); |
||||
if ( preClip ) sb.Append("..."); |
||||
sb.Append( sString.Substring( start, length ) ); |
||||
if ( postClip ) sb.Append("..."); |
||||
|
||||
return sb.ToString(); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Shows the position two strings start to differ. Comparison
|
||||
/// starts at the start index.
|
||||
/// </summary>
|
||||
/// <param name="sExpected"></param>
|
||||
/// <param name="sActual"></param>
|
||||
/// <param name="iStart"></param>
|
||||
/// <returns>-1 if no mismatch found, or the index where mismatch found</returns>
|
||||
static private int FindMismatchPosition( string sExpected, string sActual, int iStart ) |
||||
{ |
||||
int iLength = Math.Min( sExpected.Length, sActual.Length ); |
||||
for( int i=iStart; i<iLength; i++ ) |
||||
{ |
||||
//
|
||||
// If they mismatch at a specified position, report the
|
||||
// difference.
|
||||
//
|
||||
if( sExpected[i] != sActual[i] ) |
||||
{ |
||||
return i; |
||||
} |
||||
} |
||||
//
|
||||
// Strings have same content up to the length of the shorter string.
|
||||
// Mismatch occurs because string lengths are different, so show
|
||||
// that they start differing where the shortest string ends
|
||||
//
|
||||
if( sExpected.Length != sActual.Length ) |
||||
{ |
||||
return iLength; |
||||
} |
||||
|
||||
//
|
||||
// Same strings
|
||||
//
|
||||
Assert.IsTrue( sExpected.Equals( sActual ) ); |
||||
return -1; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Turns CR, LF, or TAB into visual indicator to preserve visual marker
|
||||
/// position. This is done by replacing the '\r' into '\\' and 'r'
|
||||
/// characters, and the '\n' into '\\' and 'n' characters, and '\t' into
|
||||
/// '\\' and 't' characters.
|
||||
///
|
||||
/// Thus the single character becomes two characters for display.
|
||||
/// </summary>
|
||||
/// <param name="sInput"></param>
|
||||
/// <returns></returns>
|
||||
static protected string ConvertWhitespace( string sInput ) |
||||
{ |
||||
if( null != sInput ) |
||||
{ |
||||
sInput = sInput.Replace( "\r", "\\r" ); |
||||
sInput = sInput.Replace( "\n", "\\n" ); |
||||
sInput = sInput.Replace( "\t", "\\t" ); |
||||
} |
||||
return sInput; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Called to create a message when two arrays are not equal.
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <param name="expected"></param>
|
||||
/// <param name="actual"></param>
|
||||
/// <param name="message"></param>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
static public string FormatMessageForFailArraysNotEqual(int index, Array expected, Array actual, |
||||
string message, params object[] args) |
||||
{ |
||||
AssertionFailureMessage msg = new AssertionFailureMessage( message, args ); |
||||
|
||||
msg.WriteLine(); |
||||
if( expected.Length != actual.Length ) |
||||
msg.Write( diffArrayLengthsFmt, expected.Length, actual.Length ); |
||||
else |
||||
msg.Write( sameArrayLengthsFmt, expected.Length ); |
||||
|
||||
msg.WriteLine(); |
||||
msg.Write( arraysDifferAtIndexFmt, index ); |
||||
|
||||
if ( index < expected.Length && index < actual.Length ) |
||||
msg.DisplayDifferences( expected.GetValue( index ), actual.GetValue( index ), false ); |
||||
else if( expected.Length < actual.Length ) |
||||
msg.DisplayAdditionalElements( " extra:", actual, index, 3 ); |
||||
else |
||||
msg.DisplayAdditionalElements( " missing:", expected, index, 3 ); |
||||
|
||||
return msg.ToString(); |
||||
} |
||||
|
||||
#endregion
|
||||
} |
||||
} |
||||
@ -0,0 +1,60 @@
@@ -0,0 +1,60 @@
|
||||
#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; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Summary description for CategoryAttribute.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple=true)] |
||||
public sealed class CategoryAttribute : Attribute |
||||
{ |
||||
private string name; |
||||
|
||||
/// <summary>
|
||||
/// Construct attribute for a given category
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the category</param>
|
||||
public CategoryAttribute(string name) |
||||
{ |
||||
this.name = name; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The name of the category
|
||||
/// </summary>
|
||||
public string Name |
||||
{ |
||||
get { return name; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Abstract class used as a base for asserters that compare
|
||||
/// expected and an actual values in some way or another.
|
||||
/// </summary>
|
||||
public abstract class ComparisonAsserter : AbstractAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// The expected value, used as the basis for comparison.
|
||||
/// </summary>
|
||||
protected object expected; |
||||
|
||||
/// <summary>
|
||||
/// The actual value to be compared.
|
||||
/// </summary>
|
||||
protected object actual; |
||||
|
||||
/// <summary>
|
||||
/// Constructs a ComparisonAsserter for two objects
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public ComparisonAsserter( object expected, object actual, string message, params object[] args ) |
||||
: base( message, args ) |
||||
{ |
||||
this.expected = expected; |
||||
this.actual = actual; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,101 @@
@@ -0,0 +1,101 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// ConditionAsserter class represents an asssertion
|
||||
/// that tests a particular condition, which is passed
|
||||
/// to it in the constructor. The failure message is
|
||||
/// not specialized in this class, but derived classes
|
||||
/// are free to do so.
|
||||
/// </summary>
|
||||
public class ConditionAsserter : AbstractAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// The condition we are testing
|
||||
/// </summary>
|
||||
protected bool condition; |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to be tested</param>
|
||||
/// <param name="message">The message issued upon failure</param>
|
||||
/// <param name="args">Arguments to be used in formatting the message</param>
|
||||
public ConditionAsserter( bool condition, string message, params object[] args ) |
||||
: base( message, args ) |
||||
{ |
||||
this.condition = condition; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Assert the condition.
|
||||
/// </summary>
|
||||
public override void Assert() |
||||
{ |
||||
if ( !condition ) |
||||
NUnit.Framework.Assert.Fail( message, args ); |
||||
} |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Class to assert that a condition is true
|
||||
/// </summary>
|
||||
public class TrueAsserter : ConditionAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to assert</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public TrueAsserter( bool condition, string message, params object[] args ) |
||||
: base( condition, message, args ) { } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Class to assert that a condition is false
|
||||
/// </summary>
|
||||
public class FalseAsserter : ConditionAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="condition">The condition to assert</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public FalseAsserter( bool condition, string message, params object[] args ) |
||||
: base( !condition, message, args ) { } |
||||
|
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Class to assert that an object is null
|
||||
/// </summary>
|
||||
public class NullAsserter : ConditionAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="anObject">The object to test</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public NullAsserter( object anObject, string message, params object[] args ) |
||||
: base( anObject == null, message, args ) { } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Class to assert that an object is not null
|
||||
/// </summary>
|
||||
public class NotNullAsserter : ConditionAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="anObject">The object to test</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public NotNullAsserter( object anObject, string message, params object[] args ) |
||||
: base( anObject != null, message, args ) { } |
||||
} |
||||
} |
||||
@ -0,0 +1,80 @@
@@ -0,0 +1,80 @@
|
||||
using System; |
||||
using System.Text; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Class to assert that two objects are equal
|
||||
/// </summary>
|
||||
public class EqualAsserter : EqualityAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Constructs an EqualAsserter for two objects
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">The message to issue on failure</param>
|
||||
/// <param name="args">Arguments to apply in formatting the message</param>
|
||||
public EqualAsserter( object expected, object actual, string message, params object[] args ) |
||||
: base( expected, actual, message, args ) { } |
||||
|
||||
public EqualAsserter( double expected, double actual, double delta, string message, params object[] args ) |
||||
: base( expected, actual, delta, message, args ) { } |
||||
|
||||
/// <summary>
|
||||
/// Assert that the objects are equal
|
||||
/// </summary>
|
||||
/// <returns>True if they are equal, false if not</returns>
|
||||
public override void Assert() |
||||
{ |
||||
if ( expected == null && actual == null ) return; |
||||
if ( expected == null || actual == null ) |
||||
FailNotEqual(); |
||||
|
||||
// For now, dynamically call array assertion if necessary. Try to move
|
||||
// this into the ObjectsEqual method later on.
|
||||
if ( expected.GetType().IsArray && actual.GetType().IsArray ) |
||||
{ |
||||
Array expectedArray = expected as Array; |
||||
Array actualArray = actual as Array; |
||||
|
||||
if ( expectedArray.Rank != actualArray.Rank ) |
||||
FailNotEqual(); |
||||
|
||||
if ( expectedArray.Rank != 1 ) |
||||
NUnit.Framework.Assert.Fail( "Multi-dimension array comparison is not supported" ); |
||||
|
||||
int iLength = Math.Min( expectedArray.Length, actualArray.Length ); |
||||
for( int i = 0; i < iLength; i++ ) |
||||
if ( !ObjectsEqual( expectedArray.GetValue( i ), actualArray.GetValue( i ) ) ) |
||||
FailArraysNotEqual( i ); |
||||
|
||||
if ( expectedArray.Length != actualArray.Length ) |
||||
FailArraysNotEqual( iLength ); |
||||
} |
||||
else |
||||
{ |
||||
if ( !ObjectsEqual( expected, actual ) ) |
||||
FailNotEqual(); |
||||
} |
||||
} |
||||
|
||||
private void FailNotEqual() |
||||
{ |
||||
AssertionFailureMessage msg = new AssertionFailureMessage( message, args ); |
||||
msg.DisplayDifferences( expected, actual, false ); |
||||
throw new AssertionException( msg.ToString() ); |
||||
} |
||||
|
||||
private void FailArraysNotEqual( int index ) |
||||
{ |
||||
throw new AssertionException( |
||||
AssertionFailureMessage.FormatMessageForFailArraysNotEqual( |
||||
index, |
||||
(Array)expected, |
||||
(Array)actual, |
||||
message, |
||||
args ) ); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,131 @@
@@ -0,0 +1,131 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Abstract base class for EqualsAsserter and NotEqualsAsserter
|
||||
/// </summary>
|
||||
public abstract class EqualityAsserter : ComparisonAsserter |
||||
{ |
||||
private double delta; |
||||
|
||||
public EqualityAsserter( object expected, object actual, string message, params object[] args ) |
||||
: base( expected, actual, message, args ) { } |
||||
|
||||
public EqualityAsserter( double expected, double actual, double delta, string message, params object[] args ) |
||||
: base( expected, actual, message, args ) |
||||
{ |
||||
this.delta = delta; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Used to compare two objects. Two nulls are equal and null
|
||||
/// is not equal to non-null. Comparisons between the same
|
||||
/// numeric types are fine (Int32 to Int32, or Int64 to Int64),
|
||||
/// but the Equals method fails across different types so we
|
||||
/// use <c>ToString</c> and compare the results.
|
||||
/// </summary>
|
||||
/// <param name="expected"></param>
|
||||
/// <param name="actual"></param>
|
||||
/// <returns></returns>
|
||||
protected virtual bool ObjectsEqual( Object expected, Object actual ) |
||||
{ |
||||
if ( expected == null && actual == null ) return true; |
||||
if ( expected == null || actual == null ) return false; |
||||
|
||||
//if ( expected.GetType().IsArray && actual.GetType().IsArray )
|
||||
// return ArraysEqual( (System.Array)expected, (System.Array)actual );
|
||||
|
||||
if ( expected is double && actual is double ) |
||||
{ |
||||
// handle infinity specially since subtracting two infinite values gives
|
||||
// NaN and the following test fails. mono also needs NaN to be handled
|
||||
// specially although ms.net could use either method.
|
||||
if (double.IsInfinity((double)expected) || double.IsNaN((double)expected) || double.IsNaN((double)actual)) |
||||
return (double)expected == (double)actual; |
||||
else |
||||
return Math.Abs((double)expected-(double)actual) <= this.delta; |
||||
} |
||||
|
||||
// if ( expected is float && actual is float )
|
||||
// {
|
||||
// // handle infinity specially since subtracting two infinite values gives
|
||||
// // NaN and the following test fails. mono also needs NaN to be handled
|
||||
// // specially although ms.net could use either method.
|
||||
// if (float.IsInfinity((float)expected) || float.IsNaN((float)expected) || float.IsNaN((float)actual))
|
||||
// return (float)expected == (float)actual;
|
||||
// else
|
||||
// return Math.Abs((float)expected-(float)actual) <= (float)this.delta;
|
||||
// }
|
||||
|
||||
if ( expected.GetType() != actual.GetType() && |
||||
IsNumericType( expected ) && IsNumericType( actual ) ) |
||||
{ |
||||
//
|
||||
// Convert to strings and compare result to avoid
|
||||
// issues with different types that have the same
|
||||
// value
|
||||
//
|
||||
string sExpected = expected.ToString(); |
||||
string sActual = actual.ToString(); |
||||
return sExpected.Equals( sActual ); |
||||
} |
||||
return expected.Equals(actual); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Checks the type of the object, returning true if
|
||||
/// the object is a numeric type.
|
||||
/// </summary>
|
||||
/// <param name="obj">The object to check</param>
|
||||
/// <returns>true if the object is a numeric type</returns>
|
||||
private bool IsNumericType( Object obj ) |
||||
{ |
||||
if( null != obj ) |
||||
{ |
||||
if( obj is byte ) return true; |
||||
if( obj is sbyte ) return true; |
||||
if( obj is decimal ) return true; |
||||
if( obj is double ) return true; |
||||
if( obj is float ) return true; |
||||
if( obj is int ) return true; |
||||
if( obj is uint ) return true; |
||||
if( obj is long ) return true; |
||||
if( obj is short ) return true; |
||||
if( obj is ushort ) return true; |
||||
|
||||
if( obj is System.Byte ) return true; |
||||
if( obj is System.SByte ) return true; |
||||
if( obj is System.Decimal ) return true; |
||||
if( obj is System.Double ) return true; |
||||
if( obj is System.Single ) return true; |
||||
if( obj is System.Int32 ) return true; |
||||
if( obj is System.UInt32 ) return true; |
||||
if( obj is System.Int64 ) return true; |
||||
if( obj is System.UInt64 ) return true; |
||||
if( obj is System.Int16 ) return true; |
||||
if( obj is System.UInt16 ) return true; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
protected virtual bool ArraysEqual( Array expected, Array actual ) |
||||
{ |
||||
if ( expected.Rank != actual.Rank ) |
||||
return false; |
||||
|
||||
if ( expected.Rank != 1 ) |
||||
throw new ArgumentException( "Multi-dimension array comparison is not supported" ); |
||||
|
||||
int iLength = Math.Min( expected.Length, actual.Length ); |
||||
for( int i = 0; i < iLength; i++ ) |
||||
if ( !ObjectsEqual( expected.GetValue( i ), actual.GetValue( i ) ) ) |
||||
return false; |
||||
|
||||
if ( expected.Length != actual.Length ) |
||||
return false; |
||||
|
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,82 @@
@@ -0,0 +1,82 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// ExpectedAttributeException.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class ExpectedExceptionAttribute : Attribute |
||||
{ |
||||
private Type expectedException; |
||||
private string expectedMessage; |
||||
|
||||
/// <summary>
|
||||
/// Constructor for a given type of exception
|
||||
/// </summary>
|
||||
/// <param name="exceptionType"></param>
|
||||
public ExpectedExceptionAttribute(Type exceptionType) |
||||
{ |
||||
expectedException = exceptionType; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Constructor for a given type of exception and expected message text
|
||||
/// </summary>
|
||||
/// <param name="exceptionType"></param>
|
||||
/// <param name="expectedMessage"></param>
|
||||
public ExpectedExceptionAttribute(Type exceptionType, string expectedMessage) |
||||
{ |
||||
expectedException = exceptionType; |
||||
this.expectedMessage = expectedMessage; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The expected exception type
|
||||
/// </summary>
|
||||
public Type ExceptionType |
||||
{ |
||||
get{ return expectedException; } |
||||
set{ expectedException = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The expected message
|
||||
/// </summary>
|
||||
public string ExpectedMessage |
||||
{ |
||||
get { return expectedMessage; } |
||||
set { expectedMessage = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,21 @@
@@ -0,0 +1,21 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// ExplicitAttribute marks a test or test fixture so that it will
|
||||
/// only be run if explicitly executed from the gui or command line
|
||||
/// or if it is included by use of a filter. The test will not be
|
||||
/// run simply because an enclosing suite is run.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class ExplicitAttribute : Attribute |
||||
{ |
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
public ExplicitAttribute() |
||||
{ |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,23 @@
@@ -0,0 +1,23 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// The interface implemented by an asserter. Asserters
|
||||
/// encapsulate a condition test and generation of an
|
||||
/// AssertionException with a tailored message. They
|
||||
/// are used by the Assert class as helper objects.
|
||||
///
|
||||
/// User-defined asserters may be passed to the
|
||||
/// Assert.DoAssert method in order to implement
|
||||
/// extended asserts.
|
||||
/// </summary>
|
||||
public interface IAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Assert the truth of the condition, throwing an
|
||||
/// exception if the condition is false.
|
||||
/// </summary>
|
||||
void Assert(); |
||||
} |
||||
} |
||||
@ -0,0 +1,59 @@
@@ -0,0 +1,59 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
/// <summary>
|
||||
/// IgnoreAttribute.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Method|AttributeTargets.Class, AllowMultiple=false)] |
||||
public sealed class IgnoreAttribute : Attribute |
||||
{ |
||||
private string reason; |
||||
|
||||
/// <summary>
|
||||
/// Constructor
|
||||
/// </summary>
|
||||
/// <param name="reason"></param>
|
||||
public IgnoreAttribute(string reason) |
||||
{ |
||||
this.reason = reason; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// The reason for ignoring a test
|
||||
/// </summary>
|
||||
public string Reason |
||||
{ |
||||
get { return reason; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,68 @@
@@ -0,0 +1,68 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
using System.Runtime.Serialization; |
||||
|
||||
/// <summary>
|
||||
/// Thrown when an assertion failed.
|
||||
/// </summary>
|
||||
///
|
||||
[Serializable] |
||||
public class IgnoreException : System.Exception |
||||
{ |
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
public IgnoreException (string message) : base(message) |
||||
{} |
||||
|
||||
/// <summary>
|
||||
/// Standard constructor
|
||||
/// </summary>
|
||||
/// <param name="message">The error message that explains
|
||||
/// the reason for the exception</param>
|
||||
/// <param name="inner">The exception that caused the
|
||||
/// current exception</param>
|
||||
public IgnoreException(string message, Exception inner) : |
||||
base(message, inner) |
||||
{} |
||||
|
||||
/// <summary>
|
||||
/// Serialization Constructor
|
||||
/// </summary>
|
||||
protected IgnoreException(SerializationInfo info, |
||||
StreamingContext context) : base(info,context) |
||||
{} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Summary description for NotEqualAsserter.
|
||||
/// </summary>
|
||||
public class NotEqualAsserter : EqualityAsserter |
||||
{ |
||||
public NotEqualAsserter( object expected, object actual, string message, params object[] args ) |
||||
: base( expected, actual, message, args ) { } |
||||
|
||||
public override void Assert() |
||||
{ |
||||
if ( expected == null && actual == null ) Fail(); |
||||
if ( expected == null || actual == null ) return; |
||||
|
||||
if ( expected.GetType().IsArray && actual.GetType().IsArray ) |
||||
{ |
||||
if ( ArraysEqual( (Array)expected, (Array)actual ) ) |
||||
Fail(); |
||||
} |
||||
else if ( ObjectsEqual( expected, actual ) ) |
||||
Fail(); |
||||
} |
||||
|
||||
public bool Fail() |
||||
{ |
||||
throw new AssertionException( FormattedMessage ); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Asserter that verifies two objects are different.
|
||||
/// </summary>
|
||||
public class NotSameAsserter : ComparisonAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Construct a NotSameAsserter object
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">A user-defined message for use in reporting errors</param>
|
||||
/// <param name="args">Arguments to be used in formatting the user-defined message</param>
|
||||
public NotSameAsserter( object expected, object actual, string message, params object[] args) |
||||
: base( expected, actual, message, args ) { } |
||||
|
||||
/// <summary>
|
||||
/// Assert that the objects are different
|
||||
/// </summary>
|
||||
public override void Assert() |
||||
{ |
||||
if ( object.ReferenceEquals( expected, actual ) ) |
||||
{ |
||||
string formatted = FormattedMessage; |
||||
if ( formatted.Length > 0 ) |
||||
formatted += " "; |
||||
|
||||
throw new AssertionException( formatted + "expected not same" ); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,58 @@
@@ -0,0 +1,58 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// TestFixture
|
||||
/// </summary>
|
||||
///
|
||||
[TestFixture] |
||||
[Obsolete("use TestFixture attribute instead of inheritance",false)] |
||||
public class TestCase : Assertion |
||||
{ |
||||
/// <summary>
|
||||
/// SetUp method
|
||||
/// </summary>
|
||||
[SetUp] |
||||
[Obsolete("use SetUp attribute instead of naming convention",false)] |
||||
protected virtual void SetUp() |
||||
{} |
||||
|
||||
/// <summary>
|
||||
/// TearDown method
|
||||
/// </summary>
|
||||
[TearDown] |
||||
[Obsolete("use TearDown attribute instead of naming convention",false)] |
||||
protected virtual void TearDown() |
||||
{} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
using System; |
||||
using System.Text; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// PlatformAttribute is used to mark a test fixture or an
|
||||
/// individual method as applying to a particular platform only.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class PlatformAttribute : Attribute |
||||
{ |
||||
private string include; |
||||
private string exclude; |
||||
|
||||
public PlatformAttribute() { } |
||||
|
||||
public PlatformAttribute( string platforms ) |
||||
{ |
||||
this.include = platforms; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Name of the platform that is needed in order for
|
||||
/// a test to run. Multiple platforms may be given,
|
||||
/// separated by a comma.
|
||||
/// </summary>
|
||||
public string Include |
||||
{ |
||||
get { return this.include; } |
||||
set { include = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Name of the platform to be excluded. Multiple platforms
|
||||
/// may be given, separated by a comma.
|
||||
/// </summary>
|
||||
public string Exclude |
||||
{ |
||||
get { return this.exclude; } |
||||
set { this.exclude = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Asserter that verifies two objects are the same.
|
||||
/// </summary>
|
||||
public class SameAsserter : ComparisonAsserter |
||||
{ |
||||
/// <summary>
|
||||
/// Construct a SameAsserter object
|
||||
/// </summary>
|
||||
/// <param name="expected">The expected value</param>
|
||||
/// <param name="actual">The actual value</param>
|
||||
/// <param name="message">A user-defined message for use in reporting errors</param>
|
||||
/// <param name="args">Arguments to be used in formatting the user-defined message</param>
|
||||
public SameAsserter( object expected, object actual, string message, params object[] args ) |
||||
: base( expected, actual, message, args ) { } |
||||
|
||||
/// <summary>
|
||||
/// Assert that the objects are the same
|
||||
/// </summary>
|
||||
public override void Assert() |
||||
{ |
||||
if ( ! object.ReferenceEquals( expected, actual ) ) |
||||
{ |
||||
string formatted = FormattedMessage; |
||||
if ( formatted.Length > 0 ) |
||||
formatted += " "; |
||||
|
||||
throw new AssertionException( formatted + "expected same" ); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
/// <summary>
|
||||
/// SetUpAttribute.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class SetUpAttribute : Attribute |
||||
{} |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
/// <summary>
|
||||
/// SuiteAttribute.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Property, AllowMultiple=false)] |
||||
public sealed class SuiteAttribute : Attribute |
||||
{} |
||||
} |
||||
@ -0,0 +1,12 @@
@@ -0,0 +1,12 @@
|
||||
using System; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// SuiteBuilderAttribute is used to mark custom suite builders.
|
||||
/// The class so marked must implement the ISuiteBuilder interface.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] |
||||
public sealed class SuiteBuilderAttribute : Attribute |
||||
{} |
||||
} |
||||
@ -0,0 +1,40 @@
@@ -0,0 +1,40 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
/// <summary>
|
||||
/// TearDownAttribute.
|
||||
/// </summary>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class TearDownAttribute : Attribute |
||||
{} |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
|
||||
/************************************************************************************ |
||||
' |
||||
' 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 © 2002-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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// Adding this attribute to a method within a <seealso cref="TestFixtureAttribute"/>
|
||||
/// class makes the method callable from the NUnit test runner. There is a property
|
||||
/// called Description which is optional which you can provide a more detailed test
|
||||
/// description. This class cannot be inherited.
|
||||
/// </summary>
|
||||
///
|
||||
/// <example>
|
||||
/// [TestFixture]
|
||||
/// public class Fixture
|
||||
/// {
|
||||
/// [Test]
|
||||
/// public void MethodToTest()
|
||||
/// {}
|
||||
///
|
||||
/// [Test(Description = "more detailed description")]
|
||||
/// publc void TestDescriptionMethod()
|
||||
/// {}
|
||||
/// }
|
||||
/// </example>
|
||||
///
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public sealed class TestAttribute : Attribute |
||||
{ |
||||
private string description; |
||||
|
||||
/// <summary>
|
||||
/// Descriptive text for this test
|
||||
/// </summary>
|
||||
public string Description |
||||
{ |
||||
get { return description; } |
||||
set { description = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,103 @@
@@ -0,0 +1,103 @@
|
||||
using System; |
||||
using System.Diagnostics; |
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
/// <summary>
|
||||
/// Experimental class with static settings that affect tests.
|
||||
/// A setings may be saved and restored. Currently only
|
||||
/// one setting - Tracing - is available.
|
||||
/// </summary>
|
||||
public class TestContext |
||||
{ |
||||
/// <summary>
|
||||
/// The current context, head of the list of saved contexts.
|
||||
/// </summary>
|
||||
private static ContextHolder current = new ContextHolder(); |
||||
|
||||
public static bool Tracing |
||||
{ |
||||
get { return current.Tracing; } |
||||
set { current.Tracing = value; } |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Saves the old context and makes a fresh one
|
||||
/// current without changing any settings.
|
||||
/// </summary>
|
||||
public static void Save() |
||||
{ |
||||
TestContext.current = new ContextHolder( current ); |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Restores the last saved context and puts
|
||||
/// any saved settings back into effect.
|
||||
/// </summary>
|
||||
public static void Restore() |
||||
{ |
||||
current.ReverseChanges(); |
||||
current = current.prior; |
||||
} |
||||
|
||||
private TestContext() { } |
||||
|
||||
private class ContextHolder |
||||
{ |
||||
/// <summary>
|
||||
/// Indicates whether trace is enabled
|
||||
/// </summary>
|
||||
private bool tracing; |
||||
|
||||
/// <summary>
|
||||
/// Link to a prior saved context
|
||||
/// </summary>
|
||||
public ContextHolder prior; |
||||
|
||||
public ContextHolder() |
||||
{ |
||||
this.prior = null; |
||||
this.tracing = false; |
||||
} |
||||
|
||||
public ContextHolder( ContextHolder other ) |
||||
{ |
||||
this.prior = other; |
||||
this.tracing = other.tracing; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Used to restore settings to their prior
|
||||
/// values before reverting to a prior context.
|
||||
/// </summary>
|
||||
public void ReverseChanges() |
||||
{ |
||||
if ( prior == null ) |
||||
throw new InvalidOperationException( "TestContext: too many Restores" ); |
||||
|
||||
this.Tracing = prior.Tracing; |
||||
} |
||||
|
||||
/// <summary>
|
||||
/// Controls whether trace and debug output are written
|
||||
/// to the standard output.
|
||||
/// </summary>
|
||||
public bool Tracing |
||||
{ |
||||
get { return tracing; } |
||||
set |
||||
{ |
||||
if ( tracing != value ) |
||||
{ |
||||
tracing = value; |
||||
if ( tracing ) |
||||
Trace.Listeners.Add( new TextWriterTraceListener( Console.Out, "NUnit" ) ); |
||||
else |
||||
Trace.Listeners.Remove( "NUnit" ); |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@
@@ -0,0 +1,56 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// TestFixtureAttribute
|
||||
/// </summary>
|
||||
/// <example>
|
||||
/// [TestFixture]
|
||||
/// public class ExampleClass
|
||||
/// {}
|
||||
/// </example>
|
||||
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false, Inherited=true)] |
||||
public sealed class TestFixtureAttribute : Attribute |
||||
{ |
||||
private string description; |
||||
|
||||
/// <summary>
|
||||
/// Descriptive text for this fixture
|
||||
/// </summary>
|
||||
public string Description |
||||
{ |
||||
get { return description; } |
||||
set { description = value; } |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,41 @@
@@ -0,0 +1,41 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// TestFixtureSetUpAttribute
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public class TestFixtureSetUpAttribute : Attribute |
||||
{ |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
#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
|
||||
|
||||
namespace NUnit.Framework |
||||
{ |
||||
using System; |
||||
|
||||
/// <summary>
|
||||
/// TestFixtureTearDownAttribute
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)] |
||||
public class TestFixtureTearDownAttribute : Attribute |
||||
{ |
||||
} |
||||
} |
||||
|
||||
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0"?> |
||||
<project name="NUnit.Framework" default="build"> |
||||
|
||||
<property name="project.src.dir" value="../.." |
||||
unless="${property::exists('project.src.dir')}"/> |
||||
|
||||
<include buildfile="..\..\nunit.build.include"/> |
||||
|
||||
<target name="clean" depends="set-build-dir"> |
||||
<delete failonerror="false"> |
||||
<fileset basedir="${current.build.dir}"> |
||||
<include name="nunit.framework.dll"/> |
||||
<include name="nunit.framework.pdb"/> |
||||
</fileset> |
||||
</delete> |
||||
</target> |
||||
|
||||
<target name="build" depends="make-build-dir"> |
||||
<csc target="library" |
||||
output="${current.build.dir}/nunit.framework.dll" |
||||
debug="${build.debug}" |
||||
define="${build.defines.csc},StronglyNamedAssembly" |
||||
nowarn="618,672"> |
||||
<sources basedir="."> |
||||
<include name="*.cs"/> |
||||
</sources> |
||||
</csc> |
||||
</target> |
||||
|
||||
<target name="package"> |
||||
<copy todir="${package.src.dir}/NUnitFramework/framework"> |
||||
<fileset basedir="."> |
||||
<include name="nunit.framework.dll.csproj"/> |
||||
<include name="nunit.framework.build"/> |
||||
<include name="*.cs"/> |
||||
</fileset> |
||||
</copy> |
||||
</target> |
||||
</project> |
||||
@ -0,0 +1,143 @@
@@ -0,0 +1,143 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<ProjectType>Local</ProjectType> |
||||
<ProductVersion>8.0.41115</ProductVersion> |
||||
<SchemaVersion>2.0</SchemaVersion> |
||||
<ProjectGuid>{83DD7E12-A705-4DBA-9D71-09C8973D9382}</ProjectGuid> |
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> |
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> |
||||
<AssemblyName>nunit.framework</AssemblyName> |
||||
<DefaultClientScript>JScript</DefaultClientScript> |
||||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout> |
||||
<DefaultTargetSchema>IE50</DefaultTargetSchema> |
||||
<AssemblyOriginatorKeyFile>nunit.key</AssemblyOriginatorKeyFile> |
||||
<OutputType>Library</OutputType> |
||||
<RootNamespace>NUnit.Framework</RootNamespace> |
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> |
||||
<SignAssembly>True</SignAssembly> |
||||
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode> |
||||
<OutputPath>..\..\..\bin\</OutputPath> |
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> |
||||
<BaseAddress>285212672</BaseAddress> |
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow> |
||||
<DefineConstants>TRACE;StronglyNamedAssembly</DefineConstants> |
||||
<DebugSymbols>false</DebugSymbols> |
||||
<FileAlignment>4096</FileAlignment> |
||||
<NoStdLib>false</NoStdLib> |
||||
<Optimize>true</Optimize> |
||||
<RegisterForComInterop>false</RegisterForComInterop> |
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks> |
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors> |
||||
<WarningLevel>4</WarningLevel> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' " /> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' " /> |
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug-Strong|AnyCPU' " /> |
||||
<ItemGroup> |
||||
<Reference Include="System"> |
||||
<Name>System</Name> |
||||
</Reference> |
||||
<Reference Include="System.Data"> |
||||
<Name>System.Data</Name> |
||||
</Reference> |
||||
<Reference Include="System.Xml"> |
||||
<Name>System.XML</Name> |
||||
</Reference> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Compile Include="AbstractAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="AssemblyInfo.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="Assert.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="Assertion.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="AssertionException.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="AssertionFailureMessage.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="CategoryAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="ComparisonAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="ConditionAsserters.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="EqualAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="EqualityAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="ExpectedExceptionAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="ExplicitAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="IAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="IgnoreAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="IgnoreException.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="NotEqualAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="NotSameAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="OldTestCase.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="PlatformAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="SameAsserter.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="SetUpAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="SuiteAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="SuiteBuilderAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TearDownAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TestAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TestContext.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TestFixtureAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TestFixtureSetUpAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
<Compile Include="TestFixtureTearDownAttribute.cs"> |
||||
<SubType>Code</SubType> |
||||
</Compile> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<Folder Include="Configuration\" /> |
||||
</ItemGroup> |
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> |
||||
</Project> |
||||
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<PropertyGroup> |
||||
<LastOpenVersion>8.0.41115</LastOpenVersion> |
||||
<ProjectView>ProjectFiles</ProjectView> |
||||
<ProjectTrust>0</ProjectTrust> |
||||
</PropertyGroup> |
||||
</Project> |
||||
Binary file not shown.
Loading…
Reference in new issue