1 #region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
2 /************************************************************************************
4 ' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
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 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
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 : TestInfo
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 /// True if the test should be run
58 private bool shouldRun;
61 /// Reason for not running the test
63 private string ignoreReason;
66 /// Number of test cases in this test or suite
68 private int testCaseCount;
71 /// For a test suite, the child tests or suites
72 /// Null if this is not a test suite
74 private ArrayList tests;
77 /// True if this is a suite
82 /// Interface of the test suite from which this
83 /// object was constructed. Used for deferred
84 /// population of the object.
86 private TestInfo testSuite;
90 #region Construction and Conversion
93 /// Construct from a TestInfo interface, which might be
94 /// a Test or another UITestNode. Optionally, populate
95 /// the array of child tests.
97 /// <param name="test">TestInfo interface from which a UITestNode is to be constructed</param>
98 /// <param name="populate">True if child array is to be populated</param>
99 public UITestNode ( TestInfo test, bool populate )
101 fullName = test.FullName;
102 testName = test.Name;
103 shouldRun = test.ShouldRun;
104 ignoreReason = test.IgnoreReason;
112 tests = new ArrayList();
114 if ( populate ) PopulateTests();
124 /// Default construction uses lazy population approach
126 /// <param name="test"></param>
127 public UITestNode ( TestInfo test ) : this( test, false ) { }
130 /// Populate the arraylist of child Tests recursively.
131 /// If already populated, it has no effect.
133 public void PopulateTests()
137 foreach( Test test in testSuite.Tests )
139 UITestNode node = new UITestNode( test, true );
141 testCaseCount += node.CountTestCases;
149 /// Allow implicit conversion of a Test to a TestInfo
151 /// <param name="test"></param>
152 /// <returns></returns>
153 public static implicit operator UITestNode( Test test )
155 return new UITestNode( test );
163 /// The reason for ignoring a test
165 public string IgnoreReason
167 get { return ignoreReason; }
168 set { ignoreReason = value; }
172 /// True if the test should be run
174 public bool ShouldRun
176 get { return shouldRun; }
177 set { shouldRun = value; }
181 /// Full name of the test
183 public string FullName
185 get { return fullName; }
193 get { return testName; }
197 /// If the name is a path, this just returns the file part
199 public string ShortName
204 int val = name.LastIndexOf("\\");
206 name = name.Substring(val+1);
212 /// Count of test cases in this test. If the suite
213 /// has never been populated, it will be done now.
215 public int CountTestCases
222 return testCaseCount;
227 /// Array of child tests, null if this is a test case.
228 /// The array is populated on access if necessary.
230 public ArrayList Tests
242 /// True if this is a suite, false if a test case
246 get { return isSuite; }
250 /// True if this is a test case, false if a suite
252 public bool IsTestCase
254 get { return !isSuite; }
258 /// True if this is a fixture. May populate the test's
259 /// children as a side effect.
260 /// TODO: An easier way to tell this?
262 public bool IsFixture
266 // A test case is obviously not a fixture
267 if ( IsTestCase ) return false;
269 // We have no way of constructing an empty suite unless it's a fixture
270 if ( Tests.Count == 0 ) return true;
272 // Any suite with children is a fixture if the children are test cases
273 UITestNode firstChild = (UITestNode)Tests[0];
274 return !firstChild.IsSuite;
279 /// False for suites that have not yet been populated
280 /// with their children, otherwise true - used for testing.
282 public bool Populated
284 get { return testSuite == null; }
287 public TestResult Run( EventListener listener )
289 throw new InvalidOperationException( "Cannot use Run on a local copy of Test data" );