Exemple #1
0
        public SolutionDriver(
            NuGetConfigGenerator nuGetConfigGenerator,
            TestRunConfiguration testRunConfiguration,
            ProjectBuilderFactory projectBuilderFactory,
            Folders folders,
            TestProjectFolders testProjectFolders,
            SolutionNamingConvention solutionNamingConvention)
        {
            _nuGetConfigGenerator  = nuGetConfigGenerator;
            _testRunConfiguration  = testRunConfiguration;
            _projectBuilderFactory = projectBuilderFactory;
            _folders = folders;
            _solutionNamingConvention = solutionNamingConvention;
            NuGetSources = new List <NuGetSource>
            {
                new NuGetSource("LocalSpecFlowDevPackages", _folders.NuGetFolder)
            };

            if (testRunConfiguration.UnitTestProvider == UnitTestProvider.SpecRun)
            {
                NuGetSources.Add(new NuGetSource("SpecFlow CI", "https://www.myget.org/F/specflow/api/v3/index.json"));
                NuGetSources.Add(new NuGetSource("SpecFlow Unstable", "https://www.myget.org/F/specflow-unstable/api/v3/index.json"));
            }

            _solution = new Solution(SolutionName);
            testProjectFolders.PathToSolutionFile = Path.Combine(_folders.FolderToSaveGeneratedSolutions, SolutionName, $"{SolutionName}.sln");
        }
Exemple #2
0
 public ConfigurationSteps(VSTestExecutionDriver vstestExecutionDriver, ConfigurationDriver configurationDriver, TestRunConfiguration testRunConfiguration, SolutionDriver solutionDriver)
 {
     _vstestExecutionDriver = vstestExecutionDriver;
     _configurationDriver   = configurationDriver;
     _testRunConfiguration  = testRunConfiguration;
     _solutionDriver        = solutionDriver;
 }
Exemple #3
0
        /// <summary>
        /// Creates test run.
        /// </summary>
        private void CreateTestRun()
        {
            // Skip run creation if already exists.
            if (testRun != null)
            {
                return;
            }

            Guid runId = Guid.NewGuid();

            this.testRun = new TestRun(runId);

            // We cannot rely on the StartTime for the first test result
            // In case of parallel, first test result is the fastest test and not the one which started first.
            // Setting Started to DateTime.Now in Initialize will make sure we include the startup cost, which was being ignored earlier.
            // This is in parity with the way we set this.testRun.Finished
            this.testRun.Started = this.testRunStartTime;

            // Save default test settings
            string runDeploymentRoot           = trxFileHelper.ReplaceInvalidFileNameChars(this.testRun.Name);
            TestRunConfiguration testrunConfig = new TestRunConfiguration("default", trxFileHelper);

            testrunConfig.RunDeploymentRootDirectory = runDeploymentRoot;
            this.testRun.RunConfiguration            = testrunConfig;
        }
Exemple #4
0
        public SolutionDriver(
            NuGetConfigGenerator nuGetConfigGenerator,
            TestRunConfiguration testRunConfiguration,
            ProjectBuilderFactory projectBuilderFactory,
            Folders folders,
            TestProjectFolders testProjectFolders,
            SolutionNamingConvention solutionNamingConvention)
        {
            _nuGetConfigGenerator  = nuGetConfigGenerator;
            _testRunConfiguration  = testRunConfiguration;
            _projectBuilderFactory = projectBuilderFactory;
            _folders = folders;
            _solutionNamingConvention = solutionNamingConvention;
            NuGetSources = new List <NuGetSource>
            {
                new NuGetSource("LocalSpecFlowDevPackages", _folders.NuGetFolder),
                new NuGetSource("SpecFlow CI", "https://www.myget.org/F/specflow/api/v3/index.json"),
                new NuGetSource("SpecFlow Unstable", "https://www.myget.org/F/specflow-unstable/api/v3/index.json")
            };

            if (testRunConfiguration.UnitTestProvider == UnitTestProvider.SpecRun)
            {
                NuGetSources.Add(new NuGetSource("SpecFlow CI", "https://www.myget.org/F/specflow/api/v3/index.json"));
                NuGetSources.Add(new NuGetSource("SpecFlow Unstable", "https://www.myget.org/F/specflow-unstable/api/v3/index.json"));
            }
            if (testRunConfiguration.TargetFramework == TargetFramework.Net50 && testRunConfiguration.UnitTestProvider == UnitTestProvider.NUnit3)
            {
                //NUnit is not supporting .NET 5 in the latest release (3.12.0), so add the myget feed for the pre-release versions
                NuGetSources.Add(new NuGetSource("NUnit Dev", "https://www.myget.org/F/nunit/api/v3/index.json"));
            }

            _solution = new Solution(SolutionName);
            testProjectFolders.PathToSolutionFile = Path.Combine(_folders.FolderToSaveGeneratedSolutions, SolutionName, $"{SolutionName}.sln");
        }
