**** Merged from MCS ****
[mono-project.git] / mcs / nunit20 / core / LegacySuite.cs
blob3d3ff18f972efc5c8b77ea19bf792e1bdd8c3a16
1 using System;
2 using System.Reflection;
4 namespace NUnit.Core
6 /// <summary>
7 /// Represents a test suite constructed from a type that has a static Suite property
8 /// </summary>
9 public class LegacySuite : TestSuite
11 private PropertyInfo suiteProperty;
13 #region Constructors
15 public LegacySuite( Type fixtureType ) : base( fixtureType, 0 )
17 Initialize();
20 public LegacySuite( Type fixtureType, int assemblyKey ) : base( fixtureType, assemblyKey )
22 Initialize();
25 public LegacySuite( object fixture ) : base( fixture, 0 )
27 Initialize();
30 public LegacySuite( object fixture, int assemblyKey ) : base( fixture, assemblyKey )
32 Initialize();
35 private void Initialize()
37 suiteProperty = Reflect.GetSuiteProperty( this.fixtureType );
39 MethodInfo method = suiteProperty.GetGetMethod(true);
40 if(method.ReturnType!=typeof(NUnit.Core.TestSuite) || method.GetParameters().Length>0)
42 this.ShouldRun = false;
43 this.IgnoreReason = "Invalid suite property method signature";
45 else
47 TestSuite suite = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
48 foreach( Test test in suite.Tests )
49 this.Add( test );
53 #endregion
55 #region Static methods
57 public static bool IsValidType( Type type )
59 return Reflect.GetSuiteProperty( type ) != null;
62 #endregion