2009-06-12 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mcs / nunit20 / core / LegacySuite.cs
1 using System;
2 using System.Reflection;
3
4 namespace NUnit.Core
5 {
6         /// <summary>
7         /// Represents a test suite constructed from a type that has a static Suite property
8         /// </summary>
9         public class LegacySuite : TestSuite
10         {
11                 private PropertyInfo suiteProperty;
12
13                 #region Constructors
14
15                 public LegacySuite( Type fixtureType ) : base( fixtureType, 0 )
16                 {
17                         Initialize();
18                 }
19
20                 public LegacySuite( Type fixtureType, int assemblyKey ) : base( fixtureType, assemblyKey ) 
21                 {
22                         Initialize();
23                 }
24
25                 public LegacySuite( object fixture ) : base( fixture, 0 ) 
26                 {
27                         Initialize();
28                 }
29
30                 public LegacySuite( object fixture, int assemblyKey ) : base( fixture, assemblyKey ) 
31                 {
32                         Initialize();
33                 }
34
35                 private void Initialize()
36                 {
37                         suiteProperty = Reflect.GetSuiteProperty( this.fixtureType );
38
39                         MethodInfo method = suiteProperty.GetGetMethod(true);
40                         if(method.ReturnType!=typeof(NUnit.Core.TestSuite) || method.GetParameters().Length>0)
41                         {
42                                 this.ShouldRun = false;
43                                 this.IgnoreReason = "Invalid suite property method signature";
44                         }
45                         else
46                         {
47                                 TestSuite suite = (TestSuite)suiteProperty.GetValue(null, new Object[0]);               
48                                 foreach( Test test in suite.Tests )
49                                         this.Add( test );
50                         }
51                 }
52
53                 #endregion
54
55                 #region Static methods
56
57                 public static bool IsValidType( Type type )
58                 {
59                         return Reflect.GetSuiteProperty( type ) != null;
60                 }
61
62                 #endregion
63         }
64 }