PageRenderTime 10ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/core/Extensibility/FrameworkRegistry.cs

#
C# | 73 lines | 46 code | 8 blank | 19 comment | 2 complexity | fb32aa9ca94b65d6723a33ccd57b9cdd MD5 | raw file
 1// ****************************************************************
 2// Copyright 2007, Charlie Poole
 3// This is free software licensed under the NUnit license. You may
 4// obtain a copy of the license at http://nunit.org.
 5// ****************************************************************
 6using System;
 7using System.Reflection;
 8using System.Collections;
 9
10namespace NUnit.Core.Extensibility
11{
12    public class FrameworkRegistry : ExtensionPoint, IFrameworkRegistry
13    {
14		#region Constructor
15		public FrameworkRegistry( IExtensionHost host )
16			: base( "FrameworkRegistry", host ) { }
17		#endregion Constructor
18
19        #region Instance Fields
20        /// <summary>
21        /// List of FrameworkInfo structs for supported frameworks
22        /// </summary>
23        private Hashtable testFrameworks = new Hashtable();
24        #endregion
25
26        #region IFrameworkRegistry Members
27        /// <summary>
28        /// Register a framework. NUnit registers itself using this method. Add-ins that
29        /// work with or emulate a different framework may register themselves as well.
30        /// </summary>
31        /// <param name="frameworkName">The name of the framework</param>
32        /// <param name="assemblyName">The name of the assembly that framework users reference</param>
33        public void Register(string frameworkName, string assemblyName)
34        {
35            testFrameworks[frameworkName] = new TestFramework(frameworkName, assemblyName);
36        }
37		#endregion
38
39		#region ExtensionPoint overrides
40        protected override bool IsValidExtension(object extension)
41		{
42			return extension is TestFramework;
43		}
44
45		#endregion
46
47		#region Other Methods
48        /// <summary>
49        /// Get a list of known frameworks referenced by an assembly
50        /// </summary>
51        /// <param name="assembly">The assembly to be examined</param>
52        /// <returns>A list of AssemblyNames</returns>
53        public IList GetReferencedFrameworks(Assembly assembly)
54        {
55            ArrayList referencedAssemblies = new ArrayList();
56
57            foreach (AssemblyName assemblyRef in assembly.GetReferencedAssemblies())
58            {
59                foreach (TestFramework info in testFrameworks.Values)
60                {
61                    if (assemblyRef.Name == info.AssemblyName)
62                    {
63                        referencedAssemblies.Add(assemblyRef);
64                        break;
65                    }
66                }
67            }
68
69            return referencedAssemblies;
70        }
71        #endregion
72    }
73}