Inheritance: TestRunSettings, IGoogleTestAdapterSettings
        private bool CopyToUnsetValues(XPathNavigator sourceNavigator, RunSettings targetRunSettings)
        {
            if (sourceNavigator.MoveToChild(GoogleTestConstants.SettingsName, ""))
            {
                RunSettings sourceRunSettings = RunSettings.LoadFromXml(sourceNavigator.ReadSubtree());
                targetRunSettings.GetUnsetValuesFrom(sourceRunSettings);

                return true;
            }

            return false;
        }
        public IXPathNavigable AddRunSettings(IXPathNavigable userRunSettingDocument,
            IRunSettingsConfigurationInfo configurationInfo, ILogger logger)
        {
            XPathNavigator userRunSettingsNavigator = userRunSettingDocument.CreateNavigator();
            Debug.Assert(userRunSettingsNavigator != null, "userRunSettingsNavigator == null!");
            if (!userRunSettingsNavigator.MoveToChild("RunSettings", ""))
            {
                logger.Log(MessageLevel.Warning, "RunSettingsDocument does not contain a RunSettings node! Canceling settings merging...");
                return userRunSettingsNavigator;
            }

            var finalRunSettings = new RunSettings();

            if (CopyToUnsetValues(userRunSettingsNavigator, finalRunSettings))
            {
                userRunSettingsNavigator.DeleteSelf(); // this node is to be replaced by the final run settings
            }

            string solutionRunSettingsFile = GetSolutionSettingsXmlFile();
            try
            {
                if (File.Exists(solutionRunSettingsFile))
                {
                    var solutionRunSettingsDocument = new XPathDocument(solutionRunSettingsFile);
                    XPathNavigator solutionRunSettingsNavigator = solutionRunSettingsDocument.CreateNavigator();
                    if (solutionRunSettingsNavigator.MoveToChild("RunSettings", ""))
                    {
                        CopyToUnsetValues(solutionRunSettingsNavigator, finalRunSettings);
                    }
                }
            }
            catch (Exception e)
            {
                logger.Log(MessageLevel.Warning,
                    $"Solution test settings file could not be parsed, check file: {solutionRunSettingsFile}");
                logger.LogException(e);
            }

            finalRunSettings.GetUnsetValuesFrom(_globalRunSettings.RunSettings);

            userRunSettingsNavigator.AppendChild(finalRunSettings.ToXml().CreateNavigator());
            userRunSettingsNavigator.MoveToRoot();

            return userRunSettingsNavigator;
        }
Esempio n. 3
0
        public void Setup()
        {
            _solutionSettings = new RunSettings
            {
                ProjectRegex = null,
                AdditionalTestExecutionParam = "solution"
            };

            _projectSettings1 = new RunSettings
            {
                ProjectRegex = ".*PerformanceTests.exe",
                AdditionalTestExecutionParam = "project1"
            };

            _projectSettings2 = new RunSettings
            {
                ProjectRegex = ".*UnitTests.exe",
                AdditionalTestExecutionParam = "project2"
            };

            _container = new RunSettingsContainer(_solutionSettings);
            _container.ProjectSettings.Add(_projectSettings1);
            _container.ProjectSettings.Add(_projectSettings2);
        }
Esempio n. 4
0
 public void Load(XmlReader reader)
 {
     Settings = RunSettings.LoadFromXml(reader);
 }
 public RunSettingsContainer(SettingsSerializationContainer serializationContainer) :  this()
 {
     _solutionSettings = serializationContainer.SolutionSettings.Settings;
     ProjectSettings.AddRange(serializationContainer.SettingsList);
 }
 private void GetValuesFromGlobalSettings(RunSettings settings)
 {
     settings.DebuggingNamedPipeId = null;
     settings.GetUnsetValuesFrom(_globalRunSettings.RunSettings);
 }
Esempio n. 7
0
 public RunSettingsContainer(RunSettings solutionSettings)
     : base(GoogleTestConstants.SettingsName)
 {
     SolutionSettings = solutionSettings ?? throw new ArgumentNullException(nameof(solutionSettings));
 }
Esempio n. 8
0
 private void GetValuesFromGlobalSettings(RunSettings settings)
 {
     settings.VisualStudioProcessId = null;
     settings.GetUnsetValuesFrom(_globalRunSettings.RunSettings);
 }
        private RunSettingsService SetupRunSettingsService(string solutionRunSettingsFile)
        {
            var globalRunSettings = new RunSettings
            {
                AdditionalTestExecutionParam = "Global",
                NrOfTestRepetitions = 1,
                MaxNrOfThreads = 1,
                TraitsRegexesBefore = "Global"
            };

            Mock<IGlobalRunSettings> mockGlobalRunSettings = new Mock<IGlobalRunSettings>();
            mockGlobalRunSettings.Setup(grs => grs.RunSettings).Returns(globalRunSettings);

            return new RunSettingsServiceUnderTest(mockGlobalRunSettings.Object, solutionRunSettingsFile);
        }
Esempio n. 10
0
        public static RunSettings LoadFromXml(XmlReader reader)
        {
            ValidateArg.NotNull(reader, nameof(reader));

            var runSettings = new RunSettings();
            if (reader.Read() && reader.Name.Equals(GoogleTestConstants.SettingsName))
            {
                try
                {
                    var serializer = new XmlSerializer(typeof(RunSettings));
                    runSettings = serializer.Deserialize(reader) as RunSettings;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }
            }

            return runSettings;
        }
        public void AddRunSettings_ComplexConfiguration_IsMergedCorrectly()
        {
            string global           = "GlobalSettings";
            string solutionSolution = "solutionSolution";
            string solutionProject1 = "solutionProject1";
            string solutionProject2 = "solutionProject2";
            string userSolution     = "userSolution";
            string userProject1     = "userProject1";
            string userProject3     = "userProject3";

            var solutionSettingsContainer = new RunSettingsContainer
            {
                SolutionSettings = new RunSettings
                {
                    ProjectRegex = null,
                    AdditionalTestExecutionParam = solutionSolution,
                    PathExtension      = solutionSolution,
                    TestDiscoveryRegex = solutionSolution,
                    TraitsRegexesAfter = solutionSolution,
                    WorkingDir         = solutionSolution,
                    MaxNrOfThreads     = 1,
                },
                ProjectSettings = new List <RunSettings>
                {
                    new RunSettings
                    {
                        ProjectRegex = "project1",
                        AdditionalTestExecutionParam = solutionProject1,
                        BatchForTestTeardown         = solutionProject1,
                        PathExtension       = solutionProject1,
                        TestDiscoveryRegex  = solutionProject1,
                        NrOfTestRepetitions = 2,
                        ShuffleTestsSeed    = 2
                    },
                    new RunSettings
                    {
                        ProjectRegex = "project2",
                        AdditionalTestExecutionParam = solutionProject2,
                        BatchForTestTeardown         = solutionProject2,
                        TestNameSeparator            = solutionProject2,
                        TraitsRegexesAfter           = solutionProject2,
                        WorkingDir          = solutionProject2,
                        NrOfTestRepetitions = 3,
                    }
                }
            };

            var userSettingsContainer = new RunSettingsContainer
            {
                SolutionSettings = new RunSettings
                {
                    ProjectRegex         = null,
                    BatchForTestSetup    = userSolution,
                    BatchForTestTeardown = userSolution,
                    TestDiscoveryRegex   = userSolution,
                    TraitsRegexesAfter   = userSolution,
                    MaxNrOfThreads       = 4,
                    ShuffleTestsSeed     = 4
                },
                ProjectSettings = new List <RunSettings>
                {
                    new RunSettings
                    {
                        ProjectRegex         = "project1",
                        BatchForTestTeardown = userProject1,
                        PathExtension        = userProject1,
                        TestNameSeparator    = userProject1,
                        WorkingDir           = userProject1,
                        MaxNrOfThreads       = 5,
                        ShuffleTestsSeed     = 5
                    },
                    new RunSettings
                    {
                        ProjectRegex = "project3",
                        AdditionalTestExecutionParam = userProject3,
                        BatchForTestTeardown         = userProject3,
                        TestDiscoveryRegex           = userProject3,
                        TestNameSeparator            = userProject3,
                        TraitsRegexesBefore          = userProject3,
                        MaxNrOfThreads = 6,
                    }
                }
            };

            var globalSettings = new RunSettings
            {
                ProjectRegex = null,
                AdditionalTestExecutionParam = global,
                BatchForTestSetup            = global,
                BatchForTestTeardown         = global,
                PathExtension       = global,
                TestDiscoveryRegex  = global,
                TestNameSeparator   = global,
                TraitsRegexesAfter  = global,
                TraitsRegexesBefore = global,
                WorkingDir          = global,
                MaxNrOfThreads      = 0,
                NrOfTestRepetitions = 0,
                ShuffleTestsSeed    = 0
            };

            var mockGlobalRunSettings = new Mock <IGlobalRunSettings>();

            mockGlobalRunSettings.Setup(grs => grs.RunSettings).Returns(globalSettings);

            var userSettingsNavigator = EmbedSettingsIntoRunSettings(userSettingsContainer);

            string          solutionSettingsFile = SerializeSettingsContainer(solutionSettingsContainer);
            IXPathNavigable navigable;

            try
            {
                var serviceUnderTest = new RunSettingsServiceUnderTest(mockGlobalRunSettings.Object, solutionSettingsFile);
                navigable = serviceUnderTest.AddRunSettings(userSettingsNavigator,
                                                            new Mock <IRunSettingsConfigurationInfo>().Object, new Mock <ILogger>().Object);
            }
            finally
            {
                File.Delete(solutionSettingsFile);
            }

            var navigator = navigable.CreateNavigator();

            navigator.MoveToChild("RunSettings", "");
            navigator.MoveToChild(GoogleTestConstants.SettingsName, "");
            var resultingContainer = RunSettingsContainer.LoadFromXml(navigator.ReadSubtree());

            resultingContainer.Should().NotBeNull();
            resultingContainer.SolutionSettings.Should().NotBeNull();
            resultingContainer.ProjectSettings.Count.Should().Be(3);

            resultingContainer.SolutionSettings.AdditionalTestExecutionParam.Should().Be(solutionSolution);
            resultingContainer.SolutionSettings.BatchForTestSetup.Should().Be(userSolution);
            resultingContainer.SolutionSettings.BatchForTestTeardown.Should().Be(userSolution);
            resultingContainer.SolutionSettings.PathExtension.Should().Be(solutionSolution);
            resultingContainer.SolutionSettings.TestDiscoveryRegex.Should().Be(userSolution);
            resultingContainer.SolutionSettings.TestNameSeparator.Should().Be(global);
            resultingContainer.SolutionSettings.TraitsRegexesAfter.Should().Be(userSolution);
            resultingContainer.SolutionSettings.TraitsRegexesBefore.Should().Be(global);
            resultingContainer.SolutionSettings.WorkingDir.Should().Be(solutionSolution);
            resultingContainer.SolutionSettings.MaxNrOfThreads.Should().Be(4);
            resultingContainer.SolutionSettings.MaxNrOfThreads.Should().Be(4);
            resultingContainer.SolutionSettings.NrOfTestRepetitions.Should().Be(0);

            var projectContainer = resultingContainer.GetSettingsForExecutable("project1");

            projectContainer.Should().NotBeNull();
            projectContainer.AdditionalTestExecutionParam.Should().Be(solutionProject1);
            projectContainer.BatchForTestSetup.Should().Be(userSolution);
            projectContainer.BatchForTestTeardown.Should().Be(userProject1);
            projectContainer.PathExtension.Should().Be(userProject1);
            projectContainer.TestDiscoveryRegex.Should().Be(userSolution);
            projectContainer.TestNameSeparator.Should().Be(userProject1);
            projectContainer.TraitsRegexesAfter.Should().Be(userSolution);
            projectContainer.TraitsRegexesBefore.Should().Be(global);
            projectContainer.WorkingDir.Should().Be(userProject1);
            projectContainer.MaxNrOfThreads.Should().Be(5);
            projectContainer.MaxNrOfThreads.Should().Be(5);
            projectContainer.NrOfTestRepetitions.Should().Be(2);

            projectContainer = resultingContainer.GetSettingsForExecutable("project2");
            projectContainer.Should().NotBeNull();
            projectContainer.AdditionalTestExecutionParam.Should().Be(solutionProject2);
            projectContainer.BatchForTestSetup.Should().Be(global);
            projectContainer.BatchForTestTeardown.Should().Be(solutionProject2);
            projectContainer.PathExtension.Should().Be(solutionSolution);
            projectContainer.TestDiscoveryRegex.Should().Be(solutionSolution);
            projectContainer.TestNameSeparator.Should().Be(solutionProject2);
            projectContainer.TraitsRegexesAfter.Should().Be(solutionProject2);
            projectContainer.TraitsRegexesBefore.Should().Be(global);
            projectContainer.WorkingDir.Should().Be(solutionProject2);
            projectContainer.MaxNrOfThreads.Should().Be(1);
            projectContainer.MaxNrOfThreads.Should().Be(1);
            projectContainer.NrOfTestRepetitions.Should().Be(3);

            projectContainer = resultingContainer.GetSettingsForExecutable("project3");
            projectContainer.Should().NotBeNull();
            projectContainer.AdditionalTestExecutionParam.Should().Be(userProject3);
            projectContainer.BatchForTestSetup.Should().Be(userSolution);
            projectContainer.BatchForTestTeardown.Should().Be(userProject3);
            projectContainer.PathExtension.Should().Be(global);
            projectContainer.TestDiscoveryRegex.Should().Be(userProject3);
            projectContainer.TestNameSeparator.Should().Be(userProject3);
            projectContainer.TraitsRegexesAfter.Should().Be(userSolution);
            projectContainer.TraitsRegexesBefore.Should().Be(userProject3);
            projectContainer.WorkingDir.Should().Be(global);
            projectContainer.MaxNrOfThreads.Should().Be(6);
            projectContainer.MaxNrOfThreads.Should().Be(6);
            projectContainer.NrOfTestRepetitions.Should().Be(0);
        }