Exemple #5
0
        private async Task <TestRun> PerformRunTest(TestRunConfiguration configuration, Test test)
        {
            var testRun = new TestRun(test, configuration);

            this.testRunNotificationService.NotifyTestRunStarting(testRun);

            try
            {
                await this.testRunnerService.RunTest(testRun);

                if (testRun.WasSuccessful)
                {
                    this.testRunNotificationService.NotifyTestPassed(testRun);
                }
                else
                {
                    this.testRunNotificationService.NotifyTestFailed(testRun);
                }
            }
            catch
            {
                this.testRunNotificationService.NotifyTestFailed(testRun);
                throw;
            }

            return(testRun);
        }
Exemple #6
0
        public async Task <ActionResult> RunTest(int id, TestConfigurationResource testConfiguration)
        {
            TestRunConfiguration domainConfiguration = this.objectMapper.Map(testConfiguration);

            await this.testOrchestrationService.RunTest(id, domainConfiguration);

            return(this.Ok());
        }
Exemple #7
0
        private XElement CreateTestSuiteElement(List <TestResultInfo> results, TestRunConfiguration runConfiguration, List <TestMessageInfo> messages)
        {
            var testCaseElements = results.Select(a => this.CreateTestCaseElement(a));

            StringBuilder stdOut = new StringBuilder();

            foreach (var m in results.SelectMany(x => x.Messages))
            {
                if (TestResultMessage.StandardOutCategory.Equals(m.Category, StringComparison.OrdinalIgnoreCase))
                {
                    stdOut.AppendLine(m.Text);
                }
            }

            var frameworkInfo = messages.Where(x => x.Level == TestMessageLevel.Informational);

            if (frameworkInfo.Any())
            {
                stdOut.AppendLine(string.Empty);
                stdOut.AppendLine("Test Framework Informational Messages:");

                foreach (var m in frameworkInfo)
                {
                    stdOut.AppendLine(m.Message);
                }
            }

            StringBuilder stdErr = new StringBuilder();

            foreach (var m in messages.Where(x => x.Level != TestMessageLevel.Informational))
            {
                stdErr.AppendLine($"{m.Level} - {m.Message}");
            }

            // Adding required properties, system-out, and system-err elements in the correct
            // positions as required by the xsd. In system-out collapse consequtive newlines to a
            // single newline.
            var element = new XElement(
                "testsuite",
                new XElement("properties"),
                testCaseElements,
                new XElement("system-out", stdOut.ToString()),
                new XElement("system-err", stdErr.ToString()));

            element.SetAttributeValue("name", Path.GetFileName(results.First().AssemblyPath));

            element.SetAttributeValue("tests", results.Count);
            element.SetAttributeValue("skipped", results.Where(x => x.Outcome == TestOutcome.Skipped).Count());
            element.SetAttributeValue("failures", results.Where(x => x.Outcome == TestOutcome.Failed).Count());
            element.SetAttributeValue("errors", 0); // looks like this isn't supported by .net?
            element.SetAttributeValue("time", results.Sum(x => x.Duration.TotalSeconds).ToString(CultureInfo.InvariantCulture));
            element.SetAttributeValue("timestamp", runConfiguration.StartTime.ToString("s"));
            element.SetAttributeValue("hostname", Environment.MachineName);
            element.SetAttributeValue("id", 0); // we never output multiple, so this is always zero.
            element.SetAttributeValue("package", Path.GetFileName(results.First().AssemblyPath));

            return(element);
        }
