Browse Source

Update to NUnit 2.2.5.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@973 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
044c956919
  1. 48
      src/Libraries/NUnit.Framework/AbstractAsserter.cs
  2. 26
      src/Libraries/NUnit.Framework/AssemblyInfo.cs
  3. 1176
      src/Libraries/NUnit.Framework/Assert.cs
  4. 213
      src/Libraries/NUnit.Framework/AssertionFailureMessage.cs
  5. 57
      src/Libraries/NUnit.Framework/CommonAssemblyInfo.cs
  6. 93
      src/Libraries/NUnit.Framework/ConditionAsserters.cs
  7. 67
      src/Libraries/NUnit.Framework/EqualAsserter.cs
  8. 31
      src/Libraries/NUnit.Framework/EqualityAsserter.cs
  9. 43
      src/Libraries/NUnit.Framework/ExpectedExceptionAttribute.cs
  10. 13
      src/Libraries/NUnit.Framework/IAsserter.cs
  11. 12
      src/Libraries/NUnit.Framework/IgnoreAttribute.cs
  12. 52
      src/Libraries/NUnit.Framework/ListContentsAsserter.cs
  13. 33
      src/Libraries/NUnit.Framework/NotEqualAsserter.cs
  14. 21
      src/Libraries/NUnit.Framework/NotSameAsserter.cs
  15. 9
      src/Libraries/NUnit.Framework/PlatformAttribute.cs
  16. 21
      src/Libraries/NUnit.Framework/SameAsserter.cs
  17. 12
      src/Libraries/NUnit.Framework/SetUpFixtureAttribute.cs
  18. 155
      src/Libraries/NUnit.Framework/StringAssert.cs
  19. 204
      src/Libraries/NUnit.Framework/StringAsserters.cs
  20. 12
      src/Libraries/NUnit.Framework/SuiteBuilderAttribute.cs
  21. 103
      src/Libraries/NUnit.Framework/TestContext.cs
  22. 208
      src/Libraries/NUnit.Framework/TypeAsserters.cs
  23. 42
      src/Libraries/NUnit.Framework/greaterasserter.cs
  24. 41
      src/Libraries/NUnit.Framework/lessasserter.cs
  25. 20
      src/Libraries/NUnit.Framework/nunit.framework.build
  26. 51
      src/Libraries/NUnit.Framework/nunit.framework.dll.csproj
  27. 7
      src/Libraries/NUnit.Framework/nunit.framework.dll.csproj.user

48
src/Libraries/NUnit.Framework/AbstractAsserter.cs

@ -17,13 +17,18 @@ namespace NUnit.Framework @@ -17,13 +17,18 @@ namespace NUnit.Framework
/// <summary>
/// The user-defined message for this asserter.
/// </summary>
protected readonly string message;
protected readonly string userMessage;
/// <summary>
/// Arguments to use in formatting the user-defined message.
/// </summary>
protected readonly object[] args;
/// <summary>
/// Our failure message object, initialized as needed
/// </summary>
private AssertionFailureMessage failureMessage;
/// <summary>
/// Constructs an AbstractAsserter
/// </summary>
@ -31,28 +36,45 @@ namespace NUnit.Framework @@ -31,28 +36,45 @@ namespace NUnit.Framework
/// <param name="args">Arguments to be used in formatting the message</param>
public AbstractAsserter( string message, params object[] args )
{
this.message = message;
this.userMessage = message;
this.args = args;
}
protected string FormattedMessage
/// <summary>
/// AssertionFailureMessage object used internally
/// </summary>
protected AssertionFailureMessage FailureMessage
{
get
{
if ( message == null )
return string.Empty;
if ( args != null && args.Length > 0 )
return string.Format( message, args );
return message;
if ( failureMessage == null )
failureMessage = new AssertionFailureMessage( userMessage, args );
return failureMessage;
}
}
#region IAsserter Interface
/// <summary>
/// Test method to be implemented by derived types.
/// Default always succeeds.
/// </summary>
/// <returns>True if the test succeeds</returns>
public virtual bool Test()
{
return true;
}
/// <summary>
/// Assert on the condition this object is designed
/// to handle, throwing an exception if it fails.
/// Message related to a failure. If no failure has
/// occured, the result is unspecified.
/// </summary>
public abstract void Assert();
public virtual string Message
{
get
{
return FailureMessage.ToString();
}
}
#endregion
}
}

26
src/Libraries/NUnit.Framework/AssemblyInfo.cs

@ -1,31 +1,5 @@ @@ -1,31 +1,5 @@
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")]

1176
src/Libraries/NUnit.Framework/Assert.cs

File diff suppressed because it is too large Load Diff

