Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/nunit/src/NUnitCore/ReflectionUtils.cs')
-rw-r--r--mcs/nunit/src/NUnitCore/ReflectionUtils.cs154
1 files changed, 87 insertions, 67 deletions
diff --git a/mcs/nunit/src/NUnitCore/ReflectionUtils.cs b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
index 19f656f04c4..491e0e7ec91 100644
--- a/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
+++ b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
@@ -1,74 +1,94 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.IO;
- using System.Reflection;
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+ using System.IO;
+ using System.Reflection;
- using NUnit.Framework;
-/// <summary>
-///
-/// </summary>
- public class ReflectionUtils{
-/// <summary>
-///
-/// </summary>
-/// <param name="testClass"></param>
-/// <returns></returns>
- public static bool HasTests(Type testClass) {
+ using NUnit.Framework;
+ /// <summary>
+ ///
+ /// </summary>
+ [Obsolete("Use Standar Loader")]
+ public class ReflectionUtils
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="testClass"></param>
+ /// <returns></returns>
+ [Obsolete("Use Standar Loader")]
+ public static bool HasTests(Type testClass)
+ {
- PropertyInfo suiteProperty= null;
- suiteProperty = testClass.GetProperty("Suite", new Type[0]);
- if (suiteProperty == null ) {
- // try to extract a test suite automatically
- bool result = false;
- TestSuite dummy = new TestSuite(testClass, ref result);
- return result;
- }
- ITest test= null;
- try {
- // static property
- test= (ITest)suiteProperty.GetValue(null, new Type[0]);
- if (test == null)
- return false;
- } catch(Exception) {
- return false;
- }
- return true;
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="assemblyName"></param>
-/// <returns></returns>
- public static StringCollection GetAssemblyClasses(string assemblyName){
- StringCollection classNames = new StringCollection ();
- try {
- Assembly testAssembly = Assembly.LoadFrom(assemblyName);
+ PropertyInfo suiteProperty= null;
+ suiteProperty = testClass.GetProperty("Suite", new Type[0]);
+ if (suiteProperty == null )
+ {
+ // try to extract a test suite automatically
+ TestSuite dummy = new TestSuite(testClass, true);
+ return (dummy.CountTestCases > 0);
+ }
+ ITest test= null;
+ try
+ {
+ // static property
+ test= (ITest)suiteProperty.GetValue(null, new Type[0]);
+ if (test == null)
+ return false;
+ }
+ catch(Exception)
+ {
+ return false;
+ }
+ return true;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="assemblyName"></param>
+ /// <returns></returns>
+ [Obsolete("Use Standar Loader")]
+ public static StringCollection GetAssemblyClasses(string assemblyName)
+ {
+ StringCollection classNames = new StringCollection ();
+ try
+ {
+ Assembly testAssembly = Assembly.LoadFrom(assemblyName);
- foreach(Type testType in testAssembly.GetExportedTypes()){
- if(testType.IsClass && HasTests(testType)){
- classNames.Add(testType.FullName);
- }
- }
- }catch(ReflectionTypeLoadException rcle){
+ foreach(Type testType in testAssembly.GetExportedTypes())
+ {
+ if(testType.IsClass && HasTests(testType))
+ {
+ classNames.Add(testType.FullName);
+ }
+ }
+ }
+ catch(ReflectionTypeLoadException rcle)
+ {
- Type[] loadedTypes = rcle.Types;
- Exception[] exceptions = rcle.LoaderExceptions;
+ Type[] loadedTypes = rcle.Types;
+ Exception[] exceptions = rcle.LoaderExceptions;
- int exceptionCount = 0;
+ int exceptionCount = 0;
- for ( int i =0; i < loadedTypes.Length; i++ ){
- Console.Error.WriteLine("Unable to load a type because {0}", exceptions[exceptionCount] );
- exceptionCount++;
- }
- }catch(FileNotFoundException fnfe){
- Console.Error.WriteLine(fnfe.Message);
- }catch(Exception e){
- Console.Error.WriteLine("Error reading file {0}: {1}", assemblyName, e.Message);
- }
- return classNames;
- }
- }
-}
+ for ( int i =0; i < loadedTypes.Length; i++ )
+ {
+ Console.Error.WriteLine("Unable to load a type because {0}", exceptions[exceptionCount] );
+ exceptionCount++;
+ }
+ }
+ catch(FileNotFoundException fnfe)
+ {
+ Console.Error.WriteLine(fnfe.Message);
+ }
+ catch(Exception e)
+ {
+ Console.Error.WriteLine("Error reading file {0}: {1}", assemblyName, e.Message);
+ }
+ return classNames;
+ }
+ }
+} \ No newline at end of file