private void GetValuesFromSolutionSettingsFile(RunSettingsContainer settingsContainer, ILogger logger)
        {
            string solutionRunSettingsFile = GetSolutionSettingsXmlFile();

            try
            {
                if (File.Exists(solutionRunSettingsFile))
                {
                    if (!settingsContainer.GetUnsetValuesFrom(solutionRunSettingsFile))
                    {
                        logger.Log(MessageLevel.Warning,
                                   $"Solution test settings file found at '{solutionRunSettingsFile}', but does not contain {Constants.RunSettingsName} node");
                    }
                }
            }
            catch (InvalidRunSettingsException e) when(e.InnerException != null)
            {
                logger.Log(MessageLevel.Error,
                           $"Solution test settings file could not be parsed, check file '{solutionRunSettingsFile}'. Error message: {e.InnerException.Message}");
            }
            catch (Exception e)
            {
                logger.Log(MessageLevel.Error,
                           $"Solution test settings file could not be parsed, check file '{solutionRunSettingsFile}'. Exception:{Environment.NewLine}{e}");
            }
        }
Пример #2
0
        private void GetValuesFromSolutionSettingsFile(RunSettingsContainer settingsContainer, ILogger logger)
        {
            string solutionRunSettingsFile = GetSolutionSettingsXmlFile();

            try
            {
                if (File.Exists(solutionRunSettingsFile))
                {
                    if (!settingsContainer.GetUnsetValuesFrom(solutionRunSettingsFile))
                    {
                        logger.Log(MessageLevel.Warning, string.Format(Resources.SolutionFoundButMissingNode, solutionRunSettingsFile, Constants.RunSettingsName));
                    }
                }
            }
            catch (InvalidRunSettingsException e) when(e.InnerException != null)
            {
                logger.Log(MessageLevel.Error,
                           $"Solution test settings file could not be parsed, check file '{solutionRunSettingsFile}'. Error message: {e.InnerException.Message}");
            }
            catch (Exception e)
            {
                logger.Log(MessageLevel.Error,
                           string.Format(Resources.CantParseSettings, solutionRunSettingsFile, e));
            }
        }
        private bool CopyToUnsetValues(XPathNavigator sourceNavigator, RunSettingsContainer targetSettingsContainer)
        {
            if (sourceNavigator.MoveToChild(GoogleTestConstants.SettingsName, ""))
            {
                var sourceRunSettings = RunSettingsContainer.LoadFromXml(sourceNavigator);
                targetSettingsContainer.GetUnsetValuesFrom(sourceRunSettings);
                return(true);
            }

            return(false);
        }
        public void GetUnsetValuesFrom__ResultsInCorrectlyMergedContainer()
        {
            var solutionSettings = new RunSettings
            {
                ProjectRegex = null,
                AdditionalTestDiscoveryParam = "bar",
                AdditionalTestExecutionParam = "foo",
                BatchForTestSetup            = "solution"
            };

            var projectSettings1 = new RunSettings
            {
                ProjectRegex = ".*PerformanceTests.exe",
                AdditionalTestDiscoveryParam = "bar",
                AdditionalTestExecutionParam = "foo",
                BatchForTestSetup            = "project1"
            };

            var projectSettings2 = new RunSettings
            {
                ProjectRegex = ".*IntegrationTests.exe",
                AdditionalTestDiscoveryParam = "bar",
                AdditionalTestExecutionParam = "foo",
                BatchForTestSetup            = "project2"
            };

            var container = new RunSettingsContainer {
                SolutionSettings = solutionSettings
            };

            container.ProjectSettings.Add(projectSettings1);
            container.ProjectSettings.Add(projectSettings2);

            _container.GetUnsetValuesFrom(container);

            _container.SolutionSettings.AdditionalTestDiscoveryParam.Should().Be("solution");
            _container.SolutionSettings.AdditionalTestExecutionParam.Should().Be("solution");
            _container.SolutionSettings.BatchForTestSetup.Should().Be("solution");

            _container.ProjectSettings.Count.Should().Be(3);
            _container.ProjectSettings[0].AdditionalTestDiscoveryParam.Should().Be("project1");
            _container.ProjectSettings[1].AdditionalTestDiscoveryParam.Should().Be("project2");
            _container.ProjectSettings[2].AdditionalTestDiscoveryParam.Should().Be("bar");
            _container.ProjectSettings[0].AdditionalTestExecutionParam.Should().Be("project1");
            _container.ProjectSettings[1].AdditionalTestExecutionParam.Should().Be("project2");
            _container.ProjectSettings[2].AdditionalTestExecutionParam.Should().Be("foo");
            _container.ProjectSettings[0].BatchForTestSetup.Should().Be("project1");
            _container.ProjectSettings[1].BatchForTestSetup.Should().BeNull();
            _container.ProjectSettings[2].BatchForTestSetup.Should().Be("project2");
        }
Пример #5
0
        public IXPathNavigable AddRunSettings(IXPathNavigable runSettingDocument,
                                              IRunSettingsConfigurationInfo configurationInfo, ILogger logger)
        {
            XPathNavigator runSettingsNavigator = runSettingDocument.CreateNavigator();

            Debug.Assert(runSettingsNavigator != null, "userRunSettingsNavigator == null!");
            if (!runSettingsNavigator.MoveToChild(Constants.RunSettingsName, ""))
            {
                logger.Log(MessageLevel.Warning, "RunSettingsDocument does not contain a RunSettings node! Canceling settings merging...");
                return(runSettingsNavigator);
            }

            var settingsContainer = new RunSettingsContainer();

            try
            {
                if (settingsContainer.GetUnsetValuesFrom(runSettingsNavigator))
                {
                    runSettingsNavigator.DeleteSelf(); // this node is to be replaced by the final run settings
                }
            }
            catch (InvalidRunSettingsException e)
            {
                logger.Log(MessageLevel.Error, $"Invalid run settings: {e.Message}");
            }

            GetValuesFromSolutionSettingsFile(settingsContainer, logger);

            foreach (var projectSettings in settingsContainer.ProjectSettings)
            {
                projectSettings.GetUnsetValuesFrom(settingsContainer.SolutionSettings);
            }

            GetValuesFromGlobalSettings(settingsContainer);

            runSettingsNavigator.MoveToChild(Constants.RunSettingsName, "");
            runSettingsNavigator.AppendChild(settingsContainer.ToXml().CreateNavigator());

            runSettingsNavigator.MoveToRoot();
            return(runSettingsNavigator);
        }