Exemple #8
0
        public string Serialize(
            LoggerConfiguration loggerConfiguration,
            TestRunConfiguration runConfiguration,
            List <TestResultInfo> results)
        {
            var doc = new XDocument(CreateAssembliesElement(results, loggerConfiguration, runConfiguration));

            return(doc.ToString());
        }
 public TestProperties(ITestElement testElement, TestRunConfiguration runConfig)
 {
     _testElement = testElement;
     #if !VS11
     if (runConfig != null) {
         _testSettings = runConfig.TestSettingsProperties;
     }
     #endif
 }
        public TestProperties(ITestElement testElement, TestRunConfiguration runConfig)
        {
            _testElement = testElement;
#if !DEV11
            if (runConfig != null)
            {
                _testSettings = runConfig.TestSettingsProperties;
            }
#endif
        }
        public string Serialize(
            LoggerConfiguration loggerConfiguration,
            TestRunConfiguration runConfiguration,
            List <TestResultInfo> results,
            List <TestMessageInfo> messages)
        {
            var doc = new XDocument(this.CreateTestRunElement(results, runConfiguration));

            return(doc.ToString());
        }
Exemple #12
0
        private string GetAdditionalCommandLine()
        {
            TestRunConfiguration   runConfig         = m_runContext.RunConfig.TestRun.RunConfiguration;
            VsIdeHostRunConfigData runConfigHostData = runConfig.HostData[Name] as VsIdeHostRunConfigData;

            if (runConfigHostData != null)
            {
                return(runConfigHostData.AdditionalCommandLineArguments);
            }
            return(null);
        }
 public ProjectBuilderFactory(TestProjectFolders testProjectFolders, TestRunConfiguration testRunConfiguration, CurrentVersionDriver currentVersionDriver, ConfigurationGeneratorFactory configurationGeneratorFactory, BindingsGeneratorFactory bindingsGeneratorFactory, FeatureFileGenerator featureFileGenerator,
                              Folders folders)
 {
     _testProjectFolders            = testProjectFolders;
     _testRunConfiguration          = testRunConfiguration;
     _currentVersionDriver          = currentVersionDriver;
     _configurationGeneratorFactory = configurationGeneratorFactory;
     _bindingsGeneratorFactory      = bindingsGeneratorFactory;
     _featureFileGenerator          = featureFileGenerator;
     _folders = folders;
 }
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Trace.TraceInformation("Called DynamicHostAdapter.Initialize");
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig  = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
        }
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Trace.TraceInformation("Called DynamicHostAdapter.Initialize");
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));

        }
Exemple #16
0
        private bool TryGetRegistryHiveFromConfig(TestRunConfiguration runConfig, out string hive)
        {
            const string VSHiveElement = "VSHive";

            hive = null;

            if (runConfig == null)
            {
                return(false);
            }
            string configFileName = runConfig.Storage;

            if (string.IsNullOrEmpty(configFileName))
            {
                return(false);
            }
            if (!File.Exists(configFileName))
            {
                // This will happen in the case with no file where a default file is created.
                if (!configFileName.StartsWith("default", StringComparison.OrdinalIgnoreCase))
                {
                    SendResult(string.Format(CultureInfo.InvariantCulture, "VsIdeHostAdapter: Unable to find config file: {0}", configFileName), TestOutcome.Warning, false);
                }
                return(false);
            }

            try
            {
                using (var configXml = new XmlTextReader(configFileName))
                {
                    while (configXml.Read())
                    {
                        if (configXml.NodeType == XmlNodeType.Element && configXml.Name == VSHiveElement)
                        {
                            configXml.Read();
                            if (configXml.NodeType == XmlNodeType.Text)
                            {
                                hive = configXml.Value;
                                return(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Report the error to the agent.
                SendResult(string.Format(CultureInfo.InvariantCulture, "VsIdeHostAdapter: Error reading config file: {0}", ex.ToString()), TestOutcome.Warning, false);
            }
            return(false);
        }
Exemple #17
0
        /// <summary>
        /// Determine which registry hive to use for Visual Studio:
        ///     If using RunConfig, get it from RunConfig
        ///     Else get it from environment.
        /// </summary>
        /// <returns></returns>
        private string GetRegistryHive()
        {
            // Note that Run Config Data can be null, e.g. when executing using HostType attribute.
            TestRunConfiguration runConfig = _runContext.RunConfig.TestRun.RunConfiguration;
            string configKey;

            if (TryGetRegistryHiveFromConfig(runConfig, out configKey))
            {
                return(configKey);
            }

            // Default to the experimental hive for the development evnironment.
            return("10.0Exp");
        }
Exemple #18
0
        private XElement CreateTestSuitesElement(
            List <TestResultInfo> results,
            TestRunConfiguration runConfiguration,
            List <TestMessageInfo> messages)
        {
            var assemblies        = results.Select(x => x.AssemblyPath).Distinct().ToList();
            var testsuiteElements = assemblies
                                    .Select(a => this.CreateTestSuiteElement(
                                                results.Where(x => x.AssemblyPath == a).ToList(),
                                                runConfiguration,
                                                messages));

            return(new XElement("testsuites", testsuiteElements));
        }
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            // We delay inner TAs initialization until Run method because we don't know which test type this is going to be.
            m_runContext = runContext;

            TestRunConfiguration runConfig = m_runContext.RunConfig.TestRun.RunConfiguration;

            Debug.Assert(runConfig != null);
            VsIdeHostRunConfigData runConfigHostData = runConfig.HostData[VsIdeHostAdapter.Name] as VsIdeHostRunConfigData;

            if (runConfigHostData != null)
            {
                VsIdeTestHostContext.AdditionalTestData = runConfigHostData.AdditionalTestData;
            }
        }
Exemple #20
0
        public void GetFormattedLogFilePathShouldReplaceFrameworkToken()
        {
            var runConfig = new TestRunConfiguration {
                TargetFramework = ".NETCoreApp,Version=v5.0"
            };
            var config = new Dictionary <string, string>
            {
                { LoggerConfiguration.LogFilePathKey, "/tmp/results/{framework}.json" },
            };
            var loggerConfiguration = new LoggerConfiguration(config);

            var logFilePath = loggerConfiguration.GetFormattedLogFilePath(runConfig);

            Assert.AreEqual("/tmp/results/NETCoreApp50.json", logFilePath);
        }
Exemple #21
0
        public void GetFormattedLogFilePathShouldReplaceAssemblyToken()
        {
            var runConfig = new TestRunConfiguration {
                AssemblyPath = "/tmp/foo.dll"
            };
            var config = new Dictionary <string, string>
            {
                { LoggerConfiguration.LogFilePathKey, "/tmp/results/{assembly}.json" },
            };
            var loggerConfiguration = new LoggerConfiguration(config);

            var logFilePath = loggerConfiguration.GetFormattedLogFilePath(runConfig);

            Assert.AreEqual("/tmp/results/foo.json", logFilePath);
        }
        private static XElement CreateAssembliesElement(
            List <TestResultInfo> results,
            LoggerConfiguration loggerConfiguration,
            TestRunConfiguration runConfiguration)
        {
            var assemblies = from result in results
                             group result by result.AssemblyPath into resultsByAssembly
                             orderby resultsByAssembly.Key
                             select CreateAssemblyElement(resultsByAssembly, loggerConfiguration, runConfiguration);

            var element = new XElement("assemblies", assemblies);

            element.SetAttributeValue("timestamp", runConfiguration.StartTime.ToString(CultureInfo.InvariantCulture));

            return(element);
        }
Exemple #23
0
        private void ConfigureTracing(TestRunConfiguration testRunConfiguration)
        {
            var path = testRunConfiguration.TraceFilePath;

            if (testRunConfiguration.EnableTracing)
            {
                ChutzpahTracer.AddFileListener(path);
            }
            else
            {
                // TODO (mmanela): There is a known issue with this if the user is running chutzpah in VS and changes their trace path
                // This will result in that path not getting removed until the VS is restarted. To fix this we need to keep trace of previous paths
                // and clear them all out.
                ChutzpahTracer.RemoveFileListener(path);
            }
        }
Exemple #24
0
        public string Serialize(
            LoggerConfiguration loggerConfiguration,
            TestRunConfiguration runConfiguration,
            List <TestResultInfo> results,
            List <TestMessageInfo> messages)
        {
            var res = from r in results
                      group r by r.AssemblyPath
                      into assemblies
                      orderby assemblies.Key
                      select this.CreateAssembly(assemblies);

            var content = new StringBuilder();

            new JsonSerializer().Serialize(new StringWriter(content), new TestReport(res, messages));
            return(content.ToString());
        }
Exemple #25
0
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Trace.TraceInformation("Called MtaHostAdapter.Initialize");
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig  = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            m_mtaThread = new Thread(MtaWorkerThreadMain);
            m_mtaThread.SetApartmentState(ApartmentState.MTA);
            m_completed     = false;
            m_runStartEvent = new AutoResetEvent(false);
            m_runEndEvent   = new AutoResetEvent(false);
            m_mtaThread.Start();
        }
 public SolutionDriver(NuGetConfigGenerator nuGetConfigGenerator, TestRunConfiguration testRunConfiguration, ProjectBuilderFactory projectBuilderFactory, Folders folders, NuGet nuGet, TestProjectFolders testProjectFolders, Compiler compiler, IOutputWriter outputWriter)
 {
     _nuGetConfigGenerator  = nuGetConfigGenerator;
     _testRunConfiguration  = testRunConfiguration;
     _projectBuilderFactory = projectBuilderFactory;
     _folders            = folders;
     _nuGet              = nuGet;
     _testProjectFolders = testProjectFolders;
     _compiler           = compiler;
     _outputWriter       = outputWriter;
     NuGetSources        = new List <NuGetSource>
     {
         new NuGetSource("LocalSpecFlowDevPackages", _folders.NuGetFolder),
         new NuGetSource("SpecFlow CI", "https://www.myget.org/F/specflow/api/v3/index.json")
     };
     _solution = new Solution(SolutionName);
     testProjectFolders.PathToSolutionFile = Path.Combine(_folders.FolderToSaveGeneratedSolutions, SolutionName, $"{SolutionName}.sln");
 }
Exemple #27
0
        private TestRunConfiguration BuildTestRunConfiguration(IEnumerable <PathInfo> scriptPaths, TestOptions testOptions)
        {
            var testRunConfiguration = new TestRunConfiguration();

            // Find all chutzpah.json files for the input files
            // Then group files by their respective settings file
            var testGroups        = new List <List <PathInfo> >();
            var fileSettingGroups = from path in scriptPaths
                                    let settingsFile = testSettingsService.FindSettingsFile(path.FullPath, testOptions.ChutzpahSettingsFileEnvironments)
                                                       group path by settingsFile;

            // Scan over the grouped test files and if this file is set up for batching we add those files
            // as a group to be tested. Otherwise, we will explode them out individually so they get run in their
            // own context
            foreach (var group in fileSettingGroups)
            {
                if (group.Key.EnableTestFileBatching.Value)
                {
                    testGroups.Add(group.ToList());
                }
                else
                {
                    foreach (var path in group)
                    {
                        testGroups.Add(new List <PathInfo> {
                            path
                        });
                    }
                }
            }

            testRunConfiguration.TestGroups = testGroups;

            // Take the parallelism degree to be the minimum of any non-null setting in chutzpah.json
            testRunConfiguration.MaxDegreeOfParallelism = fileSettingGroups.Min(x => x.Key.Parallelism);

            // Enable tracing if any setting is true
            testRunConfiguration.EnableTracing = fileSettingGroups.Any(x => x.Key.EnableTracing.HasValue && x.Key.EnableTracing.Value);

            testRunConfiguration.TraceFilePath = fileSettingGroups.Select(x => x.Key.TraceFilePath).FirstOrDefault(x => !string.IsNullOrEmpty(x)) ?? testRunConfiguration.TraceFilePath;

            return(testRunConfiguration);
        }
Exemple #28
0
        /// <summary>
        /// Determine which registry hive to use for Visual Studio:
        ///     If using RunConfig, get it from RunConfig
        ///     Else get it from environment.
        /// </summary>
        /// <returns></returns>
        private string GetRegistryHive()
        {
            // Note that Run Config Data can be null, e.g. when executing using HostType attribute.
            TestRunConfiguration runConfig = _runContext.RunConfig.TestRun.RunConfiguration;
            string configKey;

            if (TryGetRegistryHiveFromConfig(runConfig, out configKey))
            {
                return(configKey);
            }

            if (System.Environment.GetEnvironmentVariable("RUN_NO_EXP") != null)
            {
                return(VSUtility.Version);
            }

            // Default to the experimental hive for the development evnironment.
            return(VSUtility.Version + "Exp");
        }
Exemple #29
0
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Trace.TraceInformation("Called MtaHostAdapter.Initialize");
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));
            m_mtaThread = new Thread(MtaWorkerThreadMain);
            m_mtaThread.SetApartmentState(ApartmentState.MTA);
            m_completed = false;
            m_runStartEvent = new AutoResetEvent(false);
            m_runEndEvent = new AutoResetEvent(false);
            m_mtaThread.Start();

        }
Exemple #30
0
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]  // Base param name is incorrect.
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig  = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));

            SetupChannels();

            // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
            // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
            m_comMessageFilter = new RetryMessageFilter();

            InitHostSide();
        }
Exemple #31
0
        /// <summary>
        /// Determine which registry hive to use for Visual Studio:
        ///     If override value is set, use it, don't use anything else.
        ///     Else If using RunConfig, get it from RunConfig
        ///     Else get it from environment.
        /// </summary>
        /// <returns></returns>
        private string GetRegistryHive()
        {
            // We get registry hive each time we initialize host side, i.e. it can be changed in between tests.
            string overrideHiveValue = RegistrySettings.RegistryHiveOverride;

            if (!string.IsNullOrEmpty(overrideHiveValue))
            {
                return(overrideHiveValue);
            }

            // Note that Run Config Data can be null, e.g. when executing using HostType attribute.
            TestRunConfiguration runConfig         = m_runContext.RunConfig.TestRun.RunConfiguration;
            RunConfigData        runConfigHostData = runConfig.HostData[Constants.VsIdeHostAdapterName] as RunConfigData;

            if (runConfigHostData != null)
            {
                return(runConfigHostData.RegistryHive);
            }

            return(null);    // VsIde will figure out and use default.
        }
Exemple #32
0
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]  // Base param name is incorrect.
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig  = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));

            SetupChannels();

            // TODO: consider more reliable mechanism for hadling VS being busy. Com message filter is only for STA/same thread.
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
                // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
                try
                {
                    m_comMessageFilter = new RetryMessageFilter();
                }
                catch (COMException ex)
                {
                    string message = "Failed to create COM filter (ignorable): " + ex.ToString();
                    Debug.Fail(message);
                    SendResult(ex.Message, TestOutcome.Warning, false);
                    // Ignore the exception, continue without the filter.
                }
            }
            else
            {
                TraceMessage("COM message filter is disabled because it can be registered only in STA apartment, and current apartment is " +
                             Thread.CurrentThread.GetApartmentState().ToString());
            }

            InitHostSession();
        }
        private XElement CreateTestRunElement(List <TestResultInfo> results, TestRunConfiguration runConfiguration)
        {
            var testSuites = from result in results
                             group result by result.AssemblyPath
                             into resultsByAssembly
                             orderby resultsByAssembly.Key
                             select this.CreateAssemblyElement(resultsByAssembly);

            var element = new XElement("test-run", testSuites);

            element.SetAttributeValue("id", 2);

            element.SetAttributeValue("duration", results.Sum(x => x.Duration.TotalSeconds));

            var total = testSuites.Sum(x => (int)x.Attribute("total"));

            // TODO test case count is actually count before filtering
            element.SetAttributeValue("testcasecount", total);
            element.SetAttributeValue("total", total);
            element.SetAttributeValue("passed", testSuites.Sum(x => (int)x.Attribute("passed")));

            var failed = testSuites.Sum(x => (int)x.Attribute("failed"));

            element.SetAttributeValue("failed", failed);
            element.SetAttributeValue("inconclusive", testSuites.Sum(x => (int)x.Attribute("inconclusive")));
            element.SetAttributeValue("skipped", testSuites.Sum(x => (int)x.Attribute("skipped")));

            var resultString = failed > 0 ? ResultStatusFailed : ResultStatusPassed;

            element.SetAttributeValue("result", resultString);

            element.SetAttributeValue("start-time", runConfiguration.StartTime.ToString(DateFormat, CultureInfo.InvariantCulture));
            element.SetAttributeValue("end-time", runConfiguration.EndTime.ToString(DateFormat, CultureInfo.InvariantCulture));

            return(element);
        }
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]  // Base param name is incorrect.
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Debug.Assert(runContext != null);

            m_runContext = runContext;
            m_runConfig = m_runContext.RunConfig.TestRun.RunConfiguration;
            m_workingDir = m_runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Debug.Assert(m_runConfig != null);
            Debug.Assert(!string.IsNullOrEmpty(m_workingDir));

            SetupChannels();

            // TODO: consider more reliable mechanism for hadling VS being busy. Com message filter is only for STA/same thread.
            if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
            {
                // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
                // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
                try
                {
                    m_comMessageFilter = new RetryMessageFilter();
                }
                catch (COMException ex)
                {
                    string message = "Failed to create COM filter (ignorable): " + ex.ToString();
                    Debug.Fail(message);
                    SendResult(ex.Message, TestOutcome.Warning, false);
                    // Ignore the exception, continue without the filter.
                }
            }
            else
            {
                TraceMessage("COM message filter is disabled because it can be registered only in STA apartment, and current apartment is " +
                    Thread.CurrentThread.GetApartmentState().ToString());
            }

            InitHostSession();
        }
        private bool TryGetRegistryHiveFromConfig(TestRunConfiguration runConfig, out string hive)
        {
            const string VSHiveElement = "VSHive";
            hive = null;

            if (runConfig == null)
            {
                return false;
            }
            string configFileName = runConfig.Storage;
            if (string.IsNullOrEmpty(configFileName))
            {
                return false;
            }
            if (!File.Exists(configFileName))
            {
                // This will happen in the case with no file where a default file is created.
                if (!configFileName.StartsWith("default", StringComparison.OrdinalIgnoreCase))
                {
                    SendResult(string.Format(CultureInfo.InvariantCulture, "VsIdeHostAdapter: Unable to find config file: {0}", configFileName), TestOutcome.Warning, false);
                }
                return false;
            }

            try
            {
                using (var configXml = new XmlTextReader(configFileName))
                {
                    while (configXml.Read())
                    {
                        if (configXml.NodeType == XmlNodeType.Element && configXml.Name == VSHiveElement)
                        {
                            configXml.Read();
                            if (configXml.NodeType == XmlNodeType.Text)
                            {
                                hive = configXml.Value;
                                return true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Report the error to the agent.
                SendResult(string.Format(CultureInfo.InvariantCulture, "VsIdeHostAdapter: Error reading config file: {0}", ex.ToString()), TestOutcome.Warning, false);
            }
            return false;
        }
        /// <summary>
        /// ITestAdapter method: called to initialize run context for this adapter.
        /// </summary>
        /// <param name="runContext">The run context to be used for this run</param>
        void ITestAdapter.Initialize(IRunContext runContext)
        {
            Contract.Assert(runContext != null);

            _runContext = runContext;
            _runConfig = _runContext.RunConfig.TestRun.RunConfiguration;
            _workingDir = _runContext.RunContextVariables.GetStringValue("TestDeploymentDir");

            Contract.Assert(_runConfig != null);
            Contract.Assert(!string.IsNullOrEmpty(_workingDir));

            SetupChannels();

            // Install COM message filter to retry COM calls when VS IDE is busy, e.g. when getting the addin from VS IDE.
            // This prevents RPC_E_CALL_REJECTED error when VS IDE is busy.
            _comMessageFilter = new RetryMessageFilter();

            InitHostSide();
        }