1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright © 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright © 2000-2003 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright © 2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright © 2000-2003 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
33 using System
.Collections
;
38 public abstract class Test
: LongLivingMarshalByRefObject
, ITest
, IComparable
40 #region Private Fields
45 private string testName
;
48 /// Full Name of the test
50 private string fullName
;
53 /// Int used to distinguish suites of the same
54 /// name across multiple assemblies.
56 private int assemblyKey
;
59 /// The Type of the fixture associated with this test, or null
61 protected Type fixtureType
;
64 /// The fixture object, to be used with this test, or null
66 private object fixture
;
69 /// Whether or not the test should be run
71 private bool shouldRun
;
74 /// Reason for not running the test, if applicable
76 private string ignoreReason
;
79 /// Description for this test
81 private string description
;
84 /// Test suite containing this test, or null
86 private TestSuite parent
;
89 /// List of categories applying to this test
91 private IList categories
;
94 /// True if the test had the Explicit attribute
96 private bool isExplicit
;
102 public Test( string name
) : this( name
, 0 ) { }
104 public Test( string name
, int assemblyKey
)
106 fullName
= testName
= name
;
107 this.assemblyKey
= assemblyKey
;
110 protected Test( string pathName
, string testName
)
111 : this( pathName
, testName
, 0 ) { }
113 protected Test( string pathName
, string testName
, int assemblyKey
)
115 fullName
= pathName
== null || pathName
== string.Empty
? testName
: pathName
+ "." + testName
;
116 this.testName
= testName
;
117 this.assemblyKey
= assemblyKey
;
121 protected Test( Type fixtureType
) : this( fixtureType
, 0 ) { }
123 protected Test( Type fixtureType
, int assemblyKey
)
125 this.fixtureType
= fixtureType
;
126 this.fullName
= this.testName
= fixtureType
.FullName
;
127 this.assemblyKey
= assemblyKey
;
128 this.shouldRun
= true;
130 if ( fixtureType
.Namespace
!= null )
131 testName
= testName
.Substring( Name
.LastIndexOf( '.' ) + 1 );
134 // TODO: Currently, these two are only used by our tests. Remove?
135 protected Test( object fixture
) : this( fixture
, 0 ) { }
137 protected Test( object fixture
, int assemblyKey
) : this( fixture
.GetType(), assemblyKey
)
139 this.fixture
= fixture
;
148 get { return testName; }
151 public string FullName
153 get { return fullName; }
157 /// If the name is a path, this just returns the file part
159 public string ShortName
164 int val
= name
.LastIndexOf("\\");
166 name
= name
.Substring(val
+1);
172 /// Int used to distinguish suites of the same
173 /// name across multiple assemblies.
175 public int AssemblyKey
177 get { return assemblyKey; }
178 set { assemblyKey = value; }
182 /// Key used to look up a test in a hash table
184 public string UniqueName
186 get { return string.Format( "[{0}
]{1}
", assemblyKey, fullName ); }
189 public object Fixture
191 get { return fixture; }
192 set { fixture = value; }
196 /// Whether or not the test should be run
198 public virtual bool ShouldRun
200 get { return shouldRun; }
201 set { shouldRun = value; }
205 /// Reason for not running the test, if applicable
207 public string IgnoreReason
209 get { return ignoreReason; }
210 set { ignoreReason = value; }
213 public TestSuite Parent
215 get { return parent; }
216 set { parent = value; }
219 public string TestPath
223 string testPath = "";
225 testPath = parent.TestPath;
226 return testPath + FullName;
230 public IList Categories
232 get { return categories; }
233 set { categories = value; }
236 public bool HasCategory( string name )
238 return categories != null && categories.Contains( name );
241 public bool HasCategory( IList names )
243 if ( categories == null )
246 foreach( string name in names )
247 if ( categories.Contains( name ) )
253 public bool IsDescendant(Test test)
257 return parent == test || parent.IsDescendant(test);
263 public String Description
265 get { return description; }
266 set { description = value; }
269 public bool IsExplicit
271 get { return isExplicit; }
272 set { isExplicit = value; }
277 #region Abstract Methods and Properties
280 /// Count of the test cases ( 1 if this is a test case )
282 public abstract int CountTestCases();
283 public abstract int CountTestCases(IFilter filter);
285 public abstract bool IsSuite { get; }
286 public abstract bool IsFixture{ get; }
287 public abstract bool IsTestCase{ get; }
288 public abstract ArrayList Tests { get; }
290 public abstract bool Filter(IFilter filter);
292 public abstract TestResult Run( EventListener listener );
293 public abstract TestResult Run(EventListener listener, IFilter filter);
297 #region IComparable Members
299 public int CompareTo(object obj)
301 Test other = obj as Test;
306 return this.FullName.CompareTo( other.FullName );