importing messaging-2008 branch to trunk, going on.
[mono.git] / mcs / nunit24 / NUnitCore / interfaces / TestPackage.cs
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
6 using System;\r
7 using System.IO;\r
8 using System.Collections;\r
9 using System.Collections.Specialized;\r
10 \r
11 namespace NUnit.Core\r
12 {\r
13         /// <summary>\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
18         /// </summary>\r
19         [Serializable]\r
20         public class TestPackage\r
21         {\r
22                 private string name;\r
23                 private string fullName;\r
24 \r
25                 private ListDictionary settings = new ListDictionary();\r
26 \r
27                 private string basePath;\r
28                 private string configFile;\r
29                 private string binPath;\r
30                 private bool autoBinPath;\r
31 \r
32                 private ArrayList assemblies;\r
33                 private string testName;\r
34                 private bool isSingleAssembly;\r
35 \r
36 \r
37                 /// <summary>\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
42                 /// </summary>\r
43                 /// <param name="name">The name of the package</param>\r
44                 public TestPackage( string name )\r
45                 {\r
46                         this.fullName = name;\r
47                         this.name = Path.GetFileName( name );\r
48                         this.assemblies = new ArrayList();\r
49                         if ( IsAssemblyFileType( name ) )\r
50                         {\r
51                                 this.isSingleAssembly = true;\r
52                                 this.assemblies.Add( name );\r
53                         }\r
54                 }\r
55 \r
56                 /// <summary>\r
57                 /// Construct a package, specifying the name to be used\r
58                 /// and a list of assemblies.\r
59                 /// </summary>\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
63                 {\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
68                 }\r
69 \r
70                 /// <summary>\r
71                 /// Gets the name of the package\r
72                 /// </summary>\r
73                 public string Name\r
74                 {\r
75                         get { return name; }\r
76                 }\r
77 \r
78                 /// <summary>\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
81                 /// </summary>\r
82                 public string FullName\r
83                 {\r
84                         get { return fullName; }\r
85                 }\r
86 \r
87                 /// <summary>\r
88                 /// The BasePath to be used in loading the assemblies\r
89                 /// </summary>\r
90                 public string BasePath\r
91                 {\r
92                         get { return basePath; }\r
93                         set { basePath = value; }\r
94                 }\r
95 \r
96                 /// <summary>\r
97                 /// The configuration file to be used\r
98                 /// </summary>\r
99                 public string ConfigurationFile\r
100                 {\r
101                         get { return configFile; }\r
102                         set { configFile = value; }\r
103                 }\r
104 \r
105                 /// <summary>\r
106                 /// Addditional directories to be probed when loading assemblies\r
107                 /// </summary>\r
108                 public string PrivateBinPath\r
109                 {\r
110                         get { return binPath; }\r
111                         set { binPath = value; }\r
112                 }\r
113 \r
114                 /// <summary>\r
115                 /// Indicates whether the probing path should be generated\r
116                 /// automatically based on the list of assemblies.\r
117                 /// </summary>\r
118                 public bool AutoBinPath\r
119                 {\r
120                         get { return autoBinPath; }\r
121                         set { autoBinPath = value; }\r
122                 }\r
123 \r
124                 /// <summary>\r
125                 /// Assemblies to be loaded. At least one must be specified.\r
126                 /// </summary>\r
127                 public IList Assemblies\r
128                 {\r
129                         get { return assemblies; }\r
130                 }\r
131 \r
132                 /// <summary>\r
133                 /// Return true if the package represents a single assembly.\r
134                 /// No root node is displayed in that case.\r
135                 /// </summary>\r
136                 public bool IsSingleAssembly\r
137                 {\r
138                         get { return isSingleAssembly; }\r
139                 }\r
140 \r
141                 /// <summary>\r
142                 /// Fully qualified name of test to be loaded. If not \r
143                 /// specified, all the tests in the assemblies are loaded.\r
144                 /// </summary>\r
145                 public string TestName\r
146                 {\r
147                         get { return testName; }\r
148                         set { testName = value; }\r
149                 }\r
150 \r
151                 /// <summary>\r
152                 /// Gets the dictionary of settings for this TestPackage\r
153                 /// </summary>\r
154                 public IDictionary Settings\r
155                 {\r
156                         get { return settings; }\r
157                 }\r
158 \r
159                 /// <summary>\r
160                 /// Return the value of a bool setting or a default.\r
161                 /// </summary>\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
166                 {\r
167                         object setting = settings[name];\r
168                         \r
169                         return setting == null ? defaultSetting : (bool)setting;\r
170                 }\r
171 \r
172                 private static bool IsAssemblyFileType( string path )\r
173                 {\r
174                         string extension = Path.GetExtension( path ).ToLower();\r
175                         return extension == ".dll" || extension == ".exe";\r
176                 }\r
177         }\r
178 }\r