/src/NUnit/interfaces/TestPackage.cs
C# | 289 lines | 136 code | 31 blank | 122 comment | 11 complexity | b3d0af1a31baf1439e9cc3a6a8994c4a 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.IO; 8using System.Collections; 9using System.Collections.Specialized; 10 11namespace NUnit.Core 12{ 13 /// <summary> 14 /// Represents the manner in which test assemblies are 15 /// distributed across processes. 16 /// </summary> 17 public enum ProcessModel 18 { 19 /// <summary> 20 /// Use the default setting, depending on the runner 21 /// and the nature of the tests to be loaded. 22 /// </summary> 23 Default, 24 /// <summary> 25 /// Run tests directly in the NUnit process 26 /// </summary> 27 Single, 28 /// <summary> 29 /// Run tests in a single separate process 30 /// </summary> 31 Separate, 32 /// <summary> 33 /// Run tests in a separate process per assembly 34 /// </summary> 35 Multiple 36 } 37 38 /// <summary> 39 /// Represents the manner in which test assemblies use 40 /// AppDomains to provide isolation 41 /// </summary> 42 public enum DomainUsage 43 { 44 /// <summary> 45 /// Use the default setting, depending on the runner 46 /// and the nature of the tests to be loaded. 47 /// </summary> 48 Default, 49 /// <summary> 50 /// Don't create a test domain - run in the primary AppDomain 51 /// </summary> 52 None, 53 /// <summary> 54 /// Run tests in a single separate test domain 55 /// </summary> 56 Single, 57 /// <summary> 58 /// Run tests in a separate domain per assembly 59 /// </summary> 60 Multiple 61 } 62 63 /// <summary> 64 /// TestPackage holds information about a set of tests to 65 /// be loaded by a TestRunner. It may represent a single 66 /// assembly or a set of assemblies. It supports selection 67 /// of a single test fixture for loading. 68 /// </summary> 69 [Serializable] 70 public class TestPackage 71 { 72 private string name; 73 private string fullName; 74 75 private ListDictionary settings = new ListDictionary(); 76 77 private string basePath; 78 private string configFile; 79 private string binPath; 80 private bool autoBinPath; 81 82 private ArrayList assemblies; 83 private string testName; 84 private bool isSingleAssembly; 85 86 87 /// <summary> 88 /// Construct a package, specifying the name of the package. 89 /// If the package name is an assembly file type (dll or exe) 90 /// then the resulting package represents a single assembly. 91 /// Otherwise it is a container for multiple assemblies. 92 /// </summary> 93 /// <param name="name">The name of the package</param> 94 public TestPackage( string name ) 95 { 96 this.fullName = name; 97 this.name = Path.GetFileName( name ); 98 this.assemblies = new ArrayList(); 99 if ( IsAssemblyFileType( name ) ) 100 { 101 if (!Path.IsPathRooted(name)) 102 throw new ArgumentException("Assembly in TestPackage must be specified as an absolute path", "name"); 103 104 this.isSingleAssembly = true; 105 this.assemblies.Add(name); 106 } 107 } 108 109 /// <summary> 110 /// Construct a package, specifying the name to be used 111 /// and a list of assemblies. 112 /// </summary> 113 /// <param name="name">The package name, used to name the top-level test node</param> 114 /// <param name="assemblies">The list of assemblies comprising the package</param> 115 public TestPackage( string name, IList assemblies ) 116 { 117 this.fullName = name; 118 this.name = Path.GetFileName( name ); 119 this.assemblies = new ArrayList(); 120 foreach (string assembly in assemblies) 121 { 122 if (!Path.IsPathRooted(assembly)) 123 throw new ArgumentException("Assembly in TestPackage must be specified as an absolute path", "assemblies"); 124 this.assemblies.Add(assembly); 125 } 126 this.isSingleAssembly = false; 127 } 128 129 /// <summary> 130 /// Gets the name of the package 131 /// </summary> 132 public string Name 133 { 134 get { return name; } 135 } 136 137 /// <summary> 138 /// Gets the full name of the package, which is usually 139 /// the path to the NUnit project used to create the it 140 /// </summary> 141 public string FullName 142 { 143 get { return fullName; } 144 } 145 146 /// <summary> 147 /// The BasePath to be used in loading the assemblies 148 /// </summary> 149 public string BasePath 150 { 151 get { return basePath; } 152 set { basePath = value; } 153 } 154 155 /// <summary> 156 /// The configuration file to be used 157 /// </summary> 158 public string ConfigurationFile 159 { 160 get { return configFile; } 161 set { configFile = value; } 162 } 163 164 /// <summary> 165 /// Addditional directories to be probed when loading assemblies 166 /// </summary> 167 public string PrivateBinPath 168 { 169 get { return binPath; } 170 set { binPath = value; } 171 } 172 173 /// <summary> 174 /// Indicates whether the probing path should be generated 175 /// automatically based on the list of assemblies. 176 /// </summary> 177 public bool AutoBinPath 178 { 179 get { return autoBinPath; } 180 set { autoBinPath = value; } 181 } 182 183 /// <summary> 184 /// Assemblies to be loaded. At least one must be specified. 185 /// </summary> 186 public IList Assemblies 187 { 188 get { return assemblies; } 189 } 190 191 /// <summary> 192 /// Return true if the package represents a single assembly. 193 /// No root node is displayed in that case. 194 /// </summary> 195 public bool IsSingleAssembly 196 { 197 get { return isSingleAssembly; } 198 } 199 200 /// <summary> 201 /// Fully qualified name of test to be loaded. If not 202 /// specified, all the tests in the assemblies are loaded. 203 /// </summary> 204 public string TestName 205 { 206 get { return testName; } 207 set { testName = value; } 208 } 209 210 /// <summary> 211 /// Gets the dictionary of settings for this TestPackage 212 /// </summary> 213 public IDictionary Settings 214 { 215 get { return settings; } 216 } 217 218 /// <summary> 219 /// Return the value of a setting or a default. 220 /// </summary> 221 /// <param name="name">The name of the setting</param> 222 /// <param name="defaultSetting">The default value</param> 223 /// <returns></returns> 224 public object GetSetting(string name, object defaultSetting) 225 { 226 object setting = settings[name]; 227 228 return setting == null ? defaultSetting : setting; 229 } 230 231 /// <summary> 232 /// Return the value of a string setting or a default. 233 /// </summary> 234 /// <param name="name">The name of the setting</param> 235 /// <param name="defaultSetting">The default value</param> 236 /// <returns></returns> 237 public string GetSetting(string name, string defaultSetting) 238 { 239 object setting = settings[name]; 240 241 return setting == null ? defaultSetting : (string)setting; 242 } 243 244 /// <summary> 245 /// Return the value of a bool setting or a default. 246 /// </summary> 247 /// <param name="name">The name of the setting</param> 248 /// <param name="defaultSetting">The default value</param> 249 /// <returns></returns> 250 public bool GetSetting(string name, bool defaultSetting) 251 { 252 object setting = settings[name]; 253 254 return setting == null ? defaultSetting : (bool)setting; 255 } 256 257 /// <summary> 258 /// Return the value of an int setting or a default. 259 /// </summary> 260 /// <param name="name">The name of the setting</param> 261 /// <param name="defaultSetting">The default value</param> 262 /// <returns></returns> 263 public int GetSetting(string name, int defaultSetting) 264 { 265 object setting = settings[name]; 266 267 return setting == null ? defaultSetting : (int)setting; 268 } 269 270 /// <summary> 271 /// Return the value of a enum setting or a default. 272 /// </summary> 273 /// <param name="name">The name of the setting</param> 274 /// <param name="defaultSetting">The default value</param> 275 /// <returns></returns> 276 public System.Enum GetSetting(string name, System.Enum defaultSetting) 277 { 278 object setting = settings[name]; 279 280 return setting == null ? defaultSetting : (System.Enum)setting; 281 } 282 283 private static bool IsAssemblyFileType(string path) 284 { 285 string extension = Path.GetExtension( path ).ToLower(); 286 return extension == ".dll" || extension == ".exe"; 287 } 288 } 289}