// **************************************************************** // Copyright 2007, Charlie Poole // This is free software licensed under the NUnit license. You may // obtain a copy of the license at http://nunit.org/?p=license&r=2.4 // **************************************************************** using System; using System.IO; using System.Collections; using System.Collections.Specialized; namespace NUnit.Core { /// /// TestPackage holds information about a set of tests to /// be loaded by a TestRunner. It may represent a single /// assembly or a set of assemblies. It supports selection /// of a single test fixture for loading. /// [Serializable] public class TestPackage { private string name; private string fullName; private ListDictionary settings = new ListDictionary(); private string basePath; private string configFile; private string binPath; private bool autoBinPath; private ArrayList assemblies; private string testName; private bool isSingleAssembly; /// /// Construct a package, specifying the name of the package. /// If the package name is an assembly file type (dll or exe) /// then the resulting package represents a single assembly. /// Otherwise it is a container for multiple assemblies. /// /// The name of the package public TestPackage( string name ) { this.fullName = name; this.name = Path.GetFileName( name ); this.assemblies = new ArrayList(); if ( IsAssemblyFileType( name ) ) { this.isSingleAssembly = true; this.assemblies.Add( name ); } } /// /// Construct a package, specifying the name to be used /// and a list of assemblies. /// /// The package name, used to name the top-level test node /// The list of assemblies comprising the package public TestPackage( string name, IList assemblies ) { this.fullName = name; this.name = Path.GetFileName( name ); this.assemblies = new ArrayList( assemblies ); this.isSingleAssembly = false; } /// /// Gets the name of the package /// public string Name { get { return name; } } /// /// Gets the full name of the package, which is usually /// the path to the NUnit project used to create the it /// public string FullName { get { return fullName; } } /// /// The BasePath to be used in loading the assemblies /// public string BasePath { get { return basePath; } set { basePath = value; } } /// /// The configuration file to be used /// public string ConfigurationFile { get { return configFile; } set { configFile = value; } } /// /// Addditional directories to be probed when loading assemblies /// public string PrivateBinPath { get { return binPath; } set { binPath = value; } } /// /// Indicates whether the probing path should be generated /// automatically based on the list of assemblies. /// public bool AutoBinPath { get { return autoBinPath; } set { autoBinPath = value; } } /// /// Assemblies to be loaded. At least one must be specified. /// public IList Assemblies { get { return assemblies; } } /// /// Return true if the package represents a single assembly. /// No root node is displayed in that case. /// public bool IsSingleAssembly { get { return isSingleAssembly; } } /// /// Fully qualified name of test to be loaded. If not /// specified, all the tests in the assemblies are loaded. /// public string TestName { get { return testName; } set { testName = value; } } /// /// Gets the dictionary of settings for this TestPackage /// public IDictionary Settings { get { return settings; } } /// /// Return the value of a bool setting or a default. /// /// The name of the setting /// The default value /// public bool GetSetting( string name, bool defaultSetting ) { object setting = settings[name]; return setting == null ? defaultSetting : (bool)setting; } private static bool IsAssemblyFileType( string path ) { string extension = Path.GetExtension( path ).ToLower(); return extension == ".dll" || extension == ".exe"; } } }