* Imported NUnit 2.1.91 (2.2 beta) source code for new assembly.
svn path=/trunk/mcs/; revision=28098
--- /dev/null
+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.1.91.0")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing.
+//
+// Notes:
+// (*) If no key is specified, the assembly is not signed.
+// (*) KeyName refers to a key that has been installed in the Crypto Service
+// Provider (CSP) on your machine. KeyFile refers to a file which contains
+// a key.
+// (*) If the KeyFile and the KeyName values are both specified, the
+// following processing occurs:
+// (1) If the KeyName can be found in the CSP, that key is used.
+// (2) If the KeyName does not exist and the KeyFile does exist, the key
+// in the KeyFile is installed into the CSP and used.
+// (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+// When specifying the KeyFile, the location of the KeyFile should be
+// relative to the project output directory which is
+// %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+// located in the project directory, you would specify the AssemblyKeyFile
+// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+// documentation for more information on this.
+//
+#if !StronglyNamedAssembly || MONO
+[assembly: AssemblyDelaySign(false)]
+#else
+[assembly: AssemblyKeyFile("..\\..\\..\\nunit.key")]
+[assembly: AssemblyKeyName("")]
+#endif
--- /dev/null
+using System;
+using System.Collections;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for CategoryFilter.
+ /// </summary>
+ ///
+ [Serializable]
+ public class CategoryFilter : Filter
+ {
+ ArrayList categories;
+
+ public CategoryFilter() : this( false ) { }
+
+ public CategoryFilter( bool exclude ) : base( exclude )
+ {
+ categories = new ArrayList();
+ }
+
+ public CategoryFilter( string name ) : this( name, false ) { }
+
+ public CategoryFilter( string name, bool exclude ) : base( exclude )
+ {
+ categories = new ArrayList();
+ categories.Add( name );
+ }
+
+ public CategoryFilter( string[] names ) : this( names, false ) { }
+
+ public CategoryFilter( string[] names, bool exclude ) : base( exclude )
+ {
+ categories = new ArrayList();
+ categories.AddRange( names );
+ }
+
+ public void AddCategory(string name)
+ {
+ categories.Add( name );
+ }
+
+ #region IFilter Members
+
+ public override bool Pass(TestSuite suite)
+ {
+// return CheckCategories( suite ) ? !Exclude : Exclude;
+
+ if ( categories.Count == 0 ) return true;
+
+ bool pass = Exclude;
+
+ if (CheckCategories(suite))
+ return !Exclude;
+
+ foreach (Test test in suite.Tests)
+ {
+ if ( test.Filter(this) == !Exclude )
+ {
+ pass=true;
+ break;
+ }
+ }
+
+ return pass;
+ }
+
+ public override bool Pass(TestCase test)
+ {
+ if ( categories.Count == 0 )
+ return true;
+ return CheckCategories( test ) ? !Exclude : Exclude ;
+
+// if (CheckCategories(test.Parent))
+// return true;
+//
+// return CheckCategories(test);
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Method returns true if the test has a particular
+ /// category or if an ancestor test does. We don't
+ /// worry about whether this is an include or an
+ /// exclude filter at this point because only positive
+ /// categories are inherited, not their absence.
+ /// </summary>
+ private bool CheckCategories(Test test)
+ {
+ return test.HasCategory( categories )
+ || test.Parent != null
+ && test.Parent.HasCategory( categories );
+
+// if (test.Categories != null)
+// {
+// foreach (string name in categories)
+// {
+// if (test.Categories.Contains(name))
+// return true;
+// }
+// }
+//
+// return false;
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections;
+
+namespace NUnit.Core
+{
+ public class CategoryManager
+ {
+ private static Hashtable categories = new Hashtable();
+
+ public static void Add(string name)
+ {
+ categories[name] = name;
+ }
+
+ public static void Add(IList list)
+ {
+ foreach(string name in list)
+ {
+ Add(name);
+ }
+ }
+
+ public static ICollection Categories
+ {
+ get { return categories.Values; }
+ }
+
+ public static void Clear()
+ {
+ categories = new Hashtable();
+ }
+ }
+}
--- /dev/null
+2004-05-25 Sebastien Pouliot <sebastien@ximian.com>
+
+ * Imported NUnit 2.1.91 (2.2 beta) source code for new assembly.
--- /dev/null
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for EmptyFilter.
+ /// </summary>
+ public class EmptyFilter : Filter
+ {
+ #region IFilter Members
+
+ public override bool Pass(TestSuite suite)
+ {
+ return true;
+ }
+
+ public override bool Pass(TestCase test)
+ {
+ return true;
+ }
+
+ #endregion
+
+ public static EmptyFilter Empty
+ {
+ get { return new EmptyFilter(); }
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+
+ /// <summary>
+ /// The EventListener interface is used to receive notifications of
+ /// significant events while a test is being run.
+ /// </summary>
+ public interface EventListener
+ {
+ /// <summary>
+ /// Run is starting
+ /// </summary>
+ /// <param name="tests">Array of tests to be run</param>
+ void RunStarted( Test[] tests );
+
+ /// <summary>
+ /// Run finished successfully
+ /// </summary>
+ /// <param name="results">Array of test results</param>
+ void RunFinished( TestResult[] results );
+
+ /// <summary>
+ /// Run was terminated due to an exception
+ /// </summary>
+ /// <param name="exception">Exception that was thrown</param>
+ void RunFinished( Exception exception );
+
+ /// <summary>
+ /// A single test case is starting
+ /// </summary>
+ /// <param name="testCase">The test case</param>
+ void TestStarted(TestCase testCase);
+
+ /// <summary>
+ /// A test case finished
+ /// </summary>
+ /// <param name="result">Result of the test case</param>
+ void TestFinished(TestCaseResult result);
+
+ /// <summary>
+ /// A suite is starting
+ /// </summary>
+ /// <param name="suite">The suite that is starting</param>
+ void SuiteStarted(TestSuite suite);
+
+ /// <summary>
+ /// A suite finished
+ /// </summary>
+ /// <param name="result">Result of the suite</param>
+ void SuiteFinished(TestSuiteResult result);
+
+ /// <summary>
+ /// An unhandled exception occured while running a test,
+ /// but the test was not terminated.
+ /// </summary>
+ /// <param name="exception"></param>
+ void UnhandledException( Exception exception );
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Diagnostics;
+ using System.Reflection;
+
+ /// <summary>
+ /// Summary description for ExpectedExceptionTestCase.
+ /// </summary>
+ public class ExpectedExceptionTestCase : TemplateTestCase
+ {
+ private Type expectedException;
+ private string expectedMessage;
+
+ public ExpectedExceptionTestCase(object fixture, MethodInfo info, Type expectedException, string expectedMessage)
+ : base(fixture, info)
+ {
+ this.expectedException = expectedException;
+ this.expectedMessage = expectedMessage;
+ }
+
+ protected override internal void ProcessException(Exception exception, TestCaseResult testResult)
+ {
+ if (expectedException.Equals(exception.GetType()))
+ {
+ if (expectedMessage != null && !expectedMessage.Equals(exception.Message))
+ {
+ string message = string.Format("Expected exception to have message: \"{0}\" but received message \"{1}\"",
+ expectedMessage, exception.Message);
+ testResult.Failure(message, exception.StackTrace);
+ }
+ else
+ {
+ testResult.Success();
+ }
+ }
+ else if (exception is Framework.AssertionException)
+ {
+ RecordException(exception,testResult);
+ }
+ else
+ {
+ string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name;
+ testResult.Failure(message, exception.StackTrace);
+ }
+
+ return;
+ }
+
+ protected override internal void ProcessNoException(TestCaseResult testResult)
+ {
+ testResult.Failure(expectedException.Name + " was expected", null);
+ }
+ }
+}
--- /dev/null
+using System;
+using System.Collections;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for Filter.
+ /// </summary>
+ public interface IFilter
+ {
+ bool Pass(TestSuite suite);
+
+ bool Pass(TestCase test);
+ }
+
+ [Serializable]
+ public abstract class Filter : IFilter
+ {
+ private bool exclude;
+
+ public Filter() : this( false ) { }
+
+ public Filter( bool exclude )
+ {
+ this.exclude = exclude;
+ }
+
+ public bool Exclude
+ {
+ get { return exclude; }
+ set { exclude = value; }
+ }
+
+ public void Negate()
+ {
+ exclude = !exclude;
+ }
+
+ #region IFilter Members
+
+ public abstract bool Pass(TestSuite suite);
+
+ public abstract bool Pass(TestCase test);
+
+ #endregion
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Collections;
+
+ /// <summary>
+ /// Common interface supported by all representations
+ /// of a test. Only includes informational fields.
+ /// The Run method is specifically excluded to allow
+ /// for data-only representations of a test.
+ /// </summary>
+ public interface ITest
+ {
+ /// <summary>
+ /// Name of the test
+ /// </summary>
+ string Name { get; }
+
+ /// <summary>
+ /// Full Name of the test
+ /// </summary>
+ string FullName { get; }
+
+ /// <summary>
+ /// Last part of the full name
+ /// </summary>
+ string ShortName { get; }
+
+ /// <summary>
+ /// Int used to distinguish suites of the same
+ /// name across multiple assemblies.
+ /// </summary>
+ int AssemblyKey { get; set; }
+
+ /// <summary>
+ /// Key used to look up a test in a hash table
+ /// </summary>
+ string UniqueName { get; }
+
+ /// <summary>
+ /// Whether or not the test should be run
+ /// </summary>
+ bool ShouldRun { get; set; }
+
+ /// <summary>
+ /// Reason for not running the test, if applicable
+ /// </summary>
+ string IgnoreReason { get; set; }
+
+ /// <summary>
+ /// Count of the test cases ( 1 if this is a test case )
+ /// </summary>
+ int CountTestCases();
+
+ /// <summary>
+ /// For a test suite, the child tests or suites
+ /// Null if this is not a test suite
+ /// </summary>
+ ArrayList Tests { get; }
+
+ /// <summary>
+ /// Categories available for this test
+ /// </summary>
+ IList Categories { get; }
+
+ bool HasCategory( string name );
+
+ bool HasCategory( IList names );
+
+ /// <summary>
+ /// True if this is a suite
+ /// </summary>
+ bool IsSuite { get; }
+
+ /// <summary>
+ /// True if this is a TestFixture
+ /// </summary>
+ bool IsFixture { get; }
+
+ /// <summary>
+ /// True if this is a TestCase
+ /// </summary>
+ bool IsTestCase { get; }
+
+ /// <summary>
+ /// Return the description field.
+ /// </summary>
+ string Description { get; set; }
+
+ /// <summary>
+ /// True if this should only be run explicitly - that is
+ /// if it was marked with the ExplicitAttribute.
+ /// </summary>
+ bool IsExplicit { get; set; }
+ }
+}
+
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Defines events related to the loading of tests.
+ /// </summary>
+ public interface ILoadEvents
+ {
+ event TestEventHandler TestLoading;
+ event TestEventHandler TestLoaded;
+ event TestEventHandler TestLoadFailed;
+
+ event TestEventHandler TestReloading;
+ event TestEventHandler TestReloaded;
+ event TestEventHandler TestReloadFailed;
+
+ event TestEventHandler TestUnloading;
+ event TestEventHandler TestUnloaded;
+ event TestEventHandler TestUnloadFailed;
+ }
+
+ /// <summary>
+ /// Defines events related to the running of tests.
+ /// </summary>
+ public interface IRunEvents
+ {
+ // Events related to a running a set of tests
+ event TestEventHandler RunStarting;
+ event TestEventHandler RunFinished;
+
+ // Events that arise while a test is running
+ // These are translated from calls to the runner on the
+ // EventListener interface.
+ event TestEventHandler SuiteStarting;
+ event TestEventHandler SuiteFinished;
+ event TestEventHandler TestStarting;
+ event TestEventHandler TestFinished;
+
+ /// <summary>
+ /// An unhandled exception was thrown during a test run,
+ /// and it cannot be associated with a particular test failure.
+ /// </summary>
+ event TestEventHandler TestException;
+ }
+
+ /// <summary>
+ /// The combined interface, typically implemented by test runners.
+ /// </summary>
+ public interface ITestEvents : ILoadEvents, IRunEvents
+ {
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for InvalidFixture.
+ /// </summary>
+ public class InvalidFixture
+ {
+ private Type fixtureType;
+ private string message;
+
+ public InvalidFixture(Type original, string why)
+ {
+ fixtureType = original;
+ message = why;
+ }
+
+ public Type OriginalType
+ {
+ get { return fixtureType; }
+ }
+
+ public string Message
+ {
+ get { return message; }
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Runtime.Serialization;
+
+ [Serializable]
+ public class InvalidSuiteException : ApplicationException
+ {
+ public InvalidSuiteException () : base()
+ {}
+
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ public InvalidSuiteException(string message) : base (message)
+ {}
+
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ /// <param name="inner">The exception that caused the
+ /// current exception</param>
+ public InvalidSuiteException(string message, Exception inner) :
+ base(message, inner)
+ {}
+
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected InvalidSuiteException(SerializationInfo info,
+ StreamingContext context) : base(info,context){}
+
+ }
+}
\ No newline at end of file
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Summary description for NoTestMethodsException.
+ /// </summary>
+ ///
+ [Serializable]
+ public class InvalidTestFixtureException : ApplicationException
+ {
+ public InvalidTestFixtureException() : base() {}
+
+ public InvalidTestFixtureException(string message) : base(message)
+ {}
+
+ public InvalidTestFixtureException(string message, Exception inner) : base(message, inner)
+ {}
+
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected InvalidTestFixtureException(SerializationInfo info,
+ StreamingContext context) : base(info,context){}
+
+ }
+}
\ No newline at end of file
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// All objects which are marshalled by reference
+ /// and whose lifetime is manually controlled by
+ /// the app, should derive from this class rather
+ /// than MarshalByRefObject.
+ ///
+ /// This includes the remote test domain objects
+ /// which are accessed by the client and those
+ /// client objects which are called back by the
+ /// remote test domain.
+ ///
+ /// Objects in this category that already inherit
+ /// from some other class (e.g. from TextWriter)
+ /// which in turn inherits from MarshalByRef object
+ /// should override InitializeLifetimeService to
+ /// return null to obtain the same effect.
+ /// </summary>
+ public class LongLivingMarshalByRefObject : MarshalByRefObject
+ {
+ public override Object InitializeLifetimeService()
+ {
+ return null;
+ }
+ }
+}
--- /dev/null
+thisdir = nunit20/core
+SUBDIRS =
+include ../../build/rules.make
+
+LIBRARY = nunit.core.dll
+LOCAL_MCS_FLAGS= -r:nunit.framework.dll -r:System.dll /d:StronglyNamedAssembly
+NO_TEST = yo
+
+EXTRA_DISTFILES = nunit.core.dll.csproj
+
+include ../../build/library.make
--- /dev/null
+using System;
+using System.Collections;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for NameFilter.
+ /// </summary>
+ ///
+ [Serializable]
+ public class NameFilter : Filter
+ {
+ private ArrayList testNodes;
+
+ public NameFilter(Test node)
+ {
+ testNodes = new ArrayList();
+ testNodes.Add(node);
+ }
+
+ public NameFilter(ArrayList nodes)
+ {
+ testNodes = nodes;
+ }
+
+ public override bool Pass(TestSuite suite)
+ {
+ bool passed = Exclude;
+
+ foreach (Test node in testNodes)
+ {
+ if (suite.IsDescendant(node) || node.IsDescendant(suite) || node == suite)
+ {
+ passed = !Exclude;
+ break;
+ }
+ }
+
+ return passed;
+ }
+
+ public override bool Pass(TestCase test)
+ {
+ bool passed = Exclude;
+
+ foreach(Test node in testNodes)
+ {
+ if (test.IsDescendant(node) || test == node)
+ {
+ passed = !Exclude;
+ break;
+ }
+ }
+
+ return passed;
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Summary description for NoTestFixtureException.
+ /// </summary>
+ [Serializable]
+ public class NoTestFixturesException : ApplicationException
+ {
+ public NoTestFixturesException() : base () {}
+
+ public NoTestFixturesException(string message) : base(message)
+ {}
+
+ public NoTestFixturesException(string message, Exception inner) : base(message, inner) {}
+
+ protected NoTestFixturesException(SerializationInfo info, StreamingContext context) : base(info, context)
+ {}
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Reflection;
+
+ /// <summary>
+ /// Summary description for TestCase.
+ /// </summary>
+ public class NormalTestCase : TemplateTestCase
+ {
+ public NormalTestCase(object fixture, MethodInfo method) : base(fixture, method)
+ {}
+
+ protected internal override void ProcessNoException(TestCaseResult testResult)
+ {
+ testResult.Success();
+ }
+
+ protected internal override void ProcessException(Exception exception, TestCaseResult testResult)
+ {
+ RecordException( exception, testResult );
+ }
+ }
+}
+
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+using System.Reflection;
+using System.Diagnostics;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for NotRunnableTestCase.
+ /// </summary>
+ public class NotRunnableTestCase : TestCase
+ {
+ public NotRunnableTestCase(MethodInfo method, string reason) : base(method.DeclaringType.FullName, method.Name)
+ {
+ ShouldRun = false;
+ IgnoreReason = reason;
+ }
+
+ public NotRunnableTestCase(MethodInfo method) : base(method.DeclaringType.FullName, method.Name)
+ {
+ string reason;
+
+ if (method.IsAbstract)
+ reason = "it must not be abstract";
+ else if (method.IsStatic)
+ reason = "it must be an instance method";
+ else if (!method.IsPublic)
+ reason = "it must be a public method";
+ else if (method.GetParameters().Length != 0)
+ reason = "it must not have parameters";
+ else if (!method.ReturnType.Equals(typeof(void)))
+ reason = "it must return void";
+ else
+ reason = "reason not known";
+
+ ShouldRun = false;
+ IgnoreReason = String.Format("Method {0}'s signature is not correct: {1}.", method.Name, reason);
+ }
+
+ public override void Run(TestCaseResult result)
+ {
+ result.NotRun(base.IgnoreReason);
+ }
+ }
+}
+
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for NullListener.
+ /// </summary>
+ ///
+ [Serializable]
+ public class NullListener : EventListener
+ {
+ public void RunStarted( Test[] tests ){ }
+
+ public void RunFinished( TestResult[] results ) { }
+
+ public void RunFinished( Exception exception ) { }
+
+ public void TestStarted(TestCase testCase){}
+
+ public void TestFinished(TestCaseResult result){}
+
+ public void SuiteStarted(TestSuite suite){}
+
+ public void SuiteFinished(TestSuiteResult result){}
+
+ public void UnhandledException( Exception exception ) {}
+
+ public static EventListener NULL
+ {
+ get { return new NullListener();}
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Thrown when an assertion failed. Here to preserve the inner
+ /// exception and hence its stack trace.
+ /// </summary>
+ ///
+ [Serializable]
+ public class NunitException : ApplicationException
+ {
+ public NunitException () : base()
+ {}
+
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ public NunitException(string message) : base (message)
+ {}
+
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ /// <param name="inner">The exception that caused the
+ /// current exception</param>
+ public NunitException(string message, Exception inner) :
+ base(message, inner)
+ {}
+
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected NunitException(SerializationInfo info,
+ StreamingContext context) : base(info,context){}
+
+
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.IO;
+ using System.Collections;
+ using System.Reflection;
+ using System.Threading;
+ using System.Runtime.Remoting;
+
+ /// <summary>
+ /// Summary description for RemoteTestRunner.
+ /// </summary>
+ ///
+ [Serializable]
+ public class RemoteTestRunner : LongLivingMarshalByRefObject, TestRunner, EventListener
+ {
+ #region Instance variables
+
+ /// <summary>
+ /// The loaded test suite
+ /// </summary>
+ private TestSuite suite;
+
+ /// <summary>
+ /// Our writer for standard output
+ /// </summary>
+ private TextWriter outText;
+
+ /// <summary>
+ /// Our writer for error output
+ /// </summary>
+ private TextWriter errorText;
+
+ /// <summary>
+ /// Saved paths of the assemblies we loaded - used to set
+ /// current directory when we are running the tests.
+ /// </summary>
+ private string[] assemblies;
+
+ /// <summary>
+ /// Dispatcher used to put out runner's test events
+ /// </summary>
+ private TestEventDispatcher events = new TestEventDispatcher();
+
+ private EventListener listener; // Temp
+
+ private Version frameworkVersion;
+
+ private IFilter filter;
+
+ private bool displayTestLabels;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Construct with stdOut and stdErr writers
+ /// </summary>
+ public RemoteTestRunner( TextWriter outText, TextWriter errorText )
+ {
+ this.outText = outText;
+ this.errorText = errorText;
+ }
+
+ /// <summary>
+ /// Default constructor uses Null writers.
+ /// </summary>
+ public RemoteTestRunner() : this( TextWriter.Null, TextWriter.Null ) { }
+
+ #endregion
+
+ #region Properties
+
+ /// <summary>
+ /// Writer for standard output
+ /// </summary>
+ public TextWriter Out
+ {
+ get { return outText; }
+ set { outText = value; }
+ }
+
+ /// <summary>
+ /// Writer for error output
+ /// </summary>
+ public TextWriter Error
+ {
+ get { return errorText; }
+ set { errorText = value; }
+ }
+
+ /// <summary>
+ /// Interface to the events sourced by the runner
+ /// </summary>
+ public ITestEvents Events
+ {
+ get { return events; }
+ }
+
+ public Version FrameworkVersion
+ {
+ get { return frameworkVersion; }
+ }
+
+ public bool DisplayTestLabels
+ {
+ get { return displayTestLabels; }
+ set { displayTestLabels = value; }
+ }
+
+ #endregion
+
+ #region Methods for Loading Tests
+
+ /// <summary>
+ /// Load an assembly
+ /// </summary>
+ /// <param name="assemblyName"></param>
+ public Test Load( string assemblyName )
+ {
+ this.assemblies = new string[] { assemblyName };
+ TestSuiteBuilder builder = new TestSuiteBuilder();
+ suite = builder.Build( assemblyName );
+ frameworkVersion = builder.FrameworkVersion;
+ return suite;
+ }
+
+ /// <summary>
+ /// Load a particular test in an assembly
+ /// </summary>
+ public Test Load( string assemblyName, string testName )
+ {
+ this.assemblies = new string[] { assemblyName };
+ TestSuiteBuilder builder = new TestSuiteBuilder();
+ suite = builder.Build( assemblyName, testName );
+ frameworkVersion = builder.FrameworkVersion;
+ return suite;
+ }
+
+ /// <summary>
+ /// Load multiple assemblies
+ /// </summary>
+ public Test Load( string projectName, string[] assemblies )
+ {
+ this.assemblies = (string[])assemblies.Clone();
+ TestSuiteBuilder builder = new TestSuiteBuilder();
+ suite = builder.Build( projectName, assemblies );
+ frameworkVersion = builder.FrameworkVersion;
+ return suite;
+ }
+
+ public Test Load( string projectName, string[] assemblies, string testName )
+ {
+ this.assemblies = (string[])assemblies.Clone();
+ TestSuiteBuilder builder = new TestSuiteBuilder();
+ suite = builder.Build( assemblies, testName );
+ frameworkVersion = builder.FrameworkVersion;
+ return suite;
+ }
+
+ public void Unload()
+ {
+ suite = null; // All for now
+ frameworkVersion = null;
+ }
+
+ #endregion
+
+ #region Methods for Counting TestCases
+
+ public int CountTestCases()
+ {
+ return suite.CountTestCases();
+ }
+
+ public int CountTestCases( string testName )
+ {
+ Test test = FindTest( suite, testName );
+ return test == null ? 0 : test.CountTestCases();
+ }
+
+ public int CountTestCases(string[] testNames )
+ {
+ int count = 0;
+ foreach( string testName in testNames)
+ count += CountTestCases( testName );
+
+ return count;
+ }
+
+ public ICollection GetCategories()
+ {
+ return CategoryManager.Categories;
+ }
+
+ #endregion
+
+ #region Methods for Running Tests
+
+ public void SetFilter( IFilter filter )
+ {
+ this.filter = filter;
+ }
+
+// public TestResult Run(NUnit.Core.EventListener listener, IFilter filter)
+// {
+// BufferedStringTextWriter outBuffer = new BufferedStringTextWriter( outText );
+// BufferedStringTextWriter errorBuffer = new BufferedStringTextWriter( errorText );
+//
+// TextWriter saveOut = Console.Out;
+// TextWriter saveError = Console.Error;
+//
+// Console.SetOut( outBuffer );
+// Console.SetError( errorBuffer );
+//
+//// string currentDirectory = Environment.CurrentDirectory;
+////
+//// string assemblyName = assemblies == null ? testFileName : (string)assemblies[test.AssemblyKey];
+//// string assemblyDirectory = Path.GetDirectoryName( assemblyName );
+////
+//// if ( assemblyDirectory != null && assemblyDirectory != string.Empty )
+//// Environment.CurrentDirectory = assemblyDirectory;
+//
+//
+// try
+// {
+// TestResult result = suite.Run(listener, filter);
+// return result;
+// }
+// finally
+// {
+//
+// // Environment.CurrentDirectory = currentDirectory;
+//
+// outBuffer.Close();
+// errorBuffer.Close();
+//
+// // Helps us when we run tests of this class, among other things
+// Console.SetOut( saveOut );
+// Console.SetError( saveError );
+// }
+// }
+
+ public TestResult Run( EventListener listener )
+ {
+ return Run( listener, suite );
+ }
+
+ public TestResult Run(NUnit.Core.EventListener listener, string testName )
+ {
+ return Run( listener, FindTest( suite, testName ) );
+ }
+
+ public TestResult[] Run(NUnit.Core.EventListener listener, string[] testNames)
+ {
+ return Run( listener, FindTests( suite, testNames ) );
+ }
+
+ // Temporary implementation - runs synchronously
+ public void RunTest(NUnit.Core.EventListener listener )
+ {
+ runningThread = new TestRunnerThread( this );
+ runningThread.Run( listener );
+ }
+
+ // Temporary implementation - runs synchronously
+ public void RunTest(NUnit.Core.EventListener listener, string testName )
+ {
+ runningThread = new TestRunnerThread( this );
+ runningThread.Run( listener, testName );
+ }
+
+ // Temporary implementation - runs synchronously
+ public void RunTest(NUnit.Core.EventListener listener, string[] testNames)
+ {
+ runningThread = new TestRunnerThread( this );
+ runningThread.Run( listener, testNames );
+ }
+
+ private TestRunnerThread runningThread;
+
+ public void CancelRun()
+ {
+ if ( runningThread != null )
+ runningThread.Cancel();
+ }
+
+ #endregion
+
+ #region Helper Routines
+
+ /// <summary>
+ /// Private method to run a single test
+ /// </summary>
+ private TestResult Run( EventListener listener, Test test )
+ {
+ // Create array with the one test
+ Test[] tests = new Test[] { test };
+ // Call our workhorse method
+ TestResult[] results = Run( listener, tests );
+ // Return the first result we got
+ return results[0];
+ }
+
+ /// <summary>
+ /// Private method to run a set of tests. This routine is the workhorse
+ /// that is called anytime tests are run.
+ /// </summary>
+ private TestResult[] Run( EventListener listener, Test[] tests )
+ {
+ // Create buffered writers for efficiency
+ BufferedStringTextWriter outBuffer = new BufferedStringTextWriter( outText );
+ BufferedStringTextWriter errorBuffer = new BufferedStringTextWriter( errorText );
+
+ // Save previous state of Console. This is needed because Console.Out and
+ // Console.Error are static. In the case where the test itself calls this
+ // method, we can lose output if we don't save and restore their values.
+ // This is exactly what happens when we are testing NUnit itself.
+ TextWriter saveOut = Console.Out;
+ TextWriter saveError = Console.Error;
+
+ // Set Console to go to our buffers. Note that any changes made by
+ // the user in the test code or the code it calls will defeat this.
+ Console.SetOut( outBuffer );
+ Console.SetError( errorBuffer );
+
+ // Save the current directory so we can run each test in
+ // the same directory as its assembly
+ string currentDirectory = Environment.CurrentDirectory;
+
+ try
+ {
+ // Create an array for the resuls
+ TestResult[] results = new TestResult[ tests.Length ];
+
+ // Signal that we are starting the run
+ this.listener = listener;
+ listener.RunStarted( tests );
+
+ // TODO: Get rid of count
+ int count = 0;
+ foreach( Test test in tests )
+ count += filter == null ? test.CountTestCases() : test.CountTestCases( filter );
+
+ events.FireRunStarting( tests, count );
+
+ // Run each test, saving the results
+ int index = 0;
+ foreach( Test test in tests )
+ {
+ string assemblyDirectory = Path.GetDirectoryName( this.assemblies[test.AssemblyKey] );
+
+ if ( assemblyDirectory != null && assemblyDirectory != string.Empty )
+ Environment.CurrentDirectory = assemblyDirectory;
+
+ results[index] = test.Run( this, filter );
+ }
+
+ // Signal that we are done
+ listener.RunFinished( results );
+ events.FireRunFinished( results );
+
+ // Return result array
+ return results;
+ }
+ catch( Exception exception )
+ {
+ // Signal that we finished with an exception
+ listener.RunFinished( exception );
+ events.FireRunFinished( exception );
+ // Rethrow - should we do this?
+ throw;
+ }
+ finally
+ {
+ // Restore the directory we saved
+ Environment.CurrentDirectory = currentDirectory;
+
+ // Close our output buffers
+ outBuffer.Close();
+ errorBuffer.Close();
+
+ // Restore previous console values
+ Console.SetOut( saveOut );
+ Console.SetError( saveError );
+ }
+ }
+
+ private Test FindTest(Test test, string fullName)
+ {
+ if(test.UniqueName.Equals(fullName)) return test;
+ if(test.FullName.Equals(fullName)) return test;
+
+ Test result = null;
+ if(test is TestSuite)
+ {
+ TestSuite suite = (TestSuite)test;
+ foreach(Test testCase in suite.Tests)
+ {
+ result = FindTest(testCase, fullName);
+ if(result != null) break;
+ }
+ }
+
+ return result;
+ }
+
+ private Test[] FindTests( Test test, string[] names )
+ {
+ Test[] tests = new Test[ names.Length ];
+
+ int index = 0;
+ foreach( string name in names )
+ tests[index++] = FindTest( test, name );
+
+ return tests;
+ }
+
+ #endregion
+
+ #region EventListener Members
+
+ public void RunStarted(Test[] tests)
+ {
+ // TODO: Remove
+ }
+
+ void NUnit.Core.EventListener.RunFinished(TestResult[] results)
+ {
+ // TODO: Remove
+ outText.Close();
+ }
+
+ void NUnit.Core.EventListener.RunFinished(Exception exception)
+ {
+ // TODO: Remove
+ outText.Close();
+ }
+
+ public void TestStarted(TestCase testCase)
+ {
+ if ( displayTestLabels )
+ outText.WriteLine("***** {0}", testCase.FullName );
+
+ this.listener.TestStarted( testCase );
+ events.FireTestStarting( testCase );
+ }
+
+ void NUnit.Core.EventListener.TestFinished(TestCaseResult result)
+ {
+ listener.TestFinished( result );
+ events.FireTestFinished( result );
+ }
+
+ public void SuiteStarted(TestSuite suite)
+ {
+ listener.SuiteStarted( suite );
+ events.FireSuiteStarting( suite );
+ }
+
+ void NUnit.Core.EventListener.SuiteFinished(TestSuiteResult result)
+ {
+ listener.SuiteFinished( result );
+ events.FireSuiteFinished( result );
+ }
+
+ public void UnhandledException(Exception exception)
+ {
+ listener.UnhandledException( exception );
+ events.FireTestException( exception );
+ }
+
+ #endregion
+ }
+}
+
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+
+ /// <summary>
+ ///
+ /// </summary>
+ public interface ResultVisitor
+ {
+ void Visit(TestCaseResult caseResult);
+ void Visit(TestSuiteResult suiteResult);
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
+ <xs:complexType name="failureType">
+ <xs:sequence>
+ <xs:element ref="message" />
+ <xs:element ref="stack-trace" />
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="reasonType">
+ <xs:sequence>
+ <xs:element ref="message" />
+ </xs:sequence>
+ </xs:complexType>
+ <xs:element name="message" type="xs:string" />
+ <xs:complexType name="resultsType">
+ <xs:choice>
+ <xs:element name="test-suite" type="test-suiteType" maxOccurs="unbounded" />
+ <xs:element name="test-case" type="test-caseType" maxOccurs="unbounded" minOccurs="0" />
+ </xs:choice>
+ </xs:complexType>
+ <xs:element name="stack-trace" type="xs:string" />
+ <xs:element name="test-results" type="resultType" />
+ <xs:complexType name="categoriesType">
+ <xs:sequence>
+ <xs:element name="category" type="categoryType" maxOccurs="unbounded" minOccurs="1"/>
+ </xs:sequence>
+ </xs:complexType>
+ <xs:complexType name="categoryType">
+ <xs:attribute name="name" type="xs:string" use="required"/>
+ </xs:complexType>
+ <xs:complexType name="resultType">
+ <xs:sequence>
+ <xs:element name="test-suite" type="test-suiteType" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="total" type="xs:decimal" use="required" />
+ <xs:attribute name="failures" type="xs:decimal" use="required" />
+ <xs:attribute name="not-run" type="xs:decimal" use="required" />
+ <xs:attribute name="date" type="xs:string" use="required" />
+ <xs:attribute name="time" type="xs:string" use="required" />
+ </xs:complexType>
+ <xs:complexType name="test-caseType">
+ <xs:sequence>
+ <xs:element name="categories" type="categoriesType" minOccurs="0" maxOccurs="1" />
+ <xs:choice>
+ <xs:element name="failure" type="failureType" minOccurs="0" />
+ <xs:element name="reason" type="reasonType" minOccurs="0" />
+ </xs:choice>
+ </xs:sequence>
+
+ <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="description" type="xs:string" use="optional" />
+ <xs:attribute name="success" type="xs:string" use="optional" />
+ <xs:attribute name="time" type="xs:string" use="optional" />
+ <xs:attribute name="executed" type="xs:string" use="required" />
+ <xs:attribute name="asserts" type="xs:string" use="optional" />
+ </xs:complexType>
+ <xs:complexType name="test-suiteType">
+ <xs:sequence>
+ <xs:element name="categories" type="categoriesType" minOccurs="0" maxOccurs="1" />
+ <xs:element name="results" type="resultsType" />
+ </xs:sequence>
+ <xs:attribute name="name" type="xs:string" use="required" />
+ <xs:attribute name="description" type="xs:string" use="optional" />
+ <xs:attribute name="success" type="xs:string" use="required" />
+ <xs:attribute name="time" type="xs:string" use="required" />
+ <xs:attribute name="asserts" type="xs:string" use="optional" />
+ </xs:complexType>
+
+</xs:schema>
\ No newline at end of file
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// TestSuite forming the root of a test project
+ /// </summary>
+ public class RootTestSuite : TestSuite
+ {
+ public RootTestSuite( string projectName ) : base( projectName )
+ {
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+using System.IO;
+using System.Text;
+
+namespace NUnit.Core
+{
+ #region StringTextWriter
+
+ /// <summary>
+ /// Use this wrapper to ensure that only strings get passed accross the AppDomain
+ /// boundary. Otherwise tests will break when non-remotable objects are passed to
+ /// Console.Write/WriteLine.
+ /// </summary>
+ public class StringTextWriter : TextWriter
+ {
+ public StringTextWriter( TextWriter aTextWriter )
+ {
+ theTextWriter = aTextWriter;
+ }
+
+ protected TextWriter theTextWriter;
+
+ override public void Write(char aChar)
+ {
+ theTextWriter.Write(aChar);
+ }
+
+ override public void Write(string aString)
+ {
+ theTextWriter.Write(aString);
+ }
+
+ override public void WriteLine(string aString)
+ {
+ theTextWriter.WriteLine(aString);
+ }
+
+ override public System.Text.Encoding Encoding
+ {
+ get { return theTextWriter.Encoding; }
+ }
+
+ public override void Close()
+ {
+ this.Flush();
+ theTextWriter.Close ();
+ }
+
+ public override void Flush()
+ {
+ theTextWriter.Flush ();
+ }
+ }
+
+ #endregion
+
+ #region BufferedStringTextWriter
+
+ /// <summary>
+ /// This wrapper derives from StringTextWriter and adds buffering
+ /// to improve cross-domain performance. The buffer is flushed whenever
+ /// it reaches or exceeds a maximum size or when Flush is called.
+ /// </summary>
+ public class BufferedStringTextWriter : StringTextWriter
+ {
+ public BufferedStringTextWriter( TextWriter aTextWriter ) : base( aTextWriter ){ }
+
+ private static readonly int MAX_BUFFER = 1000;
+ private StringBuilder sb = new StringBuilder( MAX_BUFFER );
+
+ override public void Write(char aChar)
+ {
+ lock( sb )
+ {
+ sb.Append( aChar );
+ this.CheckBuffer();
+ }
+ }
+
+ override public void Write(string aString)
+ {
+ lock( sb )
+ {
+ sb.Append( aString );
+ this.CheckBuffer();
+ }
+ }
+
+ override public void WriteLine(string aString)
+ {
+ lock( sb )
+ {
+ sb.Append( aString );
+ sb.Append( '\n' );
+ this.CheckBuffer();
+ }
+ }
+
+ override public void Flush()
+ {
+ if ( sb.Length > 0 )
+ {
+ lock( sb )
+ {
+ theTextWriter.Write( sb.ToString() );
+ sb.Length = 0;
+ }
+ }
+
+ theTextWriter.Flush();
+ }
+
+ private void CheckBuffer()
+ {
+ if ( sb.Length >= MAX_BUFFER )
+ this.Flush();
+ }
+ }
+
+ #endregion
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+<xsl:output method='text'/>
+
+<xsl:template match="/">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="test-results">
+<xsl:text>Tests run: </xsl:text>
+<xsl:value-of select="@total"/>
+<xsl:text>, Failures: </xsl:text>
+<xsl:value-of select="@failures"/>
+<xsl:text>, Not run: </xsl:text>
+<xsl:value-of select="@not-run"/>
+<xsl:text>, Time: </xsl:text>
+<xsl:value-of select="test-suite/@time"/>
+<xsl:text> seconds
+</xsl:text>
+<xsl:text>
+</xsl:text>
+
+<xsl:if test="//test-case[failure]"><xsl:text>Failures:
+</xsl:text></xsl:if>
+<xsl:apply-templates select="//test-case[failure]"/>
+<xsl:if test="//test-case[@executed='False']"><xsl:text>Tests not run:
+</xsl:text></xsl:if>
+<xsl:apply-templates select="//test-case[@executed='False']"/>
+<xsl:text disable-output-escaping='yes'>
</xsl:text>
+</xsl:template>
+
+<xsl:template match="test-case">
+ <xsl:value-of select="position()"/><xsl:text>) </xsl:text>
+ <xsl:value-of select="@name"/>
+ <xsl:text> : </xsl:text>
+ <xsl:value-of select="child::node()/message"/>
+<xsl:text disable-output-escaping='yes'>
</xsl:text>
+ <xsl:if test="failure">
+ <xsl:value-of select="failure/stack-trace"/>
+<xsl:text>
+</xsl:text>
+ </xsl:if>
+</xsl:template>
+
+</xsl:stylesheet>
+
+
\ No newline at end of file
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Text;
+ using System.Reflection;
+
+ /// <summary>
+ /// Summary description for TestCase.
+ /// </summary>
+ public abstract class TemplateTestCase : TestCase
+ {
+ private object fixture;
+ private MethodInfo method;
+
+
+ public TemplateTestCase(object fixture, MethodInfo method) : base(fixture.GetType().FullName, method.Name)
+ {
+ this.fixture = fixture;
+ this.method = method;
+ }
+
+ public override void Run(TestCaseResult testResult)
+ {
+ if ( ShouldRun )
+ {
+ bool doParentSetUp = Parent != null && !Parent.IsSetUp;
+
+ try
+ {
+ if ( doParentSetUp )
+ Parent.DoSetUp( testResult );
+
+ if ( !testResult.IsFailure )
+ doRun( testResult );
+ }
+ finally
+ {
+ if ( doParentSetUp )
+ Parent.DoTearDown( testResult );
+ }
+ }
+ else
+ {
+ testResult.NotRun(this.IgnoreReason);
+ }
+ }
+
+ /// <summary>
+ /// The doRun method is used to run a test internally.
+ /// It assumes that the caller is taking care of any
+ /// TestFixtureSetUp and TestFixtureTearDown needed.
+ /// </summary>
+ /// <param name="testResult">The result in which to record success or failure</param>
+ public void doRun( TestCaseResult testResult )
+ {
+ DateTime start = DateTime.Now;
+
+ try
+ {
+ doSetUp( testResult );
+ if ( !testResult.IsFailure )
+ doTestCase( testResult );
+ }
+ finally
+ {
+ doTearDown( testResult );
+
+ DateTime stop = DateTime.Now;
+ TimeSpan span = stop.Subtract(start);
+ testResult.Time = (double)span.Ticks / (double)TimeSpan.TicksPerSecond;
+ }
+ }
+
+ #region Invoke Methods by Reflection, Recording Errors
+
+ private void doTestFixtureSetUp( TestCaseResult testResult )
+ {
+ }
+
+ private void doTestFixtureTearDown( TestCaseResult testResult )
+ {
+ }
+
+ private void doSetUp( TestCaseResult testResult )
+ {
+ try
+ {
+ invokeSetUp();
+ }
+ catch(Exception ex)
+ {
+ if ( ex is NunitException )
+ ex = ex.InnerException;
+ RecordException( ex, testResult );
+ }
+ }
+
+ private void doTearDown( TestCaseResult testResult )
+ {
+ try
+ {
+ invokeTearDown();
+ }
+ catch(Exception ex)
+ {
+ if ( ex is NunitException )
+ ex = ex.InnerException;
+ RecordException(ex, testResult, true);
+ }
+ }
+
+ private void doTestCase( TestCaseResult testResult )
+ {
+ try
+ {
+ invokeTestCase();
+ ProcessNoException(testResult);
+ }
+ catch( Exception ex )
+ {
+ if ( ex is NunitException )
+ ex = ex.InnerException;
+
+ ProcessException(ex, testResult);
+ }
+ }
+
+ #endregion
+
+ #region Record Info About An Exception
+
+ protected void RecordException( Exception exception, TestCaseResult testResult )
+ {
+ RecordException( exception, testResult, false );
+ }
+
+ protected void RecordException( Exception exception, TestCaseResult testResult, bool inTearDown )
+ {
+ StringBuilder msg = new StringBuilder();
+ StringBuilder st = new StringBuilder();
+
+ if ( inTearDown )
+ {
+ msg.Append( testResult.Message );
+ msg.Append( Environment.NewLine );
+ msg.Append( "TearDown : " );
+ st.Append( testResult.StackTrace );
+ st.Append( Environment.NewLine );
+ st.Append( "--TearDown" );
+ st.Append( Environment.NewLine );
+ }
+
+ msg.Append( BuildMessage( exception ) );
+ st.Append( BuildStackTrace( exception ) );
+ testResult.Failure( msg.ToString(), st.ToString() );
+ }
+
+ private string BuildMessage(Exception exception)
+ {
+ StringBuilder sb = new StringBuilder();
+ if ( exception is NUnit.Framework.AssertionException )
+ sb.Append( exception.Message );
+ else
+ sb.AppendFormat( "{0} : {1}", exception.GetType().ToString(), exception.Message );
+
+ Exception inner = exception.InnerException;
+ while( inner != null )
+ {
+ sb.Append( Environment.NewLine );
+ sb.AppendFormat( " ----> {0} : {1}", inner.GetType().ToString(), inner.Message );
+ inner = inner.InnerException;
+ }
+
+ return sb.ToString();
+ }
+
+ private string BuildStackTrace(Exception exception)
+ {
+ if(exception.InnerException!=null)
+ return exception.StackTrace + Environment.NewLine +
+ "--" + exception.GetType().Name + Environment.NewLine +
+ BuildStackTrace(exception.InnerException);
+ else
+ return exception.StackTrace;
+ }
+
+ #endregion
+
+ #region Invoking Methods by Reflection
+
+ private void invokeSetUp()
+ {
+ MethodInfo method = findSetUpMethod(fixture);
+ if(method != null)
+ {
+ InvokeMethod(method, fixture);
+ }
+ }
+
+ private MethodInfo findSetUpMethod(object fixture)
+ {
+ return FindMethodByAttribute(fixture, typeof(NUnit.Framework.SetUpAttribute));
+ }
+
+ private void invokeTearDown()
+ {
+ MethodInfo method = findTearDownMethod(fixture);
+ if(method != null)
+ {
+ InvokeMethod(method, fixture);
+ }
+ }
+
+ private MethodInfo findTearDownMethod(object fixture)
+ {
+ return FindMethodByAttribute(fixture, typeof(NUnit.Framework.TearDownAttribute));
+ }
+
+ private void invokeTestCase()
+ {
+ try
+ {
+ method.Invoke(fixture, null);
+ }
+ catch(TargetInvocationException e)
+ {
+ Exception inner = e.InnerException;
+ throw new NunitException("Rethrown",inner);
+ }
+ }
+
+ #endregion
+
+ #region Abstract Methods
+
+ protected internal abstract void ProcessNoException(TestCaseResult testResult);
+
+ protected internal abstract void ProcessException(Exception exception, TestCaseResult testResult);
+
+ #endregion
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Collections;
+ using System.Reflection;
+
+ /// <summary>
+ /// Test Class.
+ /// </summary>
+ public abstract class Test : LongLivingMarshalByRefObject, ITest, IComparable
+ {
+ #region Private Fields
+
+ /// <summary>
+ /// Name of the test
+ /// </summary>
+ private string testName;
+
+ /// <summary>
+ /// Full Name of the test
+ /// </summary>
+ private string fullName;
+
+ /// <summary>
+ /// Int used to distinguish suites of the same
+ /// name across multiple assemblies.
+ /// </summary>
+ private int assemblyKey;
+
+ /// <summary>
+ /// Whether or not the test should be run
+ /// </summary>
+ private bool shouldRun;
+
+ /// <summary>
+ /// Reason for not running the test, if applicable
+ /// </summary>
+ private string ignoreReason;
+
+ /// <summary>
+ /// Description for this test
+ /// </summary>
+ private string description;
+
+ /// <summary>
+ /// Test suite containing this test, or null
+ /// </summary>
+ private TestSuite parent;
+
+ /// <summary>
+ /// List of categories applying to this test
+ /// </summary>
+ private IList categories;
+
+ /// <summary>
+ /// True if the test had the Explicit attribute
+ /// </summary>
+ private bool isExplicit;
+
+ #endregion
+
+ #region Constructors
+
+ public Test( string name ) : this( name, 0 ) { }
+
+ public Test( string name, int assemblyKey )
+ {
+ fullName = testName = name;
+ this.assemblyKey = assemblyKey;
+ }
+
+ protected Test( string pathName, string testName )
+ : this( pathName, testName, 0 ) { }
+
+ protected Test( string pathName, string testName, int assemblyKey )
+ {
+ fullName = pathName + "." + testName;
+ this.testName = testName;
+ this.assemblyKey = assemblyKey;
+ shouldRun = true;
+ }
+
+ #endregion
+
+ #region Properties
+
+ public string Name
+ {
+ get { return testName; }
+ }
+
+ public string FullName
+ {
+ get { return fullName; }
+ }
+
+ /// <summary>
+ /// If the name is a path, this just returns the file part
+ /// </summary>
+ public string ShortName
+ {
+ get
+ {
+ string name = Name;
+ int val = name.LastIndexOf("\\");
+ if(val != -1)
+ name = name.Substring(val+1);
+ return name;
+ }
+ }
+
+ /// <summary>
+ /// Int used to distinguish suites of the same
+ /// name across multiple assemblies.
+ /// </summary>
+ public int AssemblyKey
+ {
+ get { return assemblyKey; }
+ set { assemblyKey = value; }
+ }
+
+ /// <summary>
+ /// Key used to look up a test in a hash table
+ /// </summary>
+ public string UniqueName
+ {
+ get { return string.Format( "[{0}]{1}", assemblyKey, fullName ); }
+ }
+
+ /// <summary>
+ /// Whether or not the test should be run
+ /// </summary>
+ public virtual bool ShouldRun
+ {
+ get { return shouldRun; }
+ set { shouldRun = value; }
+ }
+
+ /// <summary>
+ /// Reason for not running the test, if applicable
+ /// </summary>
+ public string IgnoreReason
+ {
+ get { return ignoreReason; }
+ set { ignoreReason = value; }
+ }
+
+ public TestSuite Parent
+ {
+ get { return parent; }
+ set { parent = value; }
+ }
+
+ public string TestPath
+ {
+ get
+ {
+ string testPath = "";
+ if (parent != null)
+ testPath = parent.TestPath;
+ return testPath + FullName;
+ }
+ }
+
+ public IList Categories
+ {
+ get { return categories; }
+ set { categories = value; }
+ }
+
+ public bool HasCategory( string name )
+ {
+ return categories != null && categories.Contains( name );
+ }
+
+ public bool HasCategory( IList names )
+ {
+ if ( categories == null )
+ return false;
+
+ foreach( string name in names )
+ if ( categories.Contains( name ) )
+ return true;
+
+ return false;
+ }
+
+ public bool IsDescendant(Test test)
+ {
+ if (parent != null)
+ {
+ return parent == test || parent.IsDescendant(test);
+ }
+
+ return false;
+ }
+
+ public String Description
+ {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public bool IsExplicit
+ {
+ get { return isExplicit; }
+ set { isExplicit = value; }
+ }
+
+ #endregion
+
+ #region Abstract Methods and Properties
+
+ /// <summary>
+ /// Count of the test cases ( 1 if this is a test case )
+ /// </summary>
+ public abstract int CountTestCases();
+ public abstract int CountTestCases(IFilter filter);
+
+ public abstract bool IsSuite { get; }
+ public abstract bool IsFixture{ get; }
+ public abstract bool IsTestCase{ get; }
+ public abstract ArrayList Tests { get; }
+
+ public abstract bool Filter(IFilter filter);
+
+ public abstract TestResult Run( EventListener listener );
+ public abstract TestResult Run(EventListener listener, IFilter filter);
+
+ #endregion
+
+ #region Protected Helper Methods
+
+ protected MethodInfo FindMethodByAttribute(object fixture, Type type)
+ {
+ foreach(MethodInfo method in fixture.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic))
+ {
+ if(method.IsDefined(type,true))
+ {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ protected void InvokeMethod(MethodInfo method, object fixture)
+ {
+ if(method != null)
+ {
+ try
+ {
+ method.Invoke(fixture, null);
+ }
+ catch(TargetInvocationException e)
+ {
+ Exception inner = e.InnerException;
+ throw new NunitException("Rethrown",inner);
+ }
+ }
+ }
+
+ #endregion
+
+ #region IComparable Members
+
+ public int CompareTo(object obj)
+ {
+ Test other = obj as Test;
+
+ if ( other == null )
+ return -1;
+
+ return this.FullName.CompareTo( other.FullName );
+ }
+
+ #endregion
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+using System.IO;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Test Suite formed from an assembly.
+ /// Class name changed from TestAssembly
+ /// to avoid conflict with namespace.
+ /// </summary>
+ public class AssemblyTestSuite : TestSuite
+ {
+ public AssemblyTestSuite( string assembly ) : this( assembly, 0 )
+ {
+ }
+
+ public AssemblyTestSuite( string assembly, int key) : base( assembly, key )
+ {
+ }
+
+ public override TestResult Run(EventListener listener)
+ {
+ string directoryName = Path.GetDirectoryName( this.Name );
+
+ if ( directoryName != null && directoryName != string.Empty )
+ Environment.CurrentDirectory = directoryName;
+
+ return base.Run( listener );
+ }
+
+ public override TestResult Run(EventListener listener, IFilter filter)
+ {
+ string directoryName = Path.GetDirectoryName( this.Name );
+
+ if ( directoryName != null && directoryName != string.Empty )
+ Environment.CurrentDirectory = directoryName;
+
+ return base.Run( listener, filter );
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Collections;
+
+ /// <summary>
+ /// Summary description for TestCase.
+ /// </summary>
+ public abstract class TestCase : Test
+ {
+ public TestCase(string path, string name) : base(path, name)
+ {}
+
+ public override int CountTestCases()
+ {
+ return 1;
+ }
+
+ public override int CountTestCases(IFilter filter)
+ {
+ if (Filter(filter))
+ return 1;
+
+ return 0;
+ }
+
+ public override TestResult Run(EventListener listener, IFilter filter)
+ {
+ return Run( listener ); // Ignore filter for now
+ }
+
+ public override TestResult Run( EventListener listener )
+ {
+ TestCaseResult testResult = new TestCaseResult(this);
+
+ listener.TestStarted(this);
+ long startTime = DateTime.Now.Ticks;
+
+ Run( testResult );
+
+ testResult.AssertCount = NUnit.Framework.Assert.Counter;
+
+ long stopTime = DateTime.Now.Ticks;
+ double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
+ testResult.Time = time;
+
+ listener.TestFinished(testResult);
+ return testResult;
+ }
+
+ public override bool IsSuite
+ {
+ get { return false; }
+ }
+
+ public override bool IsFixture
+ {
+ get { return false; }
+ }
+
+ public override bool IsTestCase
+ {
+ get { return true; }
+ }
+
+ public override ArrayList Tests
+ {
+ get { return null; }
+ }
+
+ public override bool Filter(IFilter filter)
+ {
+ return filter.Pass(this);
+ }
+
+ public abstract void Run(TestCaseResult result);
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Reflection;
+ using System.Collections;
+
+ /// <summary>
+ /// Summary description for TestCaseBuilder.
+ /// </summary>
+ public class TestCaseBuilder
+ {
+ private static Hashtable builders;
+ private static ITestBuilder normalBuilder = new NormalBuilder();
+
+ private static void InitBuilders()
+ {
+ builders = new Hashtable();
+ builders[typeof(NUnit.Framework.ExpectedExceptionAttribute)] = new ExpectedExceptionBuilder();
+ }
+
+ private static ITestBuilder GetBuilder(MethodInfo method)
+ {
+ if (builders == null)
+ InitBuilders();
+
+ object[] attributes = method.GetCustomAttributes(false);
+
+ foreach (object attribute in attributes)
+ {
+ ITestBuilder builder = (ITestBuilder) builders[attribute.GetType()];
+ if (builder != null)
+ return builder;
+ }
+
+ return normalBuilder;
+ }
+
+ public static TestCase Make(object fixture, MethodInfo method)
+ {
+ TestCase testCase = null;
+
+ if(HasTestAttribute(method) || HasObsoleteTestName(method) && !HasAnySetUpOrTearDownAttribute(method) )
+ {
+ if(IsTestMethodSignatureCorrect(method))
+ {
+ ITestBuilder builder = GetBuilder(method);
+ testCase = builder.Make(fixture, method);
+
+ if(HasIgnoreAttribute(method))
+ {
+ testCase.ShouldRun = false;
+ testCase.IgnoreReason = GetIgnoreReason(method);
+ }
+
+ if (HasCategoryAttribute(method))
+ {
+ IList categories = GetCategories(method);
+ CategoryManager.Add(categories);
+ testCase.Categories = categories;
+ }
+
+ testCase.IsExplicit = HasExplicitAttribute(method);
+
+ testCase.Description = GetDescription(method);
+ }
+ else
+ {
+ testCase = new NotRunnableTestCase(method);
+ }
+ }
+
+ return testCase;
+ }
+
+ public static TestCase Make(object fixture, string methodName)
+ {
+ MethodInfo [] methods = fixture.GetType().GetMethods(BindingFlags.NonPublic|BindingFlags.Public|BindingFlags.Instance);
+ foreach(MethodInfo method in methods)
+ {
+ if(method.Name.Equals(methodName))
+ return Make(fixture, method);
+ }
+
+ return null;
+ }
+
+ private static bool IsExpectedException(MethodInfo method)
+ {
+ Type exceptionAttr = typeof(NUnit.Framework.ExpectedExceptionAttribute);
+ object[] attributes = method.GetCustomAttributes(exceptionAttr, false);
+ return attributes.Length == 1;
+ }
+
+ private static NUnit.Framework.ExpectedExceptionAttribute GetExpectedExceptions(MethodInfo method)
+ {
+ Type exceptionAttr = typeof(NUnit.Framework.ExpectedExceptionAttribute);
+ object[] attributes = method.GetCustomAttributes(exceptionAttr, false);
+
+ NUnit.Framework.ExpectedExceptionAttribute expectedAttr = null;
+
+ if(attributes.Length == 1)
+ {
+ expectedAttr = (NUnit.Framework.ExpectedExceptionAttribute)attributes[0];
+ }
+
+ return expectedAttr;
+ }
+
+ private static string GetDescription(MethodInfo method)
+ {
+ Type testAttr = typeof(NUnit.Framework.TestAttribute);
+ object[] attributes = method.GetCustomAttributes(testAttr, false);
+
+ string description = null;
+
+ if(attributes.Length == 1)
+ {
+ NUnit.Framework.TestAttribute attribute =
+ (NUnit.Framework.TestAttribute)attributes[0];
+ description = attribute.Description;
+ }
+
+ return description;
+ }
+
+
+ public static int CountTestCases(object fixture)
+ {
+ int testCases = 0;
+
+ MethodInfo [] methods = fixture.GetType().GetMethods();
+ foreach(MethodInfo method in methods)
+ {
+ if(IsTestMethod(method))
+ testCases++;
+ }
+
+ return testCases;
+ }
+
+
+ public static bool IsTestMethod(MethodInfo methodToCheck)
+ {
+ return
+ (HasTestAttribute(methodToCheck) || HasObsoleteTestName(methodToCheck))
+ && IsTestMethodSignatureCorrect(methodToCheck);
+ }
+
+ private static bool IsTestMethodSignatureCorrect(MethodInfo methodToCheck)
+ {
+ return
+ !methodToCheck.IsStatic
+ && !methodToCheck.IsAbstract
+ && methodToCheck.IsPublic
+ && methodToCheck.GetParameters().Length == 0
+ && methodToCheck.ReturnType.Equals(typeof(void));
+ }
+
+ private static bool HasTestAttribute(MethodInfo methodToCheck)
+ {
+ return methodToCheck.IsDefined(typeof(NUnit.Framework.TestAttribute),false);
+ }
+
+ private static bool HasObsoleteTestName(MethodInfo methodToCheck)
+ {
+ return methodToCheck.Name.ToLower().StartsWith("test");
+ }
+
+ private static bool HasAnySetUpOrTearDownAttribute( MethodInfo methodToCheck )
+ {
+ object[] attributes = methodToCheck.GetCustomAttributes( false );
+ foreach( Attribute attribute in attributes )
+ if ( attribute is NUnit.Framework.SetUpAttribute ||
+ attribute is NUnit.Framework.TestFixtureSetUpAttribute ||
+ attribute is NUnit.Framework.TearDownAttribute ||
+ attribute is NUnit.Framework.TestFixtureTearDownAttribute )
+ return true;
+
+ return false;
+ }
+
+ private static bool HasIgnoreAttribute(MethodInfo methodToCheck)
+ {
+ Type ignoreMethodAttribute = typeof(NUnit.Framework.IgnoreAttribute);
+ object[] attributes = methodToCheck.GetCustomAttributes(ignoreMethodAttribute, false);
+ return attributes.Length == 1;
+ }
+
+ private static string GetIgnoreReason(MethodInfo methodToCheck)
+ {
+ Type ignoreMethodAttribute = typeof(NUnit.Framework.IgnoreAttribute);
+ NUnit.Framework.IgnoreAttribute[] attributes = (NUnit.Framework.IgnoreAttribute[])methodToCheck.GetCustomAttributes(ignoreMethodAttribute, false);
+ string result = "no reason";
+ if(attributes.Length > 0)
+ result = attributes[0].Reason;
+
+ return result;
+ }
+
+ private static bool HasCategoryAttribute(MethodInfo methodToCheck)
+ {
+ object[] attributes = methodToCheck.GetCustomAttributes(typeof(NUnit.Framework.CategoryAttribute), false);
+ return attributes.Length > 0;
+ }
+
+ private static bool HasExplicitAttribute(MethodInfo methodToCheck)
+ {
+ object[] attributes = methodToCheck.GetCustomAttributes(typeof(NUnit.Framework.ExplicitAttribute), false);
+ return attributes.Length > 0;
+ }
+
+ private static IList GetCategories(MethodInfo methodToCheck)
+ {
+ object[] attributes = methodToCheck.GetCustomAttributes(typeof(NUnit.Framework.CategoryAttribute), false);
+ ArrayList list = new ArrayList();
+ foreach (NUnit.Framework.CategoryAttribute attrib in attributes)
+ {
+ list.Add(attrib.Name);
+ }
+
+ return list;
+ }
+ }
+
+ internal interface ITestBuilder
+ {
+ TestCase Make(object fixture, MethodInfo method);
+ }
+
+ internal class ExpectedExceptionBuilder : ITestBuilder
+ {
+ #region ITestBuilder Members
+
+ public TestCase Make(object fixture, MethodInfo method)
+ {
+ NUnit.Framework.ExpectedExceptionAttribute expectedException = GetExpectedExceptions(method);
+ TestCase testCase = new ExpectedExceptionTestCase(fixture, method, expectedException.ExceptionType, expectedException.ExpectedMessage);
+
+ return testCase;
+ }
+
+ #endregion
+
+ private static NUnit.Framework.ExpectedExceptionAttribute GetExpectedExceptions(MethodInfo method)
+ {
+ Type exceptionAttr = typeof(NUnit.Framework.ExpectedExceptionAttribute);
+ object[] attributes = method.GetCustomAttributes(exceptionAttr, false);
+
+ NUnit.Framework.ExpectedExceptionAttribute expectedAttr = null;
+
+ if(attributes.Length == 1)
+ {
+ expectedAttr = (NUnit.Framework.ExpectedExceptionAttribute)attributes[0];
+ }
+
+ return expectedAttr;
+ }
+
+ }
+
+ internal class NormalBuilder : ITestBuilder
+ {
+ #region ITestBuilder Members
+
+ public TestCase Make(object fixture, MethodInfo method)
+ {
+ return new NormalTestCase(fixture, method);
+ }
+
+ #endregion
+
+ }
+
+
+}
+
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Text;
+
+ /// <summary>
+ ///
+ /// </summary>
+ //
+ [Serializable]
+ public class TestCaseResult : TestResult
+ {
+ public TestCaseResult(ITest testCase):base(testCase, testCase.FullName)
+ {
+ Executed = false;
+ }
+
+ public TestCaseResult(string testCaseString) : base(null, testCaseString)
+ {
+ Executed = false;
+ }
+
+ public void Success()
+ {
+ Executed = true;
+ IsFailure = false;
+ }
+
+ public override void NotRun(string reason)
+ {
+ Executed = false;
+ messageString = reason;
+ }
+
+ public void Failure(string message, string stackTrace)
+ {
+ Executed = true;
+ IsFailure = true;
+ this.messageString = message;
+ StackTrace = stackTrace;
+ }
+
+ public override string ToString()
+ {
+ StringBuilder builder = new StringBuilder();
+ string name = Name;
+ if ( Test != null )
+ name = Test.FullName;
+
+ builder.AppendFormat("{0} : " , name);
+ if(!IsSuccess)
+ builder.Append(messageString);
+
+ return builder.ToString();
+ }
+
+ public override void Accept(ResultVisitor visitor)
+ {
+ visitor.Visit(this);
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// The delegate for all events related to running tests
+ /// </summary>
+ public delegate void TestEventHandler ( object sender, TestEventArgs args );
+
+ /// <summary>
+ /// Enumeration used to distiguish test events
+ /// </summary>
+ public enum TestAction
+ {
+ // Test Load Events
+ TestLoading,
+ TestLoaded,
+ TestLoadFailed,
+ TestReloading,
+ TestReloaded,
+ TestReloadFailed,
+ TestUnloading,
+ TestUnloaded,
+ TestUnloadFailed,
+ // Test Run Events
+ RunStarting,
+ RunFinished,
+ SuiteStarting,
+ SuiteFinished,
+ TestStarting,
+ TestFinished,
+ TestException
+ }
+
+ /// <summary>
+ /// Argument used for all test events
+ /// </summary>
+ public class TestEventArgs : EventArgs
+ {
+ #region Instance Variables
+
+ // The action represented by the event
+ private TestAction action;
+
+ // The name of the test or other item
+ private string name;
+
+ // The tests we are running
+ private Test[] tests;
+
+ // The results from our tests
+ private TestResult[] results;
+
+ // The exception causing a failure
+ private Exception exception;
+
+ // TODO: Remove this count of test cases
+ private int count;
+
+ #endregion
+
+ #region Constructors
+
+ public TestEventArgs( TestAction action,
+ string name, Test test )
+ {
+ this.action = action;
+ this.name = name;
+ this.tests = new Test[] { test };
+ }
+
+ public TestEventArgs( TestAction action, string name )
+ {
+ this.action = action;
+ this.name = name;
+ }
+
+ public TestEventArgs( TestAction action,
+ string name, Exception exception )
+ {
+ this.action = action;
+ this.name = name;
+ this.exception = exception;
+ }
+
+ public TestEventArgs( TestAction action, Test test )
+ {
+ this.action = action;
+ this.tests = new Test[] { test };
+ this.count = test.CountTestCases();
+ }
+
+ public TestEventArgs( TestAction action, TestResult result )
+ {
+ this.action = action;
+ this.results = new TestResult[] { result };
+ }
+
+ public TestEventArgs( TestAction action, TestResult[] results )
+ {
+ this.action = action;
+ this.results = results;
+ }
+
+ public TestEventArgs( TestAction action, Exception exception )
+ {
+ this.action = action;
+ this.exception = exception;
+ }
+
+ public TestEventArgs( TestAction action, Test[] tests, int count)
+ {
+ this.action = action;
+ this.tests = tests;
+ this.count = count;
+ }
+
+ #endregion
+
+ #region Properties
+
+ public TestAction Action
+ {
+ get { return action; }
+ }
+
+ public string Name
+ {
+ get { return name; }
+ }
+
+// public bool IsProjectFile
+// {
+// get { return NUnitProject.IsProjectFile( testFileName ); }
+// }
+
+ public Test Test
+ {
+ get { return tests[0]; }
+ }
+
+ public Test[] Tests
+ {
+ get { return tests; }
+ }
+
+ public int TestCount
+ {
+ get { return count; }
+ }
+
+ public TestResult Result
+ {
+ get { return results[0]; }
+ }
+
+ public TestResult[] Results
+ {
+ get { return results; }
+ }
+
+ public Exception Exception
+ {
+ get { return exception; }
+ }
+
+ #endregion
+ }
+}
--- /dev/null
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Helper class used by runner to dispatch test events
+ /// </summary>
+ public class TestEventDispatcher : ITestEvents
+ {
+ #region Events
+
+ // Test loading events
+ public event TestEventHandler TestLoading;
+ public event TestEventHandler TestLoaded;
+ public event TestEventHandler TestLoadFailed;
+
+ public event TestEventHandler TestReloading;
+ public event TestEventHandler TestReloaded;
+ public event TestEventHandler TestReloadFailed;
+
+ public event TestEventHandler TestUnloading;
+ public event TestEventHandler TestUnloaded;
+ public event TestEventHandler TestUnloadFailed;
+
+ // Test running events
+ public event TestEventHandler RunStarting;
+ public event TestEventHandler RunFinished;
+
+ public event TestEventHandler SuiteStarting;
+ public event TestEventHandler SuiteFinished;
+
+ public event TestEventHandler TestStarting;
+ public event TestEventHandler TestFinished;
+
+ public event TestEventHandler TestException;
+
+ #endregion
+
+ #region Methods for Firing Events
+
+ private void Fire(
+ TestEventHandler handler, TestEventArgs e )
+ {
+ if ( handler != null )
+ handler( this, e );
+ }
+
+ public void FireTestLoading( string fileName )
+ {
+ Fire(
+ TestLoading,
+ new TestEventArgs( TestAction.TestLoading, fileName ) );
+ }
+
+ public void FireTestLoaded( string fileName, Test test )
+ {
+ Fire(
+ TestLoaded,
+ new TestEventArgs( TestAction.TestLoaded, fileName, test ) );
+ }
+
+ public void FireTestLoadFailed( string fileName, Exception exception )
+ {
+ Fire(
+ TestLoadFailed,
+ new TestEventArgs( TestAction.TestLoadFailed, fileName, exception ) );
+ }
+
+ public void FireTestUnloading( string fileName, Test test )
+ {
+ Fire(
+ TestUnloading,
+ new TestEventArgs( TestAction.TestUnloading, fileName, test ) );
+ }
+
+ public void FireTestUnloaded( string fileName, Test test )
+ {
+ Fire(
+ TestUnloaded,
+ new TestEventArgs( TestAction.TestUnloaded, fileName, test ) );
+ }
+
+ public void FireTestUnloadFailed( string fileName, Exception exception )
+ {
+ Fire(
+ TestUnloadFailed,
+ new TestEventArgs( TestAction.TestUnloadFailed, fileName, exception ) );
+ }
+
+ public void FireTestReloading( string fileName, Test test )
+ {
+ Fire(
+ TestReloading,
+ new TestEventArgs( TestAction.TestReloading, fileName, test ) );
+ }
+
+ public void FireTestReloaded( string fileName, Test test )
+ {
+ Fire(
+ TestReloaded,
+ new TestEventArgs( TestAction.TestReloaded, fileName, test ) );
+ }
+
+ public void FireTestReloadFailed( string fileName, Exception exception )
+ {
+ Fire(
+ TestReloadFailed,
+ new TestEventArgs( TestAction.TestReloadFailed, fileName, exception ) );
+ }
+
+ public void FireRunStarting( Test[] tests, int count )
+ {
+ Fire(
+ RunStarting,
+ new TestEventArgs( TestAction.RunStarting, tests, count ) );
+ }
+
+ public void FireRunFinished( TestResult[] results )
+ {
+ Fire(
+ RunFinished,
+ new TestEventArgs( TestAction.RunFinished, results ) );
+ }
+
+ public void FireRunFinished( Exception exception )
+ {
+ Fire(
+ RunFinished,
+ new TestEventArgs( TestAction.RunFinished, exception ) );
+ }
+
+ public void FireTestStarting( Test test )
+ {
+ Fire(
+ TestStarting,
+ new TestEventArgs( TestAction.TestStarting, test ) );
+ }
+
+ public void FireTestFinished( TestResult result )
+ {
+ Fire(
+ TestFinished,
+ new TestEventArgs( TestAction.TestFinished, result ) );
+ }
+
+ public void FireSuiteStarting( Test test )
+ {
+ Fire(
+ SuiteStarting,
+ new TestEventArgs( TestAction.SuiteStarting, test ) );
+ }
+
+ public void FireSuiteFinished( TestResult result )
+ {
+ Fire(
+ SuiteFinished,
+ new TestEventArgs( TestAction.SuiteFinished, result ) );
+ }
+
+ public void FireTestException( Exception exception )
+ {
+ Fire(
+ TestException,
+ new TestEventArgs( TestAction.TestException, exception ) );
+ }
+
+ #endregion
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+
+ /// <summary>
+ /// Summary description for TestResult.
+ /// </summary>
+ ///
+ [Serializable]
+ public abstract class TestResult
+ {
+ private bool executed;
+ private bool isFailure;
+ private double time;
+ private string name;
+ private ITest test;
+ private string stackTrace;
+ private string description;
+ protected string messageString;
+ private int assertCount;
+
+ protected TestResult(ITest test, string name)
+ {
+ this.name = name;
+ this.test = test;
+ if(test != null)
+ this.description = test.Description;
+ }
+
+ public bool Executed
+ {
+ get { return executed; }
+ set { executed = value; }
+ }
+
+ public virtual bool AllTestsExecuted
+ {
+ get { return executed; }
+ }
+
+ public virtual string Name
+ {
+ get{ return name;}
+ }
+
+ public ITest Test
+ {
+ get{ return test;}
+ }
+
+ public virtual bool IsSuccess
+ {
+ get { return !(isFailure); }
+ }
+
+ public virtual bool IsFailure
+ {
+ get { return isFailure; }
+ set { isFailure = value; }
+ }
+
+ public virtual string Description
+ {
+ get { return description; }
+ set { description = value; }
+ }
+
+ public double Time
+ {
+ get{ return time; }
+ set{ time = value; }
+ }
+
+ public string Message
+ {
+ get { return messageString; }
+ }
+
+ public virtual string StackTrace
+ {
+ get
+ {
+ return stackTrace;
+ }
+ set
+ {
+ stackTrace = value;
+ }
+ }
+
+ public int AssertCount
+ {
+ get { return assertCount; }
+ set { assertCount = value; }
+ }
+
+ public abstract void NotRun(string message);
+
+ public abstract void Accept(ResultVisitor visitor);
+ }
+}
--- /dev/null
+using System;
+using System.Collections;
+using System.IO;
+using System.Threading;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// The TestRunner Interface is allows client code, such as the NUnit console and
+ /// gui runners, to load and run tests. This is the lowest level interface generally
+ /// supported for running tests and is implemented by the RemoteTestRunner class in
+ /// the NUnit core as well as by other classes running on the client side.
+ ///
+ /// The Load family of methods is used to load a suite of tests from one or more
+ /// assemblies, returning the resulting test suite to the caller.
+ ///
+ /// The CountTestCases family of methods returns the number of test cases in the
+ /// loaded suite, either in its entirety or by taking a subset of tests as roots.
+ ///
+ /// The Run family of methods performs a test run synchronously, returning a TestResult
+ /// or TestResult[] to the caller. If provided, an EventListener interface will be
+ /// notified of significant events in the running of the tests.
+ ///
+ /// The RunTest family of methods uses the same set of signatures as Run but operates
+ /// asynchronously. The final result of the run may be obtained through the user of an
+ /// EventListener or through the Results property.
+ /// </summary>
+ public interface TestRunner
+ {
+ #region Properties
+
+ /// <summary>
+ /// The Out property is used to redirect any test output, which is sent to
+ /// Console.Out. It must not be changed while a test is running.
+ /// </summary>
+ TextWriter Out
+ {
+ get; set;
+ }
+
+ /// <summary>
+ /// The Error property is used to redirect any test output, which is sent to
+ /// Console.Error. It must not be changed while a test is running.
+ /// </summary>
+ TextWriter Error
+ {
+ get; set;
+ }
+
+ /// <summary>
+ /// IsTestRunning indicates whether a test is in progress. MayTo retrieve the
+ /// results from an asynchronous test run, wait till IsTestRunning is false.
+ /// </summary>
+ // bool IsTestRunning
+ // {
+ // get;
+ // }
+
+ Version FrameworkVersion
+ {
+ get;
+ }
+
+ /// <summary>
+ /// Setting to show a header line for each test case in
+ /// the console output.
+ /// </summary>
+ bool DisplayTestLabels
+ {
+ get; set;
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Load all tests from an assembly
+ /// </summary>
+ /// <param name="assemblyName">The assembly from which tests are to be loaded</param>
+ Test Load( string assemblyName );
+
+ /// <summary>
+ /// Load a particular test in an assembly
+ /// </summary>
+ /// <param name="assemblyName">The assembly from which tests are to be loaded</param>
+ /// <param name="testName">The name of the test fixture or suite to be loaded</param>
+ Test Load( string assemblyName, string testName );
+
+ /// <summary>
+ /// Load multiple assemblies
+ /// </summary>
+ /// <param name="projectName">The project name to use for the root test node</param>
+ /// <param name="assemblies">The assemblies from which tests are to be loaded</param>
+ Test Load( string projectName, string[] assemblies );
+
+ /// <summary>
+ /// Load a particular test in a set of assemblies
+ /// </summary>
+ /// <param name="projectName">The project name to use for the root test node</param>
+ /// <param name="assemblies">The assemblies from which tests are to be loaded</param>
+ /// <param name="testName">The name of the test fixture or suite to be loaded</param>
+ Test Load( string projectName, string[] assemblies, string testName );
+
+ /// <summary>
+ /// Unload all tests previously loaded
+ /// </summary>
+ void Unload();
+
+ void SetFilter( IFilter filter );
+
+ /// <summary>
+ /// Count test cases previously loaded
+ /// </summary>
+ /// <returns>The number of test cases found</returns>
+ int CountTestCases();
+
+ /// <summary>
+ /// Count Test Cases under a given test name
+ /// </summary>
+ /// <param name="testName">The name of a test case, fixture or suite</param>
+ /// <returns>The number of test cases found</returns>
+ int CountTestCases(string testName );
+
+ /// <summary>
+ /// Count test cases starting at a set of roots
+ /// </summary>
+ /// <param name="testNames">An array of names of test cases, fixtures or suites</param>
+ /// <returns>The number of test cases found</returns>
+ int CountTestCases(string[] testNames);
+
+ /// <summary>
+ /// Get the collectiion of categories used by the runner;
+ /// </summary>
+ /// <returns></returns>
+ ICollection GetCategories();
+
+ /// <summary>
+ /// Run the loaded tests using a test filter
+ /// </summary>
+// TestResult Run(NUnit.Core.EventListener listener, IFilter filter);
+
+ /// <summary>
+ /// Run all loaded tests and return a test result. The test is run synchronously,
+ /// and the listener interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to receive EventListener notifications.</param>
+ TestResult Run(NUnit.Core.EventListener listener);
+
+ /// <summary>
+ /// Run a particular loaded test and return a test result. The test is run
+ /// synchronously and the listener interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to receive EventListener notifications</param>
+ /// <param name="testName">The name of the test case, fixture or suite to be run</param>
+ TestResult Run(NUnit.Core.EventListener listener, string testName);
+
+ /// <summary>
+ /// Run a set of loaded tests and return a set of results. The test is run
+ /// synchronously and the listener interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to receive EventListener notifications</param>
+ /// <param name="testNames">The names of the test cases, fixtures or suites to be run</param>
+ TestResult[] Run(NUnit.Core.EventListener listener, string[] testNames);
+
+ /// <summary>
+ /// Run all loaded tests. The test is run asynchronously and the listener
+ /// interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to an object to receive EventListener notifications</param>
+ void RunTest(NUnit.Core.EventListener listener);
+
+ /// <summary>
+ /// Run a particular loaded test. The test is run asynchronously and the
+ /// listener interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to an object to receive EventListener notifications</param>
+ /// <param name="testName">The name of the test case, fixture or suite to be run</param>
+ void RunTest(NUnit.Core.EventListener listener, string testName);
+
+ /// <summary>
+ /// Run a set of loaded tests. The tests are run asynchronously and the
+ /// listener interface is notified as it progresses.
+ /// </summary>
+ /// <param name="listener">Interface to an object to receive EventListener notifications</param>
+ /// <param name="testNames">The names of the test cases, fixtures or suites to be run</param>
+ void RunTest(NUnit.Core.EventListener listener, string[] testNames);
+
+ void CancelRun();
+ }
+}
--- /dev/null
+using System;
+using System.IO;
+using System.Threading;
+using System.Configuration;
+using System.Collections.Specialized;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for TestRunnerThread.
+ /// </summary>
+ public class TestRunnerThread
+ {
+ #region Private Fields
+
+ /// <summary>
+ /// The Test runner to be used in running tests on the thread
+ /// </summary>
+ private TestRunner runner;
+
+ /// <summary>
+ /// The System.Threading.Thread created by the object
+ /// </summary>
+ private Thread thread;
+
+ /// <summary>
+ /// Collection of TestRunner settings from the config file
+ /// </summary>
+ private NameValueCollection settings;
+
+ /// <summary>
+ /// The exception that terminated a test run
+ /// </summary>
+ private Exception lastException;
+
+ /// <summary>
+ /// The EventListener interface to receive test events
+ /// </summary>
+ private NUnit.Core.EventListener listener;
+
+ /// <summary>
+ /// Array of test names for ues by the thread proc
+ /// </summary>
+ private string[] testNames;
+
+ /// <summary>
+ /// Array of returned results - needed?
+ /// </summary>
+ private TestResult[] results;
+
+ #endregion
+
+ #region Constructor
+
+ public TestRunnerThread( TestRunner runner )
+ {
+ this.runner = runner;
+ this.thread = new Thread( new ThreadStart( TestRunnerThreadProc ) );
+
+ this.settings = (NameValueCollection)
+ ConfigurationSettings.GetConfig( "NUnit/TestRunner" );
+
+ try
+ {
+ string apartment = (string)settings["ApartmentState"];
+ if ( apartment == "STA" )
+ thread.ApartmentState = ApartmentState.STA;
+ else if ( apartment == "MTA" )
+ thread.ApartmentState = ApartmentState.MTA;
+
+ string priority = (string)settings["ThreadPriority"];
+ if ( priority != null )
+ thread.Priority = (ThreadPriority)
+ System.Enum.Parse( typeof( ThreadPriority ), priority, true );
+ }
+ catch
+ {
+ // Ignore any problems for now - test will run using default settings
+ }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public void Wait()
+ {
+ if ( this.thread.IsAlive )
+ this.thread.Join();
+ }
+
+ public void Cancel()
+ {
+ this.thread.Abort();
+ this.thread.Join();
+ }
+
+ public void Run( EventListener listener )
+ {
+ this.listener = listener;
+
+ thread.Start();}
+
+ public void Run( EventListener listener, string testName )
+ {
+ this.listener = listener;
+ this.testNames = new string[] { testName };
+
+ thread.Start(); }
+
+ public void Run( EventListener listener, string[] testNames )
+ {
+ this.listener = listener;
+ this.testNames = testNames;
+
+ thread.Start();
+ }
+
+ #endregion
+
+ #region Thread Proc
+
+ /// <summary>
+ /// The thread proc for our actual test run
+ /// </summary>
+ private void TestRunnerThreadProc()
+ {
+ try
+ {
+ //TODO: do we need a run started event?
+ int count = runner.CountTestCases( testNames );
+
+ Directory.SetCurrentDirectory( AppDomain.CurrentDomain.BaseDirectory );
+ results = runner.Run(listener, testNames );
+
+ //TODO: do we need a run finished event?
+ }
+ catch( Exception exception )
+ {
+ lastException = exception;
+ //TODO: do we need a run finished event?
+ }
+ finally
+ {
+ testNames = null; // Do we need this?
+ //runningThread = null; // Ditto
+ }
+ }
+
+ #endregion
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Collections;
+ using System.Reflection;
+ using System.Text;
+
+ /// <summary>
+ /// Summary description for TestSuite.
+ /// </summary>
+ ///
+ [Serializable]
+ public class TestSuite : Test
+ {
+ private ArrayList tests = new ArrayList();
+ private MethodInfo fixtureSetUp;
+ private MethodInfo fixtureTearDown;
+ private object fixture;
+ private const string FIXTURE_SETUP_FAILED = "Fixture setup failed";
+ private const string EXPLICIT_SELECTION_REQUIRED = "Explicit selection required";
+ private bool isSetUp;
+
+ public TestSuite( string name ) : this( name, 0 ) { }
+
+ public TestSuite( string name, int assemblyKey )
+ : base( name, assemblyKey )
+ {
+ ShouldRun = true;
+ }
+
+ public void Sort()
+ {
+ this.Tests.Sort();
+
+ foreach( Test test in Tests )
+ {
+ TestSuite suite = test as TestSuite;
+ if ( suite != null )
+ suite.Sort();
+ }
+ }
+
+ public TestSuite( string parentSuiteName, string name )
+ : this( parentSuiteName, name, 0 ) { }
+
+ public TestSuite( string parentSuiteName, string name, int assemblyKey )
+ : base( parentSuiteName, name, assemblyKey )
+ {
+ ShouldRun = true;
+ }
+
+ private IList GetCategories(object fixture)
+ {
+ IList names = new ArrayList();
+ object[] attributes = fixture.GetType().GetCustomAttributes(typeof(NUnit.Framework.CategoryAttribute), true);
+ foreach(NUnit.Framework.CategoryAttribute attribute in attributes)
+ {
+ names.Add(attribute.Name);
+ }
+ return names;
+ }
+
+ protected internal virtual void Add(Test test)
+ {
+ if(test.ShouldRun)
+ {
+ test.ShouldRun = ShouldRun;
+ test.IgnoreReason = IgnoreReason;
+ }
+ test.Parent = this;
+ tests.Add(test);
+ }
+
+ protected internal virtual TestSuite CreateNewSuite(Type type)
+ {
+ int index = type.FullName.LastIndexOf( "." ) + 1;
+ string name = type.FullName.Substring( index );
+ return new TestSuite( type.Namespace, name, this.AssemblyKey);
+ }
+
+ public void Add(object fixture)
+ {
+ TestSuite testSuite = CreateNewSuite(fixture.GetType());
+ testSuite.fixture = fixture;
+ IList categories = GetCategories(fixture);
+ CategoryManager.Add(categories);
+ testSuite.Categories = categories;
+ testSuite.fixtureSetUp = this.FindMethodByAttribute(fixture, typeof(NUnit.Framework.TestFixtureSetUpAttribute));
+ testSuite.fixtureTearDown = this.FindMethodByAttribute(fixture, typeof(NUnit.Framework.TestFixtureTearDownAttribute));
+ Add(testSuite);
+
+ Type explicitAttribute = typeof(NUnit.Framework.ExplicitAttribute);
+ object[] attributes = fixture.GetType().GetCustomAttributes( explicitAttribute, false );
+ testSuite.IsExplicit = attributes.Length > 0;
+
+ Type ignoreMethodAttribute = typeof(NUnit.Framework.IgnoreAttribute);
+ attributes = fixture.GetType().GetCustomAttributes(ignoreMethodAttribute, false);
+ if(attributes.Length == 1)
+ {
+ NUnit.Framework.IgnoreAttribute attr =
+ (NUnit.Framework.IgnoreAttribute)attributes[0];
+ testSuite.ShouldRun = false;
+ testSuite.IgnoreReason = attr.Reason;
+ }
+
+ Type fixtureAttribute = typeof(NUnit.Framework.TestFixtureAttribute);
+ attributes = fixture.GetType().GetCustomAttributes(fixtureAttribute, false);
+ if(attributes.Length == 1)
+ {
+ NUnit.Framework.TestFixtureAttribute fixtureAttr =
+ (NUnit.Framework.TestFixtureAttribute)attributes[0];
+ testSuite.Description = fixtureAttr.Description;
+ }
+
+ ////////////////////////////////////////////////////////////////////////
+ // Uncomment the following code block to allow including Suites in the
+ // tree of tests. This causes a problem when the same test is added
+ // in multiple suites so we need to either fix it or prevent it.
+ //
+ // See also a line to change in TestSuiteBuilder.cs
+ ////////////////////////////////////////////////////////////////////////
+
+ PropertyInfo [] properties = fixture.GetType().GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly);
+ foreach(PropertyInfo property in properties)
+ {
+ object[] attrributes = property.GetCustomAttributes(typeof(NUnit.Framework.SuiteAttribute),false);
+ if(attrributes.Length>0)
+ {
+ MethodInfo method = property.GetGetMethod(true);
+ if(method.ReturnType!=typeof(NUnit.Core.TestSuite) || method.GetParameters().Length>0)
+ {
+ testSuite.ShouldRun = false;
+ testSuite.IgnoreReason = "Invalid suite property method signature";
+ }
+// else
+// {
+// TestSuite suite = (TestSuite)property.GetValue(null, new Object[0]);
+// foreach( Test test in suite.Tests )
+// testSuite.Add( test );
+// }
+ }
+ }
+
+ MethodInfo [] methods = fixture.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.Static|BindingFlags.NonPublic);
+ foreach(MethodInfo method in methods)
+ {
+ TestCase testCase = TestCaseBuilder.Make(fixture, method);
+ if(testCase != null)
+ {
+ testCase.AssemblyKey = testSuite.AssemblyKey;
+ testSuite.Add(testCase);
+ }
+ }
+
+ if(testSuite.CountTestCases() == 0)
+ {
+ testSuite.ShouldRun = false;
+ testSuite.IgnoreReason = testSuite.Name + " does not have any tests";
+ }
+ }
+
+ private void CheckSuiteProperty(PropertyInfo property)
+ {
+ MethodInfo method = property.GetGetMethod(true);
+ if(method.ReturnType!=typeof(NUnit.Core.TestSuite))
+ throw new InvalidSuiteException("Invalid suite property method signature");
+ if(method.GetParameters().Length>0)
+ throw new InvalidSuiteException("Invalid suite property method signature");
+ }
+
+ public override ArrayList Tests
+ {
+ get { return tests; }
+ }
+
+ public override bool IsSuite
+ {
+ get { return true; }
+ }
+
+ public override bool IsTestCase
+ {
+ get { return false; }
+ }
+
+ public bool IsSetUp
+ {
+ get { return isSetUp; }
+ }
+
+ /// <summary>
+ /// True if this is a fixture. May populate the test's
+ /// children as a side effect.
+ /// TODO: An easier way to tell this?
+ /// </summary>
+ public override bool IsFixture
+ {
+ get
+ {
+ // We have no way of constructing an empty suite unless it's a fixture
+ if ( Tests.Count == 0 ) return true;
+
+ // Any suite with children is a fixture if the children are test cases
+ Test firstChild = (Test)Tests[0];
+ return !firstChild.IsSuite;
+ }
+ }
+
+ public override int CountTestCases()
+ {
+ int count = 0;
+
+ foreach(Test test in Tests)
+ {
+ count += test.CountTestCases();
+ }
+ return count;
+ }
+
+ public override int CountTestCases(IFilter filter)
+ {
+ int count = 0;
+
+ if(this.Filter(filter))
+ {
+ foreach(Test test in Tests)
+ {
+ count += test.CountTestCases(filter);
+ }
+ }
+ return count;
+ }
+
+ public override TestResult Run(EventListener listener)
+ {
+ return Run( listener, null );
+ }
+
+ public override TestResult Run(EventListener listener, IFilter filter)
+ {
+ TestSuiteResult suiteResult = new TestSuiteResult(this, Name);
+
+ listener.SuiteStarted(this);
+ long startTime = DateTime.Now.Ticks;
+
+ if ( ShouldRun )
+ {
+ suiteResult.Executed = true;
+ doFixtureSetup( suiteResult );
+
+ RunAllTests( suiteResult, listener, filter );
+
+ doFixtureTearDown( suiteResult );
+ }
+ else
+ suiteResult.NotRun(this.IgnoreReason);
+
+ long stopTime = DateTime.Now.Ticks;
+ double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond;
+ suiteResult.Time = time;
+
+ listener.SuiteFinished(suiteResult);
+ return suiteResult;
+ }
+
+ public void DoSetUp( TestResult suiteResult )
+ {
+ doFixtureSetup( suiteResult );
+ }
+
+ public void DoTearDown( TestResult suiteResult )
+ {
+ doFixtureTearDown( suiteResult );
+ }
+
+ public void InvokeFixtureTearDown()
+ {
+ if (this.fixtureTearDown != null)
+ this.InvokeMethod(fixtureTearDown, fixture); }
+
+ private void doFixtureTearDown(TestResult suiteResult)
+ {
+ if (this.ShouldRun)
+ {
+ try
+ {
+ isSetUp = false;
+ InvokeFixtureTearDown();
+ }
+ catch (Exception ex)
+ {
+ handleFixtureException(suiteResult, ex);
+ }
+ finally
+ {
+ suiteResult.AssertCount += NUnit.Framework.Assert.Counter;
+ }
+ }
+ if (this.IgnoreReason == FIXTURE_SETUP_FAILED)
+ {
+ this.ShouldRun = true;
+ this.IgnoreReason = null;
+ }
+ }
+
+ private void doFixtureSetup(TestResult suiteResult)
+ {
+ try
+ {
+ InvokeFixtureSetUp();
+ isSetUp = true;
+ }
+ catch (Exception ex)
+ {
+ handleFixtureException(suiteResult, ex);
+ this.ShouldRun = false;
+ this.IgnoreReason = FIXTURE_SETUP_FAILED;
+ }
+ finally
+ {
+ suiteResult.AssertCount = NUnit.Framework.Assert.Counter;
+ }
+ }
+
+ private void InvokeFixtureSetUp()
+ {
+ if (this.fixtureSetUp != null)
+ this.InvokeMethod(fixtureSetUp, fixture);
+ }
+
+ private void handleFixtureException(TestResult result, Exception ex)
+ {
+ NunitException nex = ex as NunitException;
+ if (nex != null)
+ ex = nex.InnerException;
+
+ result.Executed = false;
+ result.NotRun(ex.ToString());
+ result.StackTrace = ex.StackTrace;
+ }
+
+ protected virtual void RunAllTests(
+ TestSuiteResult suiteResult, EventListener listener, IFilter filter )
+ {
+ foreach(Test test in ArrayList.Synchronized(Tests))
+ {
+ bool saveShouldRun = test.ShouldRun;
+
+ if (test.ShouldRun)
+ {
+ if (this.ShouldRun == false)
+ {
+ test.ShouldRun = false;
+ test.IgnoreReason = FIXTURE_SETUP_FAILED;
+ }
+ else if ( test.IsExplicit && filter == null )
+ {
+ test.ShouldRun = false;
+ test.IgnoreReason = EXPLICIT_SELECTION_REQUIRED;
+ }
+ }
+
+ if ( filter == null || test.Filter( filter ) )
+ suiteResult.AddResult( test.Run( listener, filter ) );
+
+ if ( saveShouldRun && !test.ShouldRun )
+ {
+ test.ShouldRun = true;
+ test.IgnoreReason = null;
+ }
+ }
+ }
+
+ public override bool Filter(IFilter filter)
+ {
+ return filter.Pass(this);
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.IO;
+ using System.Reflection;
+ using System.Collections;
+
+ /// <summary>
+ /// Summary description for TestSuiteBuilder.
+ /// </summary>
+ public class TestSuiteBuilder
+ {
+ #region Private Fields
+
+ /// <summary>
+ /// Hashtable of all test suites we have created to represent namespaces.
+ /// Used to locate namespace parent suites for fixtures.
+ /// </summary>
+ Hashtable namespaceSuites = new Hashtable();
+
+ /// <summary>
+ /// The root of the test suite being created by this builder. This
+ /// may be a simple TestSuite, an AssemblyTestSuite or a RootTestSuite
+ /// encompassing multiple assemblies.
+ /// </summary>
+ TestSuite rootSuite;
+
+ /// <summary>
+ /// The version of the nunit framework referenced by the loaded assembly.
+ /// </summary>
+ Version frameworkVersion = null;
+
+ #endregion
+
+ #region Properties
+
+ public Version FrameworkVersion
+ {
+ get { return frameworkVersion; }
+ }
+
+ #endregion
+
+ #region Public Methods
+
+ public Assembly Load(string assemblyName)
+ {
+ // Change currentDirectory in case assembly references unmanaged dlls
+ string currentDirectory = Environment.CurrentDirectory;
+ string assemblyDirectory = Path.GetDirectoryName( assemblyName );
+ bool swap = assemblyDirectory != null && assemblyDirectory != string.Empty;
+
+ try
+ {
+ if ( swap )
+ Environment.CurrentDirectory = assemblyDirectory;
+
+ Assembly assembly = AppDomain.CurrentDomain.Load(Path.GetFileNameWithoutExtension(assemblyName));
+
+ foreach( AssemblyName refAssembly in assembly.GetReferencedAssemblies() )
+ {
+ if ( refAssembly.Name == "nunit.framework" )
+ this.frameworkVersion = refAssembly.Version;
+ }
+
+ return assembly;
+ }
+ finally
+ {
+ if ( swap )
+ Environment.CurrentDirectory = currentDirectory;
+ }
+ }
+
+ public TestSuite Build(string projectName, IList assemblies)
+ {
+ RootTestSuite rootSuite = new RootTestSuite( projectName );
+
+ int assemblyKey = 0;
+ foreach(string assembly in assemblies)
+ {
+ TestSuite suite = Build( assembly, assemblyKey++ );
+ rootSuite.Add( suite );
+ }
+
+ return rootSuite;
+ }
+
+ public TestSuite Build( string assemblyName )
+ {
+ return Build( assemblyName, 0 );
+ }
+
+ public TestSuite Build(string assemblyName, string testName )
+ {
+ TestSuite suite = null;
+
+ Assembly assembly = Load(assemblyName);
+
+ if(assembly != null)
+ {
+ Type testType = assembly.GetType(testName);
+ if(testType != null)
+ return MakeSuite( testType );
+
+ // Assume that testName is a namespace
+ string prefix = testName + '.';
+
+ Type[] testTypes = assembly.GetExportedTypes();
+ int testFixtureCount = 0;
+
+ foreach(Type type in testTypes)
+ {
+ if(IsTestFixture(type) && type.Namespace != null)
+ //if(IsTestFixture(type) || IsTestSuiteProperty(type))
+ {
+ if( type.Namespace == testName || type.Namespace.StartsWith(prefix) )
+ {
+ suite = BuildFromNameSpace(testName, 0);
+
+ try
+ {
+ object fixture = BuildTestFixture( type );
+ suite.Add(fixture);
+ testFixtureCount++;
+ }
+ catch(InvalidTestFixtureException exception)
+ {
+ InvalidFixture fixture = new InvalidFixture(testType, exception.Message);
+ suite.Add(fixture);
+ }
+ }
+ }
+ }
+
+ return testFixtureCount == 0 ? null : rootSuite;
+ }
+
+ return suite;
+ }
+
+ public TestSuite Build( IList assemblies, string testName )
+ {
+ TestSuite suite = null;
+
+ foreach(string assemblyName in assemblies)
+ {
+ suite = Build( assemblyName, testName );
+ if ( suite != null ) break;
+ }
+
+ return suite;
+ }
+
+ public object BuildTestFixture( Type fixtureType )
+ {
+ ConstructorInfo ctor = fixtureType.GetConstructor(Type.EmptyTypes);
+ if(ctor == null) throw new InvalidTestFixtureException(fixtureType.FullName + " does not have a valid constructor");
+
+ object testFixture;
+
+ try
+ {
+ testFixture = ctor.Invoke(Type.EmptyTypes);
+ }
+ catch( Exception ex )
+ {
+ throw new InvalidTestFixtureException( ctor.Name + " threw a exception", ex );
+ }
+
+ if(testFixture == null) throw new InvalidTestFixtureException(ctor.Name + " cannot be invoked");
+
+ if(HasMultipleSetUpMethods(testFixture))
+ {
+ throw new InvalidTestFixtureException(ctor.Name + " has multiple SetUp methods");
+ }
+ if(HasMultipleTearDownMethods(testFixture))
+ {
+ throw new InvalidTestFixtureException(ctor.Name + " has multiple TearDown methods");
+ }
+ if(HasMultipleFixtureSetUpMethods(testFixture))
+ {
+ throw new InvalidTestFixtureException(ctor.Name + " has multiple TestFixtureSetUp methods");
+ }
+ if(HasMultipleFixtureTearDownMethods(testFixture))
+ {
+ throw new InvalidTestFixtureException(ctor.Name + " has multiple TestFixtureTearDown methods");
+ }
+
+ CheckSetUpTearDownSignature(GetMethodWithGivenAttribute(fixtureType,typeof(NUnit.Framework.SetUpAttribute)));
+ CheckSetUpTearDownSignature(GetMethodWithGivenAttribute(fixtureType,typeof(NUnit.Framework.TearDownAttribute)));
+ CheckSetUpTearDownSignature(GetMethodWithGivenAttribute(fixtureType,typeof(NUnit.Framework.TestFixtureSetUpAttribute)));
+ CheckSetUpTearDownSignature(GetMethodWithGivenAttribute(fixtureType,typeof(NUnit.Framework.TestFixtureTearDownAttribute)));
+
+ return testFixture;
+ }
+
+ public TestSuite MakeSuite( Type testType )
+ {
+ TestSuite suite = null;
+
+ if(testType != null)
+ {
+ if(IsTestFixture(testType))
+ {
+ suite = MakeSuiteFromTestFixtureType(testType);
+ }
+ else if(IsTestSuiteProperty(testType))
+ {
+ suite = MakeSuiteFromProperty(testType);
+ }
+ }
+
+ return suite;
+ }
+
+ public TestSuite MakeSuiteFromTestFixtureType(Type fixtureType)
+ {
+ TestSuite suite = new TestSuite(fixtureType.Name);
+
+ try
+ {
+ object testFixture = BuildTestFixture(fixtureType);
+ suite.Add(testFixture);
+ }
+ catch(InvalidTestFixtureException exception)
+ {
+ InvalidFixture fixture = new InvalidFixture(fixtureType,exception.Message);
+ suite.ShouldRun = false;
+ suite.IgnoreReason = exception.Message;
+ suite.Add(fixture);
+ }
+
+ return suite.Tests[0] as TestSuite;
+ }
+
+ #endregion
+
+ #region Nested TypeFilter Class
+
+ private class TypeFilter
+ {
+ private string rootNamespace;
+
+ TypeFilter( string rootNamespace )
+ {
+ this.rootNamespace = rootNamespace;
+ }
+
+ public bool Include( Type type )
+ {
+ if ( type.Namespace == rootNamespace )
+ return true;
+
+ return type.Namespace.StartsWith( rootNamespace + '.' );
+ }
+ }
+
+ #endregion
+
+ #region Helper Methods
+
+ private TestSuite BuildFromNameSpace( string nameSpace, int assemblyKey )
+ {
+ if( nameSpace == null || nameSpace == "" ) return rootSuite;
+ TestSuite suite = (TestSuite)namespaceSuites[nameSpace];
+ if(suite!=null) return suite;
+
+ int index = nameSpace.LastIndexOf(".");
+ string prefix = string.Format( "[{0}]", assemblyKey );
+ if( index == -1 )
+ {
+ suite = new TestSuite( nameSpace, assemblyKey );
+ if ( rootSuite == null )
+ rootSuite = suite;
+ else
+ rootSuite.Add(suite);
+ namespaceSuites[nameSpace]=suite;
+ }
+ else
+ {
+ string parentNameSpace = nameSpace.Substring( 0,index );
+ TestSuite parent = BuildFromNameSpace( parentNameSpace, assemblyKey );
+ string suiteName = nameSpace.Substring( index+1 );
+ suite = new TestSuite( parentNameSpace, suiteName, assemblyKey );
+ parent.Add( suite );
+ namespaceSuites[nameSpace] = suite;
+ }
+
+ return suite;
+ }
+
+ private TestSuite Build( string assemblyName, int assemblyKey )
+ {
+ TestSuiteBuilder builder = new TestSuiteBuilder();
+
+ Assembly assembly = Load( assemblyName );
+
+ builder.rootSuite = new AssemblyTestSuite( assemblyName, assemblyKey );
+ int testFixtureCount = 0;
+ Type[] testTypes = assembly.GetExportedTypes();
+ foreach(Type testType in testTypes)
+ {
+ ////////////////////////////////////////////////////////////////////////
+ // Use the second if statement to allow including Suites in the
+ // tree of tests. This causes a problem when the same test is added
+ // in multiple suites so we need to either fix it or prevent it.
+ //
+ // See also the block of code to uncomment in TestSuite.cs
+ ////////////////////////////////////////////////////////////////////////
+
+ if(IsTestFixture(testType))
+ //if(IsTestFixture(testType) || IsTestSuiteProperty(testType))
+ {
+ testFixtureCount++;
+ string namespaces = testType.Namespace;
+ TestSuite suite = builder.BuildFromNameSpace( namespaces, assemblyKey );
+
+ try
+ {
+ object fixture = BuildTestFixture( testType );
+ suite.Add(fixture);
+ }
+ catch(InvalidTestFixtureException exception)
+ {
+ InvalidFixture fixture = new InvalidFixture(testType, exception.Message);
+ suite.Add(fixture);
+ }
+ }
+ }
+
+ if(testFixtureCount == 0)
+ {
+ //throw new NoTestFixturesException(assemblyName + " has no TestFixtures");
+ builder.rootSuite.ShouldRun = false;
+ builder.rootSuite.IgnoreReason = "Has no TestFixtures";
+ }
+
+ return builder.rootSuite;
+ }
+
+ private int CountMethodWithGivenAttribute(object fixture, Type type)
+ {
+ int count = 0;
+ foreach(MethodInfo method in fixture.GetType().GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.DeclaredOnly))
+ {
+ if(method.IsDefined(type,false))
+ count++;
+ }
+ return count;
+ }
+
+ private MethodInfo GetMethodWithGivenAttribute(Type fixtureType, Type attrType)
+ {
+ foreach ( MethodInfo method in fixtureType.GetMethods(BindingFlags.Public|BindingFlags.Instance|BindingFlags.NonPublic|BindingFlags.Static ))
+ {
+ if( method.IsDefined( attrType, true ) )
+ return method;
+ }
+
+ return null;
+ }
+
+ private bool HasMultipleSetUpMethods(object fixture)
+ {
+ return CountMethodWithGivenAttribute(fixture,typeof(NUnit.Framework.SetUpAttribute)) > 1;
+ }
+
+ private bool HasMultipleTearDownMethods(object fixture)
+ {
+ return CountMethodWithGivenAttribute(fixture,typeof(NUnit.Framework.TearDownAttribute)) > 1;
+ }
+
+ private bool HasMultipleFixtureSetUpMethods(object fixture)
+ {
+ return CountMethodWithGivenAttribute(fixture,typeof(NUnit.Framework.TestFixtureSetUpAttribute)) > 1;
+ }
+
+ private bool HasMultipleFixtureTearDownMethods(object fixture)
+ {
+ return CountMethodWithGivenAttribute(fixture,typeof(NUnit.Framework.TestFixtureTearDownAttribute)) > 1;
+ }
+
+ private bool IsTestFixture(Type type)
+ {
+ if(type.IsAbstract) return false;
+
+ return type.IsDefined(typeof(NUnit.Framework.TestFixtureAttribute), true);
+ }
+
+ private bool IsTestSuiteProperty(Type testClass)
+ {
+ return (GetSuiteProperty(testClass) != null);
+ }
+
+ /// <summary>
+ /// Uses reflection to obtain the suite property for the Type
+ /// </summary>
+ /// <param name="testClass"></param>
+ /// <returns>The Suite property of the Type, or null if the property
+ /// does not exist</returns>
+ private TestSuite MakeSuiteFromProperty(Type testClass)
+ {
+ TestSuite suite = null;
+ PropertyInfo suiteProperty = null;
+ try
+ {
+ suiteProperty=GetSuiteProperty(testClass);
+ suite = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
+ }
+ catch(InvalidSuiteException)
+ {
+ return null;
+ }
+ return suite;
+ }
+
+ private PropertyInfo GetSuiteProperty(Type testClass)
+ {
+ if(testClass != null)
+ {
+ PropertyInfo[] properties = testClass.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly);
+ foreach(PropertyInfo property in properties)
+ {
+ object[] attrributes = property.GetCustomAttributes(typeof(NUnit.Framework.SuiteAttribute),false);
+ if(attrributes.Length>0)
+ {
+ try {
+ CheckSuiteProperty(property);
+ }catch(InvalidSuiteException){
+ return null;
+ }
+ return property;
+ }
+ }
+ }
+ return null;
+ }
+
+ private void CheckSuiteProperty(PropertyInfo property)
+ {
+ MethodInfo method = property.GetGetMethod(true);
+ if(method.ReturnType!=typeof(NUnit.Core.TestSuite))
+ throw new InvalidSuiteException("Invalid suite property method signature");
+ if(method.GetParameters().Length>0)
+ throw new InvalidSuiteException("Invalid suite property method signature");
+ }
+
+ private void CheckSetUpTearDownSignature(MethodInfo method)
+ {
+ if ( method != null )
+ {
+ if ( !method.IsPublic && !method.IsFamily || method.ReturnType != typeof(void) || method.GetParameters().Length > 0 )
+ throw new InvalidTestFixtureException("Invalid SetUp or TearDown method signature");
+ }
+ }
+ }
+
+ #endregion
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Core
+{
+ using System;
+ using System.Collections;
+
+ /// <summary>
+ /// TestSuiteResult
+ /// </summary>
+ ///
+ [Serializable]
+ public class TestSuiteResult : TestResult
+ {
+ private ArrayList results = new ArrayList();
+
+ public TestSuiteResult(ITest test, string name) : base(test, name)
+ {
+ Executed = false;
+ }
+
+ public void AddResult(TestResult result)
+ {
+ results.Add(result);
+ }
+
+ public override bool IsSuccess
+ {
+ get
+ {
+ bool result = true;
+ foreach(TestResult testResult in results)
+ result &= testResult.IsSuccess;
+ return result;
+ }
+ }
+
+ public override bool IsFailure
+ {
+ get
+ {
+ bool result = false;
+ foreach(TestResult testResult in results)
+ result |= testResult.IsFailure;
+ return result;
+ }
+ }
+
+ public override bool AllTestsExecuted
+ {
+ get
+ {
+ if (!this.Executed)
+ return false;
+
+ foreach( TestResult testResult in results )
+ {
+ if ( !testResult.AllTestsExecuted )
+ return false;
+ }
+ return true;
+ }
+ }
+
+ public override void NotRun(string message)
+ {
+ this.Executed = false;
+ this.messageString = message;
+ }
+
+ public IList Results
+ {
+ get { return results; }
+ }
+
+ public override void Accept(ResultVisitor visitor)
+ {
+ visitor.Visit(this);
+ }
+ }
+}
--- /dev/null
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright © 2000-2003 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no
+' event will the authors be held liable for any damages arising from the use of this
+' software.
+'
+' Permission is granted to anyone to use this software for any purpose, including
+' commercial applications, and to alter it and redistribute it freely, subject to the
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that
+' you wrote the original software. If you use this software in a product, an
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright © 2000-2003 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+using System;
+
+namespace NUnit.Core
+{
+ /// <summary>
+ /// Summary description for WarningSuite.
+ /// </summary>
+ public class WarningSuite : TestSuite
+ {
+ public WarningSuite(string name) : base(name)
+ {
+ ShouldRun=false;
+ }
+
+ public WarningSuite(string parentName, string name) : base(parentName,name)
+ {
+ ShouldRun=false;
+ }
+
+ protected internal override void Add(Test test)
+ {
+ base.Add(test);
+ test.ShouldRun = false;
+ test.IgnoreReason = "Containing Suite cannot be run";
+ }
+
+ protected internal override TestSuite CreateNewSuite(Type type)
+ {
+ return new WarningSuite(type.Namespace,type.Name);
+ }
+ }
+}
--- /dev/null
+<?xml version="1.0"?>
+<project name="NUnit.Core" default="build">
+
+ <!--
+ Required properties:
+ * bin.dir - bin directory
+ * src.dir - source location(build) or target(copy)
+ * build.debug - (true|false) debug build?
+ * build.defines.csc - build defines for build config
+ * runtime.defines.csc - build defines for target framework
+ -->
+
+ <target name="build" depends="copy">
+
+ <csc target="library" output="${bin.dir}/nunit.core.dll"
+ debug="${build.debug}" define="${build.defines.csc},${runtime.defines.csc},StronglyNamedAssembly">
+ <sources basedir="${src.dir}/core">
+ <includes name="*.cs"/>
+ </sources>
+ <references>
+ <includes name="${bin.dir}/nunit.framework.dll"/>
+ </references>
+ </csc>
+
+ </target>
+
+ <target name="copy">
+ <copy todir="${src.dir}/core">
+ <fileset basedir=".">
+ <includes name="nunit.core.dll.csproj"/>
+ <includes name="nunit.core.build"/>
+ <includes name="AssemblyInfo.cs"/>
+ <includes name="CategoryFilter.cs"/>
+ <includes name="CategoryManager.cs"/>
+ <includes name="EmptyFilter.cs"/>
+ <includes name="EventListener.cs"/>
+ <includes name="ExpectedExceptionTestCase.cs"/>
+ <includes name="Filter.cs"/>
+ <includes name="InvalidFixture.cs"/>
+ <includes name="InvalidSuiteException.cs"/>
+ <includes name="InvalidTestFixtureException.cs"/>
+ <includes name="ITest.cs"/>
+ <includes name="ITestEvents.cs"/>
+ <includes name="LongLivingMarshalByRefObject.cs"/>
+ <includes name="NameFilter.cs"/>
+ <includes name="NormalTestCase.cs"/>
+ <includes name="NoTestFixturesException.cs"/>
+ <includes name="NotRunnableTestCase.cs"/>
+ <includes name="NullListener.cs"/>
+ <includes name="NunitException.cs"/>
+ <includes name="RemoteTestRunner.cs"/>
+ <includes name="Results.xsd"/>
+ <includes name="ResultVisitor.cs"/>
+ <includes name="RootTestSuite.cs"/>
+ <includes name="StringTextWriter.cs"/>
+ <includes name="Summary.xslt"/>
+ <includes name="TemplateTestCase.cs"/>
+ <includes name="Test.cs"/>
+ <includes name="TestAssembly.cs"/>
+ <includes name="TestCase.cs"/>
+ <includes name="TestCaseBuilder.cs"/>
+ <includes name="TestCaseResult.cs"/>
+ <includes name="TestEventArgs.cs"/>
+ <includes name="TestEventDispatcher.cs"/>
+ <includes name="TestResult.cs"/>
+ <includes name="TestRunner.cs"/>
+ <includes name="TestRunnerThread.cs"/>
+ <includes name="TestSuite.cs"/>
+ <includes name="TestSuiteBuilder.cs"/>
+ <includes name="TestSuiteResult.cs"/>
+ <includes name="WarningSuite.cs"/>
+ </fileset>
+ </copy>
+ </target>
+
+</project>
--- /dev/null
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.10.3077"
+ SchemaVersion = "2.0"
+ ProjectGuid = "{EBD43A7F-AFCA-4281-BB53-5CDD91F966A3}"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "nunit.core"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Grid"
+ DefaultTargetSchema = "IE50"
+ DelaySign = "false"
+ OutputType = "Library"
+ PreBuildEvent = ""
+ PostBuildEvent = ""
+ RootNamespace = "NUnit.Core"
+ RunPostBuildEvent = "OnBuildSuccess"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE;StronglyNamedAssembly"
+ DocumentationFile = ""
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ NoStdLib = "false"
+ NoWarn = ""
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "285212672"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "TRACE;StronglyNamedAssembly"
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ NoStdLib = "false"
+ NoWarn = ""
+ Optimize = "true"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ HintPath = "E:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.dll"
+ />
+ <Reference
+ Name = "System.Data"
+ AssemblyName = "System.Data"
+ HintPath = "E:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
+ />
+ <Reference
+ Name = "System.XML"
+ AssemblyName = "System.Xml"
+ HintPath = "E:\WINNT\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
+ />
+ <Reference
+ Name = "nunit.framework.dll"
+ Project = "{83DD7E12-A705-4DBA-9D71-09C8973D9382}"
+ Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "AssemblyInfo.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "CategoryFilter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "CategoryManager.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "EmptyFilter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "EventListener.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ExpectedExceptionTestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Filter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "InvalidFixture.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "InvalidSuiteException.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "InvalidTestFixtureException.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITest.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITestEvents.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "LongLivingMarshalByRefObject.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NameFilter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NormalTestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NoTestFixturesException.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NotRunnableTestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NullListener.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NunitException.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "RemoteTestRunner.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Results.xsd"
+ BuildAction = "Content"
+ />
+ <File
+ RelPath = "Results.xsx"
+ DependentUpon = "Results.xsd"
+ BuildAction = "None"
+ />
+ <File
+ RelPath = "ResultVisitor.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "RootTestSuite.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "StringTextWriter.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Summary.xslt"
+ BuildAction = "Content"
+ />
+ <File
+ RelPath = "TemplateTestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Test.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestAssembly.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestCaseBuilder.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestCaseResult.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestEventArgs.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestEventDispatcher.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestResult.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestRunner.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestRunnerThread.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestSuite.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestSuiteBuilder.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestSuiteResult.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "WarningSuite.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
--- /dev/null
+./AssemblyInfo.cs
+./CategoryFilter.cs
+./CategoryManager.cs
+./EmptyFilter.cs
+./EventListener.cs
+./ExpectedExceptionTestCase.cs
+./Filter.cs
+./InvalidFixture.cs
+./InvalidSuiteException.cs
+./InvalidTestFixtureException.cs
+./ITest.cs
+./ITestEvents.cs
+./LongLivingMarshalByRefObject.cs
+./NameFilter.cs
+./NormalTestCase.cs
+./NoTestFixturesException.cs
+./NotRunnableTestCase.cs
+./NullListener.cs
+./NunitException.cs
+./RemoteTestRunner.cs
+./ResultVisitor.cs
+./RootTestSuite.cs
+./StringTextWriter.cs
+./TemplateTestCase.cs
+./TestAssembly.cs
+./TestCaseBuilder.cs
+./TestCase.cs
+./TestCaseResult.cs
+./Test.cs
+./TestEventArgs.cs
+./TestEventDispatcher.cs
+./TestResult.cs
+./TestRunner.cs
+./TestRunnerThread.cs
+./TestSuiteBuilder.cs
+./TestSuite.cs
+./TestSuiteResult.cs
+./WarningSuite.cs