1 // ****************************************************************
\r
2 // Copyright 2007, Charlie Poole
\r
3 // This is free software licensed under the NUnit license. You may
\r
4 // obtain a copy of the license at http://nunit.org/?p=license&r=2.4
\r
5 // ****************************************************************
\r
8 using System.Collections;
\r
9 using System.Collections.Specialized;
\r
11 namespace NUnit.Core
\r
14 /// TestPackage holds information about a set of tests to
\r
15 /// be loaded by a TestRunner. It may represent a single
\r
16 /// assembly or a set of assemblies. It supports selection
\r
17 /// of a single test fixture for loading.
\r
20 public class TestPackage
\r
22 private string name;
\r
23 private string fullName;
\r
25 private ListDictionary settings = new ListDictionary();
\r
27 private string basePath;
\r
28 private string configFile;
\r
29 private string binPath;
\r
30 private bool autoBinPath;
\r
32 private ArrayList assemblies;
\r
33 private string testName;
\r
34 private bool isSingleAssembly;
\r
38 /// Construct a package, specifying the name of the package.
\r
39 /// If the package name is an assembly file type (dll or exe)
\r
40 /// then the resulting package represents a single assembly.
\r
41 /// Otherwise it is a container for multiple assemblies.
\r
43 /// <param name="name">The name of the package</param>
\r
44 public TestPackage( string name )
\r
46 this.fullName = name;
\r
47 this.name = Path.GetFileName( name );
\r
48 this.assemblies = new ArrayList();
\r
49 if ( IsAssemblyFileType( name ) )
\r
51 this.isSingleAssembly = true;
\r
52 this.assemblies.Add( name );
\r
57 /// Construct a package, specifying the name to be used
\r
58 /// and a list of assemblies.
\r
60 /// <param name="name">The package name, used to name the top-level test node</param>
\r
61 /// <param name="assemblies">The list of assemblies comprising the package</param>
\r
62 public TestPackage( string name, IList assemblies )
\r
64 this.fullName = name;
\r
65 this.name = Path.GetFileName( name );
\r
66 this.assemblies = new ArrayList( assemblies );
\r
67 this.isSingleAssembly = false;
\r
71 /// Gets the name of the package
\r
75 get { return name; }
\r
79 /// Gets the full name of the package, which is usually
\r
80 /// the path to the NUnit project used to create the it
\r
82 public string FullName
\r
84 get { return fullName; }
\r
88 /// The BasePath to be used in loading the assemblies
\r
90 public string BasePath
\r
92 get { return basePath; }
\r
93 set { basePath = value; }
\r
97 /// The configuration file to be used
\r
99 public string ConfigurationFile
\r
101 get { return configFile; }
\r
102 set { configFile = value; }
\r
106 /// Addditional directories to be probed when loading assemblies
\r
108 public string PrivateBinPath
\r
110 get { return binPath; }
\r
111 set { binPath = value; }
\r
115 /// Indicates whether the probing path should be generated
\r
116 /// automatically based on the list of assemblies.
\r
118 public bool AutoBinPath
\r
120 get { return autoBinPath; }
\r
121 set { autoBinPath = value; }
\r
125 /// Assemblies to be loaded. At least one must be specified.
\r
127 public IList Assemblies
\r
129 get { return assemblies; }
\r
133 /// Return true if the package represents a single assembly.
\r
134 /// No root node is displayed in that case.
\r
136 public bool IsSingleAssembly
\r
138 get { return isSingleAssembly; }
\r
142 /// Fully qualified name of test to be loaded. If not
\r
143 /// specified, all the tests in the assemblies are loaded.
\r
145 public string TestName
\r
147 get { return testName; }
\r
148 set { testName = value; }
\r
152 /// Gets the dictionary of settings for this TestPackage
\r
154 public IDictionary Settings
\r
156 get { return settings; }
\r
160 /// Return the value of a bool setting or a default.
\r
162 /// <param name="name">The name of the setting</param>
\r
163 /// <param name="defaultSetting">The default value</param>
\r
164 /// <returns></returns>
\r
165 public bool GetSetting( string name, bool defaultSetting )
\r
167 object setting = settings[name];
\r
169 return setting == null ? defaultSetting : (bool)setting;
\r
172 private static bool IsAssemblyFileType( string path )
\r
174 string extension = Path.GetExtension( path ).ToLower();
\r
175 return extension == ".dll" || extension == ".exe";
\r