213
src/Libraries/NUnit.Framework/AssertionFailureMessage.cs

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
using System;
using System.Text;
using System.IO;
using System.Collections;
namespace NUnit.Framework
{
@ -55,11 +56,19 @@ namespace NUnit.Framework @@ -55,11 +56,19 @@ namespace NUnit.Framework
/// </summary>
static public readonly int PostClipLength = 35;
static protected readonly string ExpectedText = "expected:<";
static protected readonly string ButWasText = " but was:<";
/// <summary>
/// Prefix used to start an expected value line.
/// Must be same length as actualPrefix.
/// </summary>
static protected readonly string expectedPrefix = "expected:";
/// <summary>
/// Prefix used to start an actual value line.
/// Must be same length as expectedPrefix.
/// </summary>
static protected readonly string actualPrefix = " but was:";
static private readonly string expectedFmt = "\texpected:<{0}>";
static private readonly string butWasFmt = "\t but was:<{0}>";
static private readonly string expectedAndActualFmt = "\t{0} {1}";
static private readonly string diffStringLengthsFmt
= "\tString lengths differ. Expected length={0}, but was length={1}.";
static private readonly string sameStringLengthsFmt
@ -93,6 +102,67 @@ namespace NUnit.Framework @@ -93,6 +102,67 @@ namespace NUnit.Framework
#endregion
/// <summary>
/// Add text to the message as a new line.
/// </summary>
/// <param name="text">The text to add</param>
public void AddLine( string text )
{
WriteLine();
Write( text );
}
/// <summary>
/// Add formatted text and arguments to the message as a new line.
/// </summary>
/// <param name="fmt">Format string</param>
/// <param name="args">Arguments to use with the format</param>
public void AddLine( string fmt, params object[] args )
{
WriteLine();
Write( fmt, args );
}
/// <summary>
/// Add an expected value line to the message containing
/// the text provided as an argument.
/// </summary>
/// <param name="text">Text describing what was expected.</param>
public void AddExpectedLine( string text )
{
AddLine( string.Format( expectedAndActualFmt, expectedPrefix, text ) );
}
/// <summary>
/// Add an actual value line to the message containing
/// the text provided as an argument.
/// </summary>
/// <param name="text">Text describing the actual value.</param>
public void AddActualLine( string text )
{
AddLine( string.Format( expectedAndActualFmt, actualPrefix, text ) );
}
/// <summary>
/// Add an expected value line to the message containing
/// a string representation of the object provided.
/// </summary>
/// <param name="expected">An object representing the expected value</param>
public void DisplayExpectedValue( object expected )
{
AddExpectedLine( FormatObjectForDisplay( expected ) );
}
/// <summary>
/// Add an actual value limne to the message containing
/// a string representation of the object provided.
/// </summary>
/// <param name="actual">An object representing what was actually found</param>
public void DisplayActualValue( object actual )
{
AddActualLine( FormatObjectForDisplay( actual ) );
}
/// <summary>
/// Display two lines that communicate the expected value, and the actual value
/// </summary>
@ -100,10 +170,8 @@ namespace NUnit.Framework @@ -100,10 +170,8 @@ namespace NUnit.Framework
/// <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 ) );
DisplayExpectedValue( expected );
DisplayActualValue( actual );
}
/// <summary>
@ -113,13 +181,7 @@ namespace NUnit.Framework @@ -113,13 +181,7 @@ namespace NUnit.Framework
/// <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( "^" );
AddLine( "\t{0}^", new String( '-', expectedPrefix.Length + iPosition + 3 ) );
}
/// <summary>
@ -130,11 +192,10 @@ namespace NUnit.Framework @@ -130,11 +192,10 @@ namespace NUnit.Framework
/// <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 );
AddLine( diffStringLengthsFmt, sExpected.Length, sActual.Length );
else
Write( sameStringLengthsFmt, sExpected.Length );
AddLine( sameStringLengthsFmt, sExpected.Length );
}
/// <summary>
@ -194,8 +255,7 @@ namespace NUnit.Framework @@ -194,8 +255,7 @@ namespace NUnit.Framework
BuildStringLengthReport( sExpected, sActual );
WriteLine();
Write( stringsDifferAtIndexFmt, iPosition );
AddLine( stringsDifferAtIndexFmt, iPosition );
//
// Clips the strings, then turns any hidden whitespace into visible
@ -216,52 +276,77 @@ namespace NUnit.Framework @@ -216,52 +276,77 @@ namespace NUnit.Framework
: FindMismatchPosition( sClippedExpected, sClippedActual, 0 ) );
}
private void DisplayAdditionalElements( string label, Array array, int index, int max )
/// <summary>
/// Display a standard message showing the differences found between
/// two arrays that were expected to be equal.
/// </summary>
/// <param name="expected">The expected array value</param>
/// <param name="actual">The actual array value</param>
/// <param name="index">The index at which a difference was found</param>
public void DisplayArrayDifferences( Array expected, Array actual, int index )
{
if( expected.Length != actual.Length )
AddLine( diffArrayLengthsFmt, expected.Length, actual.Length );
else
AddLine( sameArrayLengthsFmt, expected.Length );
AddLine( arraysDifferAtIndexFmt, index );
if ( index < expected.Length && index < actual.Length )
DisplayDifferences( expected.GetValue( index ), actual.GetValue( index ), false );
else if( expected.Length < actual.Length )
DisplayListElements( " extra:", actual, index, 3 );
else
DisplayListElements( " missing:", expected, index, 3 );
}
/// <summary>
/// Displays elements from a list on a line
/// </summary>
/// <param name="label">Text to prefix the line with</param>
/// <param name="list">The list of items to display</param>
/// <param name="index">The index in the list of the first element to display</param>
/// <param name="max">The maximum number of elements to display</param>
public void DisplayListElements( string label, IList list, int index, int max )
{
WriteLine();
Write( "{0}<", label );
AddLine( "{0}<", label );
for( int i = 0; i < max; i++ )
if ( list == null )
Write( "null" );
else if ( list.Count == 0 )
Write( "empty" );
else
{
Write( DisplayString( array.GetValue(index++) ) );
for( int i = 0; i < max && index < list.Count; i++ )
{
Write( FormatObjectForDisplay( list[index++] ) );
if ( index >= array.Length )
break;
if ( index < list.Count )
Write( "," );
}
Write( "," );
if ( index < list.Count )
Write( "..." );
}
if ( index < array.Length )
Write( "..." );
Write( ">" );
}
#region Static Methods
/// <summary>
/// Display an object as a string
/// Formats an object for display in a message line
/// </summary>
/// <param name="obj"></param>
/// <param name="obj">The object to be displayed</param>
/// <returns></returns>
static protected string DisplayString( object obj )
static protected string FormatObjectForDisplay( object obj )
{
if ( obj == null )
return "(null)";
return "<(null)>";
else if ( obj is string )
return Quoted( (string)obj );
return string.Format( "<\"{0}\">", 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 );
return string.Format( "<{0}>", obj );
}
/// <summary>
@ -391,40 +476,6 @@ namespace NUnit.Framework @@ -391,40 +476,6 @@ namespace NUnit.Framework
}
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
}
}

57
src/Libraries/NUnit.Framework/CommonAssemblyInfo.cs

@ -0,0 +1,57 @@ @@ -0,0 +1,57 @@
#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-2002 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-2002 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.Reflection;
//
// Common Information about all NUnit assemblies 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("NUnit.org")]
[assembly: AssemblyProduct("NUnit")]
[assembly: AssemblyCopyright("Copyright (C) 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole.\r\nCopyright (C) 2000-2003 Philip Craig.\r\nAll Rights Reserved.")]
[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.5.0")]

93
src/Libraries/NUnit.Framework/ConditionAsserters.cs

@ -1,7 +1,9 @@ @@ -1,7 +1,9 @@
using System;
using System.Collections;
namespace NUnit.Framework
{
#region ConditionAsserter
/// <summary>
/// ConditionAsserter class represents an asssertion
/// that tests a particular condition, which is passed
@ -16,6 +18,12 @@ namespace NUnit.Framework @@ -16,6 +18,12 @@ namespace NUnit.Framework
/// </summary>
protected bool condition;
/// <summary>
/// Phrase indicating what we expected to find
/// Ignored unless set by derived class
/// </summary>
protected string expectation;
/// <summary>
/// Constructor
/// </summary>
@ -29,15 +37,16 @@ namespace NUnit.Framework @@ -29,15 +37,16 @@ namespace NUnit.Framework
}
/// <summary>
/// Assert the condition.
/// Test the condition being asserted directly
/// </summary>
public override void Assert()
public override bool Test()
{
if ( !condition )
NUnit.Framework.Assert.Fail( message, args );
return condition;
}
}
#endregion
#region TrueAsserter
/// <summary>
/// Class to assert that a condition is true
/// </summary>
@ -52,7 +61,9 @@ namespace NUnit.Framework @@ -52,7 +61,9 @@ namespace NUnit.Framework
public TrueAsserter( bool condition, string message, params object[] args )
: base( condition, message, args ) { }
}
#endregion
#region FalseAsserter
/// <summary>
/// Class to assert that a condition is false
/// </summary>
@ -68,7 +79,9 @@ namespace NUnit.Framework @@ -68,7 +79,9 @@ namespace NUnit.Framework
: base( !condition, message, args ) { }
}
#endregion
#region NullAsserter
/// <summary>
/// Class to assert that an object is null
/// </summary>
@ -83,7 +96,9 @@ namespace NUnit.Framework @@ -83,7 +96,9 @@ namespace NUnit.Framework
public NullAsserter( object anObject, string message, params object[] args )
: base( anObject == null, message, args ) { }
}
#endregion
#region NotNullAsserter
/// <summary>
/// Class to assert that an object is not null
/// </summary>
@ -98,4 +113,74 @@ namespace NUnit.Framework @@ -98,4 +113,74 @@ namespace NUnit.Framework
public NotNullAsserter( object anObject, string message, params object[] args )
: base( anObject != null, message, args ) { }
}
#endregion
#region NaNAsserter
/// <summary>
/// Class to assert that a double is an NaN
/// </summary>
public class NaNAsserter : ConditionAsserter
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="aDouble">The value 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 NaNAsserter( double aDouble, string message, params object[] args )
: base( double.IsNaN( aDouble ), message, args ) { }
}
#endregion
#region EmptyAsserter
/// <summary>
/// Class to Assert that a string or collection is empty
/// </summary>
public class EmptyAsserter : ConditionAsserter
{
/// <summary>
/// Construct an EmptyAsserter for a string
/// </summary>
/// <param name="aString">The string to be tested</param>
/// <param name="message">The message to display if the string is not empty</param>
/// <param name="args">Arguements to use in formatting the message</param>
public EmptyAsserter( string aString, string message, params object[] args )
: base( aString == string.Empty, message, args ) { }
/// <summary>
/// Construct an EmptyAsserter for a collection
/// </summary>
/// <param name="collection">The collection to be tested</param>
/// <param name="message">The message to display if the collection is not empty</param>
/// <param name="args">Arguements to use in formatting the message</param>
public EmptyAsserter( ICollection collection, string message, params object[] args )
: base( collection.Count == 0, message, args ) { }
}
#endregion
#region NotEmptyAsserter
/// <summary>
/// Class to Assert that a string or collection is not empty
/// </summary>
public class NotEmptyAsserter : ConditionAsserter
{
/// <summary>
/// Construct a NotEmptyAsserter for a string
/// </summary>
/// <param name="aString">The string to be tested</param>
/// <param name="message">The message to display if the string is empty</param>
/// <param name="args">Arguements to use in formatting the message</param>
public NotEmptyAsserter( string aString, string message, params object[] args )
: base( aString != string.Empty, message, args ) { }
/// <summary>
/// Construct a NotEmptyAsserter for a collection
/// </summary>
/// <param name="collection">The collection to be tested</param>
/// <param name="message">The message to display if the collection is empty</param>
/// <param name="args">Arguements to use in formatting the message</param>
public NotEmptyAsserter( ICollection collection, string message, params object[] args )
: base( collection.Count != 0, message, args ) { }
}
#endregion
}

67
src/Libraries/NUnit.Framework/EqualAsserter.cs

@ -18,18 +18,30 @@ namespace NUnit.Framework @@ -18,18 +18,30 @@ namespace NUnit.Framework
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>
/// Constructs an EqualAsserter for two doubles and a tolerance
/// </summary>
/// <param name="expected">The expected value</param>
/// <param name="actual">The actual value</param>
/// <param name="tolerance">The tolerance used in making the comparison</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public EqualAsserter( double expected, double actual, double tolerance, string message, params object[] args )
: base( expected, actual, tolerance, message, args ) { }
/// <summary>
/// Assert that the objects are equal
/// Test whether the objects are equal, building up
/// the failure message for later use if they are not.
/// </summary>
/// <returns>True if they are equal, false if not</returns>
public override void Assert()
/// <returns>True if the objects are equal</returns>
public override bool Test()
{
if ( expected == null && actual == null ) return;
if ( expected == null && actual == null ) return true;
if ( expected == null || actual == null )
FailNotEqual();
{
DisplayDifferences();
return false;
}
// For now, dynamically call array assertion if necessary. Try to move
// this into the ObjectsEqual method later on.
@ -39,42 +51,49 @@ namespace NUnit.Framework @@ -39,42 +51,49 @@ namespace NUnit.Framework
Array actualArray = actual as Array;
if ( expectedArray.Rank != actualArray.Rank )
FailNotEqual();
{
DisplayDifferences();
return false;
}
if ( expectedArray.Rank != 1 )
NUnit.Framework.Assert.Fail( "Multi-dimension array comparison is not supported" );
throw new ArgumentException( "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 );
{
DisplayArrayDifferences( i );
return false;
}
if ( expectedArray.Length != actualArray.Length )
FailArraysNotEqual( iLength );
{
DisplayArrayDifferences( iLength );
return false;
}
}
else
{
if ( !ObjectsEqual( expected, actual ) )
FailNotEqual();
{
DisplayDifferences();
return false;
}
}
return true;
}
private void FailNotEqual()
private void DisplayDifferences()
{
AssertionFailureMessage msg = new AssertionFailureMessage( message, args );
msg.DisplayDifferences( expected, actual, false );
throw new AssertionException( msg.ToString() );
FailureMessage.DisplayDifferences( expected, actual, false );
}
private void FailArraysNotEqual( int index )
private void DisplayArrayDifferences( int index )
{
throw new AssertionException(
AssertionFailureMessage.FormatMessageForFailArraysNotEqual(
index,
(Array)expected,
(Array)actual,
message,
args ) );
FailureMessage.DisplayArrayDifferences( (Array)expected, (Array)actual, index );
}
}
}

31
src/Libraries/NUnit.Framework/EqualityAsserter.cs

@ -9,16 +9,32 @@ namespace NUnit.Framework @@ -9,16 +9,32 @@ namespace NUnit.Framework
{
private double delta;
/// <summary>
/// Constructor taking expected and actual values and a user message with arguments.
/// </summary>
/// <param name="expected"></param>
/// <param name="actual"></param>
/// <param name="message"></param>
/// <param name="args"></param>
public EqualityAsserter( object expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Constructor taking expected and actual values, a tolerance
/// and a user message and arguments.
/// </summary>
/// <param name="expected"></param>
/// <param name="actual"></param>
/// <param name="delta"></param>
/// <param name="message"></param>
/// <param name="args"></param>
public EqualityAsserter( double expected, double actual, double delta, string message, params object[] args )
: base( expected, actual, message, args )
{
this.delta = delta;
}
{
this.delta = delta;
}
/// <summary>
/// <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),
@ -38,11 +54,13 @@ namespace NUnit.Framework @@ -38,11 +54,13 @@ namespace NUnit.Framework
if ( expected is double && actual is double )
{
if ( double.IsNaN((double)expected) && double.IsNaN((double)actual) )
return true;
// 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;
return expected.Equals( actual );
else
return Math.Abs((double)expected-(double)actual) <= this.delta;
}
@ -109,6 +127,9 @@ namespace NUnit.Framework @@ -109,6 +127,9 @@ namespace NUnit.Framework
return false;
}
/// <summary>
/// Helper method to compare two arrays
/// </summary>
protected virtual bool ArraysEqual( Array expected, Array actual )
{
if ( expected.Rank != actual.Rank )

43
src/Libraries/NUnit.Framework/ExpectedExceptionAttribute.cs

@ -32,32 +32,54 @@ namespace NUnit.Framework @@ -32,32 +32,54 @@ namespace NUnit.Framework
using System;
/// <summary>
/// ExpectedAttributeException.
/// ExpectedExceptionAttribute
/// </summary>
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false)]
public sealed class ExpectedExceptionAttribute : Attribute
{
private Type expectedException;
private string expectedExceptionName;
private string expectedMessage;
/// <summary>
/// Constructor for a given type of exception
/// </summary>
/// <param name="exceptionType"></param>
/// <param name="exceptionType">The type of the expected exception</param>
public ExpectedExceptionAttribute(Type exceptionType)
{
expectedException = exceptionType;
this.expectedException = exceptionType;
this.expectedExceptionName = exceptionType.FullName;
}
/// <summary>
/// Constructor for a given exception name
/// </summary>
/// <param name="exceptionName">The full name of the expected exception</param>
public ExpectedExceptionAttribute(string exceptionName)
{
this.expectedExceptionName = exceptionName;
}
/// <summary>
/// Constructor for a given type of exception and expected message text
/// </summary>
/// <param name="exceptionType"></param>
/// <param name="expectedMessage"></param>
/// <param name="exceptionType">The type of the expected exception</param>
/// <param name="expectedMessage">The expected message text</param>
public ExpectedExceptionAttribute(Type exceptionType, string expectedMessage)
{
expectedException = exceptionType;
this.expectedException = exceptionType;
this.expectedMessage = expectedMessage;
}
/// <summary>
/// Constructor for a given exception name and expected message text
/// </summary>
/// <param name="exceptionName">The full name of the expected exception</param>
/// <param name="expectedMessage">The expected messge text</param>
public ExpectedExceptionAttribute(string exceptionName, string expectedMessage)
{
this.expectedExceptionName = exceptionName;
this.expectedMessage = expectedMessage;
}
@ -70,6 +92,15 @@ namespace NUnit.Framework @@ -70,6 +92,15 @@ namespace NUnit.Framework
set{ expectedException = value; }
}
/// <summary>
/// The full Type name of the expected exception
/// </summary>
public string ExceptionName
{
get{ return expectedExceptionName; }
set{ expectedExceptionName = value; }
}
/// <summary>
/// The expected message
/// </summary>

13
src/Libraries/NUnit.Framework/IAsserter.cs

@ -15,9 +15,16 @@ namespace NUnit.Framework @@ -15,9 +15,16 @@ namespace NUnit.Framework
public interface IAsserter
{
/// <summary>
/// Assert the truth of the condition, throwing an
/// exception if the condition is false.
/// Test the condition for the assertion.
/// </summary>
void Assert();
/// <returns>True if the test succeeds</returns>
bool Test();
/// <summary>
/// Return the message giving the failure reason.
/// The return value is unspecified if no failure
/// has occured.
/// </summary>
string Message { get; }
}
}

12
src/Libraries/NUnit.Framework/IgnoreAttribute.cs

@ -40,9 +40,17 @@ namespace NUnit.Framework @@ -40,9 +40,17 @@ namespace NUnit.Framework
private string reason;
/// <summary>
/// Constructor
/// Default constructor
/// </summary>
/// <param name="reason"></param>
public IgnoreAttribute()
{
this.reason = "";
}
/// <summary>
/// Constructor with a reason
/// </summary>
/// <param name="reason">The reason for ignoring the test</param>
public IgnoreAttribute(string reason)
{
this.reason = reason;

52
src/Libraries/NUnit.Framework/ListContentsAsserter.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
using System;
using System.Collections;
namespace NUnit.Framework
{
/// <summary>
/// ListContentsAsserter implements an assertion that a given
/// item is found in an array or other List.
/// </summary>
public class ListContentsAsserter : AbstractAsserter
{
private object expected;
private IList list;
/// <summary>
/// Constructs a ListContentsAsserter for a particular list and object.
/// </summary>
/// <param name="expected">The expected object</param>
/// <param name="list">The list to be examined</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public ListContentsAsserter( object expected, IList list, string message, params object[] args )
: base( message, args )
{
this.expected = expected;
this.list = list;
}
/// <summary>
/// Test that the object is contained in the list
/// </summary>
/// <returns>True if the object is found</returns>
public override bool Test()
{
return list != null && list.Contains( expected );
}
/// <summary>
/// Error message to display after a failure.
/// </summary>
public override string Message
{
get
{
FailureMessage.DisplayExpectedValue( expected );
FailureMessage.DisplayListElements( "\t but was: ", list, 0, 5 );
return FailureMessage.ToString();
}
}
}
}

33
src/Libraries/NUnit.Framework/NotEqualAsserter.cs

@ -3,30 +3,33 @@ using System; @@ -3,30 +3,33 @@ using System;
namespace NUnit.Framework
{
/// <summary>
/// Summary description for NotEqualAsserter.
/// NotEqualAsserter is the asserter class that handles
/// inequality assertions.
/// </summary>
public class NotEqualAsserter : EqualityAsserter
{
/// <summary>
/// Constructor for NotEqualAsserter
/// </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>
public NotEqualAsserter( object expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
public override void Assert()
/// <summary>
/// Test that the objects are not equal
/// </summary>
public override bool Test()
{
if ( expected == null && actual == null ) Fail();
if ( expected == null || actual == null ) return;
if ( expected == null && actual == null ) return false;
if ( expected == null || actual == null ) return true;
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 );
return !ArraysEqual( (Array)expected, (Array)actual );
else
return !ObjectsEqual( expected, actual );
}
}
}

21
src/Libraries/NUnit.Framework/NotSameAsserter.cs

@ -18,17 +18,22 @@ namespace NUnit.Framework @@ -18,17 +18,22 @@ namespace NUnit.Framework
: base( expected, actual, message, args ) { }
/// <summary>
/// Assert that the objects are different
/// Tests that the objects are not the same
/// </summary>
public override void Assert()
public override bool Test()
{
if ( object.ReferenceEquals( expected, actual ) )
{
string formatted = FormattedMessage;
if ( formatted.Length > 0 )
formatted += " ";
return !object.ReferenceEquals( expected, actual );
}
throw new AssertionException( formatted + "expected not same" );
/// <summary>
/// Provides a message in case of failure
/// </summary>
public override string Message
{
get
{
FailureMessage.Write( "expected not same" );
return FailureMessage.ToString();
}
}
}

9
src/Libraries/NUnit.Framework/PlatformAttribute.cs

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
using System;
using System.Text;
namespace NUnit.Framework
{
@ -13,8 +12,16 @@ namespace NUnit.Framework @@ -13,8 +12,16 @@ namespace NUnit.Framework
private string include;
private string exclude;
/// <summary>
/// Constructor with no platforms specified, for use
/// with named property syntax.
/// </summary>
public PlatformAttribute() { }
/// <summary>
/// Constructor taking one or more platforms
/// </summary>
/// <param name="platforms">Comma-deliminted list of platforms</param>
public PlatformAttribute( string platforms )
{
this.include = platforms;

21
src/Libraries/NUnit.Framework/SameAsserter.cs

@ -18,17 +18,22 @@ namespace NUnit.Framework @@ -18,17 +18,22 @@ namespace NUnit.Framework
: base( expected, actual, message, args ) { }
/// <summary>
/// Assert that the objects are the same
/// Test that actual and expected reference the same object
/// </summary>
public override void Assert()
public override bool Test()
{
if ( ! object.ReferenceEquals( expected, actual ) )
{
string formatted = FormattedMessage;
if ( formatted.Length > 0 )
formatted += " ";
return object.ReferenceEquals( expected, actual );
}
throw new AssertionException( formatted + "expected same" );
/// <summary>
/// Provide error message when the objects are different.
/// </summary>
public override string Message
{
get
{
FailureMessage.Write( "expected same" );
return FailureMessage.ToString();
}
}
}

12
src/Libraries/NUnit.Framework/SetUpFixtureAttribute.cs

@ -0,0 +1,12 @@ @@ -0,0 +1,12 @@
using System;
namespace NUnit.Framework
{
/// <summary>
/// SetUpFixtureAttribute is used to identify a SetUpFixture
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple=false)]
public sealed class SetUpFixtureAttribute : Attribute
{
}
}

155
src/Libraries/NUnit.Framework/StringAssert.cs

@ -0,0 +1,155 @@ @@ -0,0 +1,155 @@
namespace NUnit.Framework
{
/// <summary>
/// Basic Asserts on strings.
/// </summary>
public class StringAssert
{
#region Contains
/// <summary>
/// Asserts that a string is found within another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments used in formatting the message</param>
static public void Contains( string expected, string actual, string message, params object[] args )
{
Assert.DoAssert( new ContainsAsserter( expected, actual, message, args ) );
}
/// <summary>
/// Asserts that a string is found within another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
static public void Contains( string expected, string actual, string message )
{
Contains( expected, actual, message, null );
}
/// <summary>
/// Asserts that a string is found within another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
static public void Contains( string expected, string actual )
{
Contains( expected, actual, string.Empty, null );
}
#endregion
#region StartsWith
/// <summary>
/// Asserts that a string starts with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments used in formatting the message</param>
static public void StartsWith( string expected, string actual, string message, params object[] args )
{
Assert.DoAssert( new StartsWithAsserter( expected, actual, message, args ) );
}
/// <summary>
/// Asserts that a string starts with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
static public void StartsWith( string expected, string actual, string message )
{
StartsWith( expected, actual, message, null );
}
/// <summary>
/// Asserts that a string starts with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
static public void StartsWith( string expected, string actual )
{
StartsWith( expected, actual, string.Empty, null );
}
#endregion
#region EndsWith
/// <summary>
/// Asserts that a string ends with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments used in formatting the message</param>
static public void EndsWith( string expected, string actual, string message, params object[] args )
{
Assert.DoAssert( new EndsWithAsserter( expected, actual, message, args ) );
}
/// <summary>
/// Asserts that a string ends with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
/// <param name="message">The message to display in case of failure</param>
static public void EndsWith( string expected, string actual, string message )
{
EndsWith( expected, actual, message, null );
}
/// <summary>
/// Asserts that a string ends with another string.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The string to be examined</param>
static public void EndsWith( string expected, string actual )
{
EndsWith( expected, actual, string.Empty, null );
}
#endregion
#region AreEqualIgnoringCase
/// <summary>
/// Asserts that two strings are equal, without regard to case.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The actual string</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments used in formatting the message</param>
static public void AreEqualIgnoringCase( string expected, string actual, string message, params object[] args )
{
Assert.DoAssert( new EqualIgnoringCaseAsserter( expected, actual, message, args ) );
}
/// <summary>
/// Asserts that two strings are equal, without regard to case.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The actual string</param>
/// <param name="message">The message to display in case of failure</param>
static public void AreEqualIgnoringCase( string expected, string actual, string message )
{
AreEqualIgnoringCase( expected, actual, message, null );
}
/// <summary>
/// Asserts that two strings are equal, without regard to case.
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The actual string</param>
static public void AreEqualIgnoringCase( string expected, string actual )
{
AreEqualIgnoringCase( expected, actual, string.Empty, null );
}
#endregion
}
}

204
src/Libraries/NUnit.Framework/StringAsserters.cs

@ -0,0 +1,204 @@ @@ -0,0 +1,204 @@
using System;
namespace NUnit.Framework
{
#region StringAsserter
/// <summary>
/// Abstract class used as a base for asserters that compare
/// expected and an actual string values in some way or another.
/// </summary>
public abstract class StringAsserter : AbstractAsserter
{
/// <summary>
/// The expected value, used as the basis for comparison.
/// </summary>
protected string expected;
/// <summary>
/// The actual value to be compared.
/// </summary>
protected string actual;
/// <summary>
/// Constructs a StringAsserter for two strings
/// </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 StringAsserter( string expected, string actual, string message, params object[] args )
: base( message, args )
{
this.expected = expected;
this.actual = actual;
}
/// <summary>
/// Message related to a failure. If no failure has
/// occured, the result is unspecified.
/// </summary>
public override string Message
{
get
{
FailureMessage.AddExpectedLine( Expectation );
FailureMessage.DisplayActualValue( actual );
return FailureMessage.ToString();
}
}
/// <summary>
/// String value that represents what the asserter expected
/// to find. Defaults to the expected value itself.
/// </summary>
protected virtual string Expectation
{
get { return string.Format( "<\"{0}\">", expected ); }
}
}
#endregion
#region ContainsAsserter
/// <summary>
/// Summary description for ContainsAsserter.
/// </summary>
public class ContainsAsserter : StringAsserter
{
/// <summary>
/// Constructs a ContainsAsserter for two strings
/// </summary>
/// <param name="expected">The expected substring</param>
/// <param name="actual">The actual string to be examined</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public ContainsAsserter( string expected, string actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the assertion.
/// </summary>
/// <returns>True if the test succeeds</returns>
public override bool Test()
{
return actual.IndexOf( expected ) >= 0;
}
/// <summary>
/// String value that represents what the asserter expected
/// </summary>
protected override string Expectation
{
get { return string.Format( "String containing \"{0}\"", expected ); }
}
}
#endregion
#region StartsWithAsserter
/// <summary>
/// Summary description for StartsWithAsserter.
/// </summary>
public class StartsWithAsserter : StringAsserter
{
/// <summary>
/// Constructs a StartsWithAsserter for two strings
/// </summary>
/// <param name="expected">The expected substring</param>
/// <param name="actual">The actual string to be examined</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public StartsWithAsserter( string expected, string actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the assertion.
/// </summary>
/// <returns>True if the test succeeds</returns>
public override bool Test()
{
return actual.StartsWith( expected );
}
/// <summary>
/// String value that represents what the asserter expected
/// </summary>
protected override string Expectation
{
get { return string.Format( "String starting with \"{0}\"", expected ); }
}
}
#endregion
#region EndsWithAsserter
/// <summary>
/// Summary description for EndsWithAsserter.
/// </summary>
public class EndsWithAsserter : StringAsserter
{
/// <summary>
/// Constructs a EndsWithAsserter for two strings
/// </summary>
/// <param name="expected">The expected substring</param>
/// <param name="actual">The actual string to be examined</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public EndsWithAsserter( string expected, string actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the assertion.
/// </summary>
/// <returns>True if the test succeeds</returns>
public override bool Test()
{
return actual.EndsWith( expected );
}
/// <summary>
/// String value that represents what the asserter expected
/// </summary>
protected override string Expectation
{
get { return string.Format( "String ending with \"{0}\"", expected ); }
}
}
#endregion
#region EqualIgnoringCaseAsserter
/// <summary>
/// Asserter that implements AreEqualIgnoringCase
/// </summary>
public class EqualIgnoringCaseAsserter : StringAsserter
{
/// <summary>
/// Constructs an EqualIgnoringCaseAsserter for two strings
/// </summary>
/// <param name="expected">The expected string</param>
/// <param name="actual">The actual string</param>
/// <param name="message">The message to issue on failure</param>
/// <param name="args">Arguments to apply in formatting the message</param>
public EqualIgnoringCaseAsserter( string expected, string actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the assertion.
/// </summary>
/// <returns>True if the test succeeds</returns>
public override bool Test()
{
return string.Compare( expected, actual, true ) == 0;
}
/// <summary>
/// String value that represents what the asserter expected
/// </summary>
public override string Message
{
get
{
FailureMessage.DisplayDifferences( expected, actual, true );
return FailureMessage.ToString();
}
}
}
#endregion
}

12
src/Libraries/NUnit.Framework/SuiteBuilderAttribute.cs

@ -1,12 +0,0 @@ @@ -1,12 +0,0 @@
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
{}
}

103
src/Libraries/NUnit.Framework/TestContext.cs

@ -1,103 +0,0 @@ @@ -1,103 +0,0 @@
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" );
}
}
}
}
}
}

208
src/Libraries/NUnit.Framework/TypeAsserters.cs

@ -0,0 +1,208 @@ @@ -0,0 +1,208 @@
using System;
namespace NUnit.Framework
{
#region TypeAsserter
/// <summary>
/// The abstract asserter from which all specific type asserters
/// will inherit from in order to limit code-reproduction.
/// </summary>
public abstract class TypeAsserter : AbstractAsserter
{
/// <summary>
/// The expected Type
/// </summary>
protected System.Type expected;
/// <summary>
/// The actual object to be compared
/// </summary>
protected object actual;
/// <summary>
/// Construct a TypeAsserter
/// </summary>
/// <param name="expected">The expected Type</param>
/// <param name="actual">The object to be examined</param>
/// <param name="message">A message to display on failure</param>
/// <param name="args">Arguments to be used in formatting the message</param>
public TypeAsserter( System.Type expected, object actual, string message, params object[] args )
: base( message, args )
{
this.expected = expected;
this.actual = actual;
}
/// <summary>
/// The complete message text in case of a failure.
/// </summary>
public override string Message
{
get
{
FailureMessage.AddExpectedLine( Expectation );
FailureMessage.AddActualLine( actual.GetType().ToString() );
return FailureMessage.ToString();
}
}
/// <summary>
/// A string representing what was expected. Used as a part of the message text.
/// </summary>
protected virtual string Expectation
{
get { return expected.ToString(); }
}
}
#endregion
#region AssignableFromAsserter
/// <summary>
/// Class to Assert that an object may be assigned from a given Type.
/// </summary>
public class AssignableFromAsserter : TypeAsserter
{
/// <summary>
/// Construct an AssignableFromAsserter
/// </summary>
/// <param name="expected">The expected Type</param>
/// <param name="actual">The object being examined</param>
/// <param name="message">A message to display in case of failure</param>
/// <param name="args">Arguments for use in formatting the message</param>
public AssignableFromAsserter( System.Type expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the object to determine if it can be assigned from the expected Type
/// </summary>
/// <returns>True if the object is assignable</returns>
public override bool Test()
{
return actual.GetType().IsAssignableFrom(expected);
}
/// <summary>
/// A string representing what was expected. Used as a part of the message text.
/// </summary>
protected override string Expectation
{
get { return string.Format( "Type assignable from {0}", expected ); }
}
}
#endregion
#region NotAssignableFromAsserter
/// <summary>
/// Class to Assert that an object may not be assigned from a given Type.
/// </summary>
public class NotAssignableFromAsserter : TypeAsserter
{
/// <summary>
/// Construct a NotAssignableFromAsserter
/// </summary>
/// <param name="expected">The expected Type</param>
/// <param name="actual">The object to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments to use in formatting the message</param>
public NotAssignableFromAsserter( System.Type expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the object to determine if it can be assigned from the expected Type
/// </summary>
/// <returns>True if the object is not assignable</returns>
public override bool Test()
{
return !actual.GetType().IsAssignableFrom(expected);
}
/// <summary>
/// A string representing what was expected. Used as a part of the message text.
/// </summary>
protected override string Expectation
{
get { return string.Format( "Type not assignable from {0}", expected ); }
}
}
#endregion
#region InstanceOfTypeAsserter
/// <summary>
/// Class to Assert that an object is an instance of a given Type.
/// </summary>
public class InstanceOfTypeAsserter : TypeAsserter
{
/// <summary>
/// Construct an InstanceOfTypeAsserter
/// </summary>
/// <param name="expected">The expected Type</param>
/// <param name="actual">The object to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments to use in formatting the message</param>
public InstanceOfTypeAsserter( System.Type expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the object to determine if it is an instance of the expected Type
/// </summary>
/// <returns>True if the object is an instance of the expected Type</returns>
public override bool Test()
{
return expected.IsInstanceOfType( actual );
}
/// <summary>
/// A string representing what was expected. Used as a part of the message text.
/// </summary>
protected override string Expectation
{
get
{
return string.Format( "Object to be instance of {0}", expected );
}
}
}
#endregion
#region NotInstanceOfTypeAsserter
/// <summary>
/// Class to Assert that an object is not an instance of a given Type.
/// </summary>
public class NotInstanceOfTypeAsserter : TypeAsserter
{
/// <summary>
/// Construct a NotInstanceOfTypeAsserter
/// </summary>
/// <param name="expected">The expected Type</param>
/// <param name="actual">The object to be examined</param>
/// <param name="message">The message to display in case of failure</param>
/// <param name="args">Arguments to use in formatting the message</param>
public NotInstanceOfTypeAsserter( System.Type expected, object actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test the object to determine if it is an instance of the expected Type
/// </summary>
/// <returns>True if the object is not an instance of the expected Type</returns>
public override bool Test()
{
return !expected.IsInstanceOfType( actual );
}
/// <summary>
/// A string representing what was expected. Used as a part of the message text.
/// </summary>
protected override string Expectation
{
get
{
return string.Format( "Object not an instance of {0}", expected );
}
}
}
#endregion
}

42
src/Libraries/NUnit.Framework/greaterasserter.cs

@ -0,0 +1,42 @@ @@ -0,0 +1,42 @@
using System;
namespace NUnit.Framework
{
/// <summary>
/// Class to assert that the actual value is greater than the expected value.
/// </summary>
public class GreaterAsserter : ComparisonAsserter
{
/// <summary>
/// Constructs a GreaterAsserter for two objects implementing IComparable
/// </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 GreaterAsserter( IComparable expected, IComparable actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test whether the actual is greater than the expected, building up
/// the failure message for later use if they are not.
/// </summary>
/// <returns>True if actual is greater than expected</returns>
public override bool Test()
{
if ( ((IComparable)actual).CompareTo(expected) > 0 ) return true;
DisplayDifferences();
return false;
}
private void DisplayDifferences()
{
FailureMessage.AddExpectedLine( string.Format( "Value greater than {0}", expected ) );
FailureMessage.AddActualLine(actual.ToString());
}
}
}

41
src/Libraries/NUnit.Framework/lessasserter.cs

@ -0,0 +1,41 @@ @@ -0,0 +1,41 @@
using System;
namespace NUnit.Framework
{
/// <summary>
/// Class to assert that the actual value is greater than the expected value.
/// </summary>
public class LessAsserter : ComparisonAsserter
{
/// <summary>
/// Constructs a GreaterAsserter for two objects implementing IComparable
/// </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 LessAsserter( IComparable expected, IComparable actual, string message, params object[] args )
: base( expected, actual, message, args ) { }
/// <summary>
/// Test whether the actual is greater than the expected, building up
/// the failure message for later use if they are not.
/// </summary>
/// <returns>True if actual is greater than expected</returns>
public override bool Test()
{
if ( ((IComparable)expected).CompareTo(actual) < 0 ) return true;
DisplayDifferences();
return false;
}
private void DisplayDifferences()
{
FailureMessage.AddExpectedLine( string.Format( "Value less than {0}", expected ) );
FailureMessage.AddActualLine(actual.ToString());
}
}
}

20
src/Libraries/NUnit.Framework/nunit.framework.build

@ -1,19 +1,9 @@ @@ -1,19 +1,9 @@
<?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.project.include"/>
<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>
<property name="current.build.output" value="nunit.framework"/>
<target name="build" depends="make-build-dir">
<csc target="library"
@ -23,6 +13,7 @@ @@ -23,6 +13,7 @@
nowarn="618,672">
<sources basedir=".">
<include name="*.cs"/>
<include name="../../CommonAssemblyInfo.cs"/>
</sources>
</csc>
</target>
@ -30,8 +21,9 @@ @@ -30,8 +21,9 @@
<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="*.csproj"/>
<include name="*.build"/>
<include name="*.snk"/>
<include name="*.cs"/>
</fileset>
</copy>

51
src/Libraries/NUnit.Framework/nunit.framework.dll.csproj

@ -1,7 +1,7 @@ @@ -1,7 +1,7 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectType>Local</ProjectType>
<ProductVersion>8.0.41115</ProductVersion>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{83DD7E12-A705-4DBA-9D71-09C8973D9382}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@ -10,25 +10,27 @@ @@ -10,25 +10,27 @@
<DefaultClientScript>JScript</DefaultClientScript>
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
<DefaultTargetSchema>IE50</DefaultTargetSchema>
<AssemblyOriginatorKeyFile>nunit.key</AssemblyOriginatorKeyFile>
<DelaySign>false</DelaySign>
<OutputType>Library</OutputType>
<RootNamespace>NUnit.Framework</RootNamespace>
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
<SignAssembly>true</SignAssembly>
<OutputPath>..\..\..\bin\</OutputPath>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<AssemblyOriginatorKeyFile>nunit.key</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyMode>File</AssemblyOriginatorKeyMode>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release2005|AnyCPU' ">
<DefineConstants>TRACE;VS2005</DefineConstants>
<BaseAddress>285212672</BaseAddress>
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
<DefineConstants>TRACE;StronglyNamedAssembly</DefineConstants>
<DebugSymbols>false</DebugSymbols>
<FileAlignment>4096</FileAlignment>
<NoStdLib>false</NoStdLib>
<DocumentationFile>nunit.framework.xml</DocumentationFile>
<Optimize>true</Optimize>
<RegisterForComInterop>false</RegisterForComInterop>
<RemoveIntegerChecks>false</RemoveIntegerChecks>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug2005|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>TRACE;DEBUG;VS2005</DefineConstants>
<BaseAddress>285212672</BaseAddress>
<DocumentationFile>nunit.framework.xml</DocumentationFile>
<NoWarn>1701;1702;1699</NoWarn>
</PropertyGroup>
<ItemGroup>
<Reference Include="System">
@ -42,6 +44,9 @@ @@ -42,6 +44,9 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="CommonAssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="AbstractAsserter.cs">
<SubType>Code</SubType>
</Compile>
@ -81,6 +86,7 @@ @@ -81,6 +86,7 @@
<Compile Include="ExplicitAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="GreaterAsserter.cs" />
<Compile Include="IAsserter.cs">
<SubType>Code</SubType>
</Compile>
@ -90,6 +96,8 @@ @@ -90,6 +96,8 @@
<Compile Include="IgnoreException.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="LessAsserter.cs" />
<Compile Include="ListContentsAsserter.cs" />
<Compile Include="NotEqualAsserter.cs">
<SubType>Code</SubType>
</Compile>
@ -108,10 +116,12 @@ @@ -108,10 +116,12 @@
<Compile Include="SetUpAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="SuiteAttribute.cs">
<Compile Include="SetUpFixtureAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="SuiteBuilderAttribute.cs">
<Compile Include="StringAssert.cs" />
<Compile Include="StringAsserters.cs" />
<Compile Include="SuiteAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TearDownAttribute.cs">
@ -120,9 +130,6 @@ @@ -120,9 +130,6 @@
<Compile Include="TestAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TestContext.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TestFixtureAttribute.cs">
<SubType>Code</SubType>
</Compile>
@ -132,9 +139,7 @@ @@ -132,9 +139,7 @@
<Compile Include="TestFixtureTearDownAttribute.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="TypeAsserters.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Configuration\" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

7
src/Libraries/NUnit.Framework/nunit.framework.dll.csproj.user

@ -1,7 +0,0 @@ @@ -1,7 +0,0 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<LastOpenVersion>8.0.41115</LastOpenVersion>
<ProjectView>ProjectFiles</ProjectView>
<ProjectTrust>0</ProjectTrust>
</PropertyGroup>
</Project>
Loading…
Cancel
Save