2010-05-21 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / nunit24 / NUnitCore / interfaces / TestNode.cs
1 // ****************************************************************\r
2 // Copyright 2007, Charlie Poole\r
3 // This is free software licensed under the NUnit license. You may\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4\r
5 // ****************************************************************\r
6 using System;\r
7 using System.Collections;\r
8 \r
9 namespace NUnit.Core\r
10 {\r
11         /// <summary>\r
12         /// TestNode represents a single test or suite in the test hierarchy.\r
13         /// TestNode holds common info needed about a test and represents a\r
14         /// single node - either a test or a suite - in the hierarchy of tests.\r
15         /// \r
16         /// TestNode extends TestInfo, which holds all the information with\r
17         /// the exception of the list of child classes. When constructed from\r
18         /// a Test, TestNodes are always fully populated with child TestNodes.\r
19         /// \r
20         /// Like TestInfo, TestNode is purely a data class, and is not able\r
21         /// to execute tests.\r
22         /// \r
23         /// </summary>\r
24         [Serializable]\r
25         public class TestNode : TestInfo\r
26         {\r
27                 #region Instance Variables\r
28                 private ITest parent;\r
29 \r
30                 /// <summary>\r
31                 /// For a test suite, the child tests or suites\r
32                 /// Null if this is not a test suite\r
33                 /// </summary>\r
34                 private ArrayList tests;\r
35                 #endregion\r
36 \r
37                 #region Constructors\r
38                 /// <summary>\r
39                 /// Construct from an ITest\r
40                 /// </summary>\r
41                 /// <param name="test">Test from which a TestNode is to be constructed</param>\r
42                 public TestNode ( ITest test ) : base( test )\r
43                 {\r
44                         if ( test.IsSuite )\r
45                         {\r
46                                 this.tests = new ArrayList();\r
47                                 \r
48                                 foreach( ITest child in test.Tests )\r
49                                 {\r
50                                         TestNode node = new TestNode( child );\r
51                                         this.Tests.Add( node );\r
52                                         node.parent = this;\r
53                                 }\r
54                         }\r
55                 }\r
56 \r
57         /// <summary>\r
58         /// Construct a TestNode given a TestName and an\r
59         /// array of child tests.\r
60         /// </summary>\r
61         /// <param name="testName">The TestName of the new test</param>\r
62         /// <param name="tests">An array of tests to be added as children of the new test</param>\r
63             public TestNode ( TestName testName, ITest[] tests ) : base( testName, tests )\r
64                 {\r
65                         this.tests = new ArrayList();\r
66                         this.tests.AddRange( tests );\r
67                 }\r
68                 #endregion\r
69 \r
70                 #region Properties\r
71         /// <summary>\r
72         /// Gets the parent test of the current test\r
73         /// </summary>\r
74                 public override ITest Parent\r
75                 {\r
76                         get { return parent; }\r
77                 }\r
78 \r
79                 /// <summary>\r
80                 /// Array of child tests, null if this is a test case.\r
81                 /// </summary>\r
82                 public override IList Tests \r
83                 {\r
84                         get { return tests; }\r
85                 }\r
86                 #endregion\r
87         }\r
88 }\r