/// </summary>
private EventListener listener;
+ /// <summary>
+ /// Indicate whether files should be shadow copied
+ /// </summary>
+ private bool shadowCopyFiles = true;
+
#endregion
#region Properties
+ public AppDomain AppDomain
+ {
+ get { return domain; }
+ }
+
public TextWriter Out
{
get { return outWriter; }
get { return Runner.FrameworkVersion; }
}
+ public bool ShadowCopyFiles
+ {
+ get { return shadowCopyFiles; }
+ set
+ {
+ if ( this.domain != null )
+ throw new ArgumentException( "ShadowCopyFiles may not be set after domain is created" );
+ shadowCopyFiles = value;
+ }
+ }
+
+ public TestResult[] Results
+ {
+ get { return Runner.Results; }
+ }
+
+ public TestResult Result
+ {
+ get { return Runner.Result; }
+ }
+
#endregion
#region Constructors
public Test Load( NUnitProject project )
{
- if ( project.IsAssemblyWrapper )
- return Load( project.ActiveConfig.Assemblies[0].FullPath );
- else
- return Load( project.ProjectPath, project.ActiveConfig.TestAssemblies );
+ return Load( project, null );
}
public Test Load( NUnitProject project, string testFixture )
{
+ ProjectConfig cfg = project.ActiveConfig;
+
if ( project.IsAssemblyWrapper )
- return Load( project.ActiveConfig.Assemblies[0].FullPath, testFixture );
+ return Load( cfg.Assemblies[0].FullPath, testFixture );
else
- return Load( project.ProjectPath, project.ActiveConfig.TestAssemblies, testFixture );
+ return Load( project.ProjectPath, cfg.BasePath, cfg.ConfigurationFile, cfg.PrivateBinPath, cfg.TestAssemblies, testFixture );
}
public void Unload()
try
{
AppDomain.Unload(domain);
- DirectoryInfo cacheDir = new DirectoryInfo(cachePath);
- if(cacheDir.Exists) cacheDir.Delete(true);
+ if ( this.ShadowCopyFiles )
+ DeleteCacheDir( new DirectoryInfo( cachePath ) );
}
catch( CannotUnloadAppDomainException )
{
Runner.CancelRun();
}
+ public void Wait()
+ {
+ Runner.Wait();
+ }
+
// For now, just publish any unhandled exceptions and let the listener
// figure out what to do with them.
private void OnUnhandledException( object sender, UnhandledExceptionEventArgs e )
#endregion
- #region Helpers Used in AppDomain Creation
+ #region Helpers Used in AppDomain Creation and Removal
/// <summary>
/// Construct an application domain for testing a single assembly
domain = MakeAppDomain( testFileName, appBase, configFile, binPath );
}
- private void CreateDomain( NUnitProject project )
- {
- ProjectConfig cfg = project.ActiveConfig;
-
- if ( project.IsAssemblyWrapper )
- CreateDomain( cfg.Assemblies[0].FullPath );
- else
- CreateDomain( project.ProjectPath, cfg.BasePath, cfg.ConfigurationFilePath, cfg.PrivateBinPath, cfg.TestAssemblies );
- }
-
/// <summary>
/// This method creates appDomains for the framework.
/// </summary>
// We always use the same application name
setup.ApplicationName = "Tests";
- // We always want to do shadow copying. Note that we do NOT
+ // Note that we do NOT
// set ShadowCopyDirectories because we rely on the default
// setting of ApplicationBase plus PrivateBinPath
- setup.ShadowCopyFiles = "true";
- setup.ShadowCopyDirectories = appBase;
+ if ( this.ShadowCopyFiles )
+ {
+ setup.ShadowCopyFiles = "true";
+ setup.ShadowCopyDirectories = appBase;
+ }
+ else
+ {
+ setup.ShadowCopyFiles = "false";
+ }
setup.ApplicationBase = appBase;
setup.ConfigurationFile = configFile;
AppDomain runnerDomain = AppDomain.CreateDomain(domainName, evidence, setup);
- ConfigureCachePath(runnerDomain);
+ if ( this.ShadowCopyFiles )
+ ConfigureCachePath(runnerDomain);
return runnerDomain;
}
return;
}
+ /// <summary>
+ /// Helper method to delete the cache dir. This method deals
+ /// with a bug that occurs when pdb files are marked read-only.
+ /// </summary>
+ /// <param name="cacheDir"></param>
+ private void DeleteCacheDir( DirectoryInfo cacheDir )
+ {
+ if(cacheDir.Exists)
+ {
+ foreach( DirectoryInfo dirInfo in cacheDir.GetDirectories() )
+ {
+ dirInfo.Attributes &= ~FileAttributes.ReadOnly;
+ DeleteCacheDir( dirInfo );
+ }
+
+ foreach( FileInfo fileInfo in cacheDir.GetFiles() )
+ {
+ fileInfo.Attributes &= ~FileAttributes.ReadOnly;
+ }
+
+ cacheDir.Delete(true);
+ }
+ }
+
#endregion
}
}