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

ReflectionUtils.cs « NUnitCore « src « nunit « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 491e0e7ec91695b41677df00e4b4f9c48cf8c0f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
namespace NUnit.Runner 
{

	using System;
	using System.Collections;
	using System.Collections.Specialized;
	using System.IO;
	using System.Reflection;

	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
				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)
			{

				Type[] loadedTypes     = rcle.Types;
				Exception[] exceptions = rcle.LoaderExceptions;

				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;
		}
	}
}