1
// ***********************************************************************
2
// Copyright (c) 2007 Charlie Poole
4
// Permission is hereby granted, free of charge, to any person obtaining
5
// a copy of this software and associated documentation files (the
6
// "Software"), to deal in the Software without restriction, including
7
// without limitation the rights to use, copy, modify, merge, publish,
8
// distribute, sublicense, and/or sell copies of the Software, and to
9
// permit persons to whom the Software is furnished to do so, subject to
10
// the following conditions:
12
// The above copyright notice and this permission notice shall be
13
// included in all copies or substantial portions of the Software.
15
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
// ***********************************************************************
26
using System.Collections;
27
using System.Collections.Specialized;
32
/// Represents the manner in which test assemblies are
33
/// distributed across processes.
35
public enum ProcessModel
38
/// Use the default setting, depending on the runner
39
/// and the nature of the tests to be loaded.
43
/// Run tests directly in the NUnit process
47
/// Run tests in a single separate process
51
/// Run tests in a separate process per assembly
57
/// Represents the manner in which test assemblies use
58
/// AppDomains to provide isolation
60
public enum DomainUsage
63
/// Use the default setting, depending on the runner
64
/// and the nature of the tests to be loaded.
68
/// Don't create a test domain - run in the primary AppDomain
72
/// Run tests in a single separate test domain
76
/// Run tests in a separate domain per assembly
82
/// TestPackage holds information about a set of tests to
83
/// be loaded by a TestRunner. It may represent a single
84
/// assembly or a set of assemblies. It supports selection
85
/// of a single test fixture for loading.
88
public class TestPackage
91
private string fullName;
93
private ListDictionary settings = new ListDictionary();
95
private string basePath;
96
private string configFile;
97
private string binPath;
98
private bool autoBinPath;
100
private ArrayList assemblies;
101
private string testName;
102
private bool isSingleAssembly;
106
/// Construct a package, specifying the name of the package.
107
/// If the package name is an assembly file type (dll or exe)
108
/// then the resulting package represents a single assembly.
109
/// Otherwise it is a container for multiple assemblies.
111
/// <param name="name">The name of the package</param>
112
public TestPackage( string name )
114
this.fullName = name;
115
this.name = Path.GetFileName( name );
116
this.assemblies = new ArrayList();
117
if ( IsAssemblyFileType( name ) )
119
this.isSingleAssembly = true;
120
this.assemblies.Add( name );
125
/// Construct a package, specifying the name to be used
126
/// and a list of assemblies.
128
/// <param name="name">The package name, used to name the top-level test node</param>
129
/// <param name="assemblies">The list of assemblies comprising the package</param>
130
public TestPackage( string name, IList assemblies )
132
this.fullName = name;
133
this.name = Path.GetFileName( name );
134
this.assemblies = new ArrayList( assemblies );
135
this.isSingleAssembly = false;
139
/// Gets the name of the package
147
/// Gets the full name of the package, which is usually
148
/// the path to the NUnit project used to create the it
150
public string FullName
152
get { return fullName; }
156
/// The BasePath to be used in loading the assemblies
158
public string BasePath
160
get { return basePath; }
161
set { basePath = value; }
165
/// The configuration file to be used
167
public string ConfigurationFile
169
get { return configFile; }
170
set { configFile = value; }
174
/// Addditional directories to be probed when loading assemblies
176
public string PrivateBinPath
178
get { return binPath; }
179
set { binPath = value; }
183
/// Indicates whether the probing path should be generated
184
/// automatically based on the list of assemblies.
186
public bool AutoBinPath
188
get { return autoBinPath; }
189
set { autoBinPath = value; }
193
/// Assemblies to be loaded. At least one must be specified.
195
public IList Assemblies
197
get { return assemblies; }
201
/// Return true if the package represents a single assembly.
202
/// No root node is displayed in that case.
204
public bool IsSingleAssembly
206
get { return isSingleAssembly; }
210
/// Fully qualified name of test to be loaded. If not
211
/// specified, all the tests in the assemblies are loaded.
213
public string TestName
215
get { return testName; }
216
set { testName = value; }
220
/// Gets the dictionary of settings for this TestPackage
222
public IDictionary Settings
224
get { return settings; }
228
/// Return the value of a setting or a default.
230
/// <param name="name">The name of the setting</param>
231
/// <param name="defaultSetting">The default value</param>
232
/// <returns></returns>
233
public object GetSetting(string name, object defaultSetting)
235
object setting = settings[name];
237
return setting == null ? defaultSetting : setting;
241
/// Return the value of a string setting or a default.
243
/// <param name="name">The name of the setting</param>
244
/// <param name="defaultSetting">The default value</param>
245
/// <returns></returns>
246
public string GetSetting(string name, string defaultSetting)
248
object setting = settings[name];
250
return setting == null ? defaultSetting : (string)setting;
254
/// Return the value of a bool setting or a default.
256
/// <param name="name">The name of the setting</param>
257
/// <param name="defaultSetting">The default value</param>
258
/// <returns></returns>
259
public bool GetSetting(string name, bool defaultSetting)
261
object setting = settings[name];
263
return setting == null ? defaultSetting : (bool)setting;
267
/// Return the value of an int setting or a default.
269
/// <param name="name">The name of the setting</param>
270
/// <param name="defaultSetting">The default value</param>
271
/// <returns></returns>
272
public int GetSetting(string name, int defaultSetting)
274
object setting = settings[name];
276
return setting == null ? defaultSetting : (int)setting;
280
/// Return the value of a enum setting or a default.
282
/// <param name="name">The name of the setting</param>
283
/// <param name="defaultSetting">The default value</param>
284
/// <returns></returns>
285
public System.Enum GetSetting(string name, System.Enum defaultSetting)
287
object setting = settings[name];
289
return setting == null ? defaultSetting : (System.Enum)setting;
292
private static bool IsAssemblyFileType(string path)
294
string extension = Path.GetExtension( path ).ToLower();
295
return extension == ".dll" || extension == ".exe";