コード例 #1
0
        private bool Deploy(string source, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, IList <DeploymentItem> deploymentItems, ref TestRunDirectories testRunDirectories)
        {
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("MSTestExecutor: Found that deployment items for source {0} are: ", source);

                foreach (var item in deploymentItems)
                {
                    EqtTrace.Info("MSTestExecutor: SourcePath: - {0}", item.SourcePath);
                }
            }

            // Do the deployment.
            IEnumerable <string> warnings;

            var runDirectories = testRunDirectories ?? this.CreateDeploymentDirectories(runContext);

            ValidateArg.NotNull(runDirectories, "runDirectories");
            EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: Using deployment directory {0} for source {1}.", runDirectories.OutDirectory, source);

            this.Deploy(new List <DeploymentItem>(deploymentItems), source, runDirectories.OutDirectory, out warnings);

            // Log warnings
            LogWarnings(testExecutionRecorder, warnings);

            return(deploymentItems != null && deploymentItems.Count > 0);
        }
コード例 #2
0
        /// <summary>
        /// Sets context required for running tests.
        /// </summary>
        /// <param name="source">
        /// source parameter used for setting context
        /// </param>
        private void SetContext(string source)
        {
            if (string.IsNullOrEmpty(source))
            {
                return;
            }

            Exception setWorkingDirectoryException = null;

            this.currentDirectory = Environment.CurrentDirectory;

            try
            {
                Environment.CurrentDirectory = Path.GetDirectoryName(source);
                EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: Changed the working directory to {0}", Environment.CurrentDirectory);
            }
            catch (IOException ex)
            {
                setWorkingDirectoryException = ex;
            }
            catch (System.Security.SecurityException ex)
            {
                setWorkingDirectoryException = ex;
            }

            if (setWorkingDirectoryException != null)
            {
                EqtTrace.ErrorIf(EqtTrace.IsErrorEnabled, "MSTestExecutor.SetWorkingDirectory: Failed to set the working directory to '{0}'. {1}", Path.GetDirectoryName(source), setWorkingDirectoryException);
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns the dependent assemblies of the parameter assembly.
        /// </summary>
        /// <param name="assemblyPath"> Path to assembly to get dependencies for. </param>
        /// <param name="configFile"> Config file to use while trying to resolve dependencies. </param>
        /// <param name="warnings"> The warnings. </param>
        /// <returns> The <see cref="string[]"/>. </returns>
        internal virtual string[] GetFullPathToDependentAssemblies(string assemblyPath, string configFile, out IList <string> warnings)
        {
            Debug.Assert(!string.IsNullOrEmpty(assemblyPath), "assemblyPath");

            EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: start.");

            AppDomainSetup setupInfo = new AppDomainSetup();

            setupInfo.ApplicationBase = Path.GetDirectoryName(Path.GetFullPath(assemblyPath));

            Debug.Assert(string.IsNullOrEmpty(configFile) || File.Exists(configFile), "Config file is specified but does not exist: {0}", configFile);

            AppDomainUtilities.SetConfigurationFile(setupInfo, configFile);

            EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: Using config file: '{0}'.", setupInfo.ConfigurationFile);

            setupInfo.LoaderOptimization = LoaderOptimization.MultiDomainHost;

            AppDomain appDomain = null;

            try
            {
                appDomain = AppDomain.CreateDomain("Dependency finder domain", null, setupInfo);
                if (EqtTrace.IsInfoEnabled)
                {
                    EqtTrace.Info("AssemblyDependencyFinder.GetDependentAssemblies: Created AppDomain.");
                }

                var assemblyResolverType = typeof(AssemblyResolver);

                EqtTrace.SetupRemoteEqtTraceListeners(appDomain);

                // This has to be LoadFrom, otherwise we will have to use AssemblyResolver to find self.
                using (
                    AssemblyResolver resolver =
                        (AssemblyResolver)AppDomainUtilities.CreateInstance(
                            appDomain,
                            assemblyResolverType,
                            new object[] { this.GetResolutionPaths() }))
                {
                    // This has to be Load, otherwise Serialization of argument types will not work correctly.
                    AssemblyLoadWorker worker =
                        (AssemblyLoadWorker)AppDomainUtilities.CreateInstance(appDomain, typeof(AssemblyLoadWorker), null);

                    EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: loaded the worker.");

                    return(worker.GetFullPathToDependentAssemblies(assemblyPath, out warnings));
                }
            }
            finally
            {
                if (appDomain != null)
                {
                    EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: unloading AppDomain...");
                    AppDomain.Unload(appDomain);
                    EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "AssemblyDependencyFinder.GetDependentAssemblies: unloading AppDomain succeeded.");
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Returns whether deployment can happen or not
        /// </summary>
        /// <returns>True if deployment can be done.</returns>
        private bool CanDeploy()
        {
            if (!this.adapterSettings.DeploymentEnabled)
            {
                EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: CanDeploy is false.");
                return(false);
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// The cleanup.
        /// </summary>
        public void Cleanup()
        {
            // Delete the deployment directory
            if (RunDirectories != null && this.adapterSettings.DeleteDeploymentDirectoryAfterTestRunIsComplete)
            {
                EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleting deployment directory {0}", RunDirectories.RootDeploymentDirectory);

                this.fileUtility.DeleteDirectories(RunDirectories.RootDeploymentDirectory);

                EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleted deployment directory {0}", RunDirectories.RootDeploymentDirectory);
            }
        }
コード例 #6
0
 /// <summary>
 /// Log an information message in a given format.
 /// </summary>
 /// <param name="format"> The format. </param>
 /// <param name="args"> The args. </param>
 public void LogInfo(string format, params object[] args)
 {
     EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, format, args);
 }