importing messaging-2008 branch to trunk, going on.
[mono.git] / mcs / nunit20 / util / UITestNode.cs
old mode 100755 (executable)
new mode 100644 (file)
index ff2229a..2448fc7
@@ -1,8 +1,8 @@
-#region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
+#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
 /************************************************************************************
 '
-' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
-' Copyright © 2000-2002 Philip A. Craig
+' Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' Copyright  2000-2002 Philip A. Craig
 '
 ' This software is provided 'as-is', without any express or implied warranty. In no 
 ' event will the authors be held liable for any damages arising from the use of this 
@@ -16,8 +16,8 @@
 ' you wrote the original software. If you use this software in a product, an 
 ' acknowledgment (see the following) in the product documentation is required.
 '
-' Portions Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov 
-' or Copyright © 2000-2002 Philip A. Craig
+' Portions Copyright  2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
+' or Copyright  2000-2002 Philip A. Craig
 '
 ' 2. Altered source versions must be plainly marked as such, and must not be 
 ' misrepresented as being the original software.
@@ -38,7 +38,7 @@ namespace NUnit.Util
        /// in the UI, avoiding the remoting issues associated
        /// with holding an actual Test object.
        /// </summary>
-       public class UITestNode : TestInfo
+       public class UITestNode : ITest
        {
                #region Instance Variables
 
@@ -52,6 +52,11 @@ namespace NUnit.Util
                /// </summary>
                private string testName;
 
+               /// <summary>
+               /// Used to distinguish tests in multiple assemblies;
+               /// </summary>
+               private int assemblyKey;
+
                /// <summary>
                /// True if the test should be run
                /// </summary>
@@ -83,7 +88,16 @@ namespace NUnit.Util
                /// object was constructed. Used for deferred 
                /// population of the object.
                /// </summary>
-               private TestInfo testSuite;
+               private ITest testSuite;
+
+               /// <summary>
+               /// The test description
+               /// </summary>
+               private string description;
+
+               private ArrayList categories = new ArrayList();
+
+               private bool isExplicit;
 
                #endregion
 
@@ -96,12 +110,23 @@ namespace NUnit.Util
                /// </summary>
                /// <param name="test">TestInfo interface from which a UITestNode is to be constructed</param>
                /// <param name="populate">True if child array is to be populated</param>
-               public UITestNode ( TestInfo test, bool populate )
+               public UITestNode ( ITest test, bool populate )
                {
                        fullName = test.FullName;
                        testName = test.Name;
+                       assemblyKey = test.AssemblyKey;
                        shouldRun = test.ShouldRun;
                        ignoreReason = test.IgnoreReason;
+                       description = test.Description;
+                       isExplicit = test.IsExplicit;
+
+                       if (test.Categories != null) 
+                       {
+                               categories.AddRange(test.Categories);
+                       }
+
+                       if ( test is UITestNode )
+                               testCaseCount = 0;
                        
                        if ( test.IsSuite )
                        {
@@ -124,7 +149,20 @@ namespace NUnit.Util
                /// Default construction uses lazy population approach
                /// </summary>
                /// <param name="test"></param>
-               public UITestNode ( TestInfo test ) : this( test, false ) { }
+               public UITestNode ( ITest test ) : this( test, false ) { }
+
+               public UITestNode ( string pathName, string testName )
+                       : this( pathName, testName, 0 ) { }
+
+               public UITestNode ( string pathName, string testName, int assemblyKey )
+               {
+                       this.fullName = pathName + "." + testName;
+                       this.testName = testName;
+                       this.assemblyKey = assemblyKey;
+                       this.shouldRun = true;
+                       this.isSuite = false;
+                       this.testCaseCount = 1;
+               }
 
                /// <summary>
                /// Populate the arraylist of child Tests recursively.
@@ -134,11 +172,11 @@ namespace NUnit.Util
                {
                        if ( !Populated )
                        {
-                               foreach( Test test in testSuite.Tests )
+                               foreach( ITest test in testSuite.Tests )
                                {
                                        UITestNode node = new UITestNode( test, true );
                                        tests.Add( node );
-                                       testCaseCount += node.CountTestCases;
+                                       testCaseCount += node.CountTestCases();
                                }
 
                                testSuite = null;
@@ -159,6 +197,15 @@ namespace NUnit.Util
 
                #region Properties
 
+               /// <summary>
+               /// The test description 
+               /// </summary>
+               public string Description
+               {
+                       get { return description; }
+                       set { description = value; }
+               }
+
                /// <summary>
                /// The reason for ignoring a test
                /// </summary>
@@ -193,6 +240,20 @@ namespace NUnit.Util
                        get { return testName; }
                }
 
+               /// <summary>
+               /// Identifier for assembly containing this test
+               /// </summary>
+               public int AssemblyKey
+               {
+                       get { return assemblyKey; }
+                       set { assemblyKey = value; }
+               }
+
+               public string UniqueName
+               {
+                       get{ return string.Format( "[{0}]{1}", assemblyKey, fullName ); }
+               }
+
                /// <summary>
                /// If the name is a path, this just returns the file part
                /// </summary>
@@ -208,19 +269,44 @@ namespace NUnit.Util
                        }
                }
 
+               public bool IsExplicit
+               {
+                       get { return isExplicit; }
+                       set { isExplicit = value; }
+               }
+
+               public IList Categories 
+               {
+                       get { return categories; }
+               }
+
+               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;
+               }
+
                /// <summary>
                /// Count of test cases in this test. If the suite
                /// has never been populated, it will be done now.
                /// </summary>
-               public int CountTestCases
+               public int CountTestCases()
                { 
-                       get 
-                       { 
-                               if ( !Populated )
-                                       PopulateTests();
+                       if ( !Populated )
+                               PopulateTests();
 
-                               return testCaseCount; 
-                       }
+                       return testCaseCount; 
                }
 
                /// <summary>