Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@973 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
27 changed files with 2364 additions and 406 deletions
File diff suppressed because it is too large
Load Diff
@ -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")] |
||||||
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
} |
||||||
@ -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 |
||||||
|
{ |
||||||
|
} |
||||||
|
} |
||||||
@ -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
|
||||||
|
} |
||||||
|
} |
||||||
@ -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
|
||||||
|
} |
||||||
@ -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 |
|
||||||
{} |
|
||||||
} |
|
||||||
@ -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" ); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -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
|
||||||
|
} |
||||||
@ -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()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
@ -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()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
@ -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…
Reference in new issue