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-2002 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 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 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;
37 /// UITestNode holds common info needed about a test
38 /// in the UI, avoiding the remoting issues associated
39 /// with holding an actual Test object.
41 public class UITestNode : ITest
43 #region Instance Variables
46 /// The full name of the test, including the assembly and namespaces
48 private string fullName;
53 private string testName;
56 /// Used to distinguish tests in multiple assemblies;
58 private int assemblyKey;
61 /// True if the test should be run
63 private bool shouldRun;
66 /// Reason for not running the test
68 private string ignoreReason;
71 /// Number of test cases in this test or suite
73 private int testCaseCount;
76 /// For a test suite, the child tests or suites
77 /// Null if this is not a test suite
79 private ArrayList tests;
82 /// True if this is a suite
87 /// Interface of the test suite from which this
88 /// object was constructed. Used for deferred
89 /// population of the object.
91 private ITest testSuite;
94 /// The test description
96 private string description;
100 #region Construction and Conversion
102 public UITestNode( string suiteName ) : this( suiteName, 0 ) { }
104 public UITestNode( string suiteName, int assemblyKey )
106 this.fullName = this.testName = suiteName;
107 this.assemblyKey = assemblyKey;
108 this.shouldRun = true;
110 this.testCaseCount = 0;
111 this.tests = new ArrayList();
114 public UITestNode( string pathName, string testName )
115 : this( pathName, testName, 0 ) { }
117 public UITestNode( string pathName, string testName, int assemblyKey )
119 this.fullName = pathName + "." + testName;
120 this.testName = testName;
121 this.assemblyKey = assemblyKey;
122 this.shouldRun = true;
123 this.isSuite = false;
124 this.testCaseCount = 1;
128 /// Construct from a TestInfo interface, which might be
129 /// a Test or another UITestNode. Optionally, populate
130 /// the array of child tests.
132 /// <param name="test">TestInfo interface from which a UITestNode is to be constructed</param>
133 /// <param name="populate">True if child array is to be populated</param>
134 public UITestNode ( ITest test, bool populate )
136 fullName = test.FullName;
137 testName = test.Name;
138 assemblyKey = test.AssemblyKey;
139 shouldRun = test.ShouldRun;
140 ignoreReason = test.IgnoreReason;
141 description = test.Description;
149 tests = new ArrayList();
151 if ( populate ) PopulateTests();
161 /// Default construction uses lazy population approach
163 /// <param name="test"></param>
164 public UITestNode ( ITest test ) : this( test, false ) { }
167 /// Populate the arraylist of child Tests recursively.
168 /// If already populated, it has no effect.
170 public void PopulateTests()
174 foreach( Test test in testSuite.Tests )
176 UITestNode node = new UITestNode( test, true );
178 testCaseCount += node.CountTestCases;
186 /// Allow implicit conversion of a Test to a TestInfo
188 /// <param name="test"></param>
189 /// <returns></returns>
190 public static implicit operator UITestNode( Test test )
192 return new UITestNode( test );
200 /// The test description
202 public string Description
204 get { return description; }
205 set { description = value; }
209 /// The reason for ignoring a test
211 public string IgnoreReason
213 get { return ignoreReason; }
214 set { ignoreReason = value; }
218 /// True if the test should be run
220 public bool ShouldRun
222 get { return shouldRun; }
223 set { shouldRun = value; }
227 /// Full name of the test
229 public string FullName
231 get { return fullName; }
239 get { return testName; }
243 /// Identifier for assembly containing this test
245 public int AssemblyKey
247 get { return assemblyKey; }
248 set { assemblyKey = value; }
251 public string UniqueName
253 get{ return string.Format( "[{0}]{1}", assemblyKey, fullName ); }
257 /// If the name is a path, this just returns the file part
259 public string ShortName
264 int val = name.LastIndexOf("\\");
266 name = name.Substring(val+1);
272 /// Count of test cases in this test. If the suite
273 /// has never been populated, it will be done now.
275 public int CountTestCases
282 return testCaseCount;
287 /// Array of child tests, null if this is a test case.
288 /// The array is populated on access if necessary.
290 public ArrayList Tests
302 /// True if this is a suite, false if a test case
306 get { return isSuite; }
310 /// True if this is a test case, false if a suite
312 public bool IsTestCase
314 get { return !isSuite; }
318 /// True if this is a fixture. May populate the test's
319 /// children as a side effect.
320 /// TODO: An easier way to tell this?
322 public bool IsFixture
326 // A test case is obviously not a fixture
327 if ( IsTestCase ) return false;
329 // We have no way of constructing an empty suite unless it's a fixture
330 if ( Tests.Count == 0 ) return true;
332 // Any suite with children is a fixture if the children are test cases
333 UITestNode firstChild = (UITestNode)Tests[0];
334 return !firstChild.IsSuite;
339 /// False for suites that have not yet been populated
340 /// with their children, otherwise true - used for testing.
342 public bool Populated
344 get { return testSuite == null; }
347 public TestResult Run( EventListener listener )
349 throw new InvalidOperationException( "Cannot use Run on a local copy of Test data" );