PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/src/NUnit/interfaces/TestPackage.cs

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