public void LoadFromXml_UserSettings_AreLoadedCorrectly()
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.Load(TestResources.UserTestSettings);
            var navigator = xmlDocument.CreateNavigator();

            navigator.MoveToChild("RunSettings", "");
            navigator.MoveToChild(GoogleTestConstants.SettingsName, "");

            var runSettingsContainer = RunSettingsContainer.LoadFromXml(navigator.ReadSubtree());

            runSettingsContainer.Should().NotBeNull();
            runSettingsContainer.SolutionSettings.Should().NotBeNull();
            runSettingsContainer.ProjectSettings.Count.Should().Be(1);

            runSettingsContainer.SolutionSettings.MaxNrOfThreads.Should().Be(3);
            runSettingsContainer.ProjectSettings[0].MaxNrOfThreads.Should().Be(4);
            runSettingsContainer.SolutionSettings.TraitsRegexesBefore.Should().Be("User");
            runSettingsContainer.ProjectSettings[0].TraitsRegexesBefore.Should().Be("User");
        }
        private RunSettingsContainer SetupFinalRunSettingsContainer(
            string solutionSolutionWorkingDir, string solutionProject1WorkingDir, string solutionProject2WorkingDir,
            string userSolutionWorkingDir, string userProject1WorkingDir, string userProject3WorkingDir)
        {
            var globalSettings = new RunSettings {
                ProjectRegex = null, WorkingDir = GlobalWorkingDir
            };
            var mockGlobalRunSettings = new Mock <IGlobalRunSettings2>();

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

            var solutionSettingsContainer = SetupSettingsContainer(solutionSolutionWorkingDir, solutionProject1WorkingDir, solutionProject2WorkingDir, null);
            var solutionSettingsNavigator = EmbedSettingsIntoRunSettings(solutionSettingsContainer);
            var solutionSettingsFile      = SerializeSolutionSettings(solutionSettingsNavigator);

            var userSettingsContainer = SetupSettingsContainer(userSolutionWorkingDir, userProject1WorkingDir, null, userProject3WorkingDir);
            var userSettingsNavigator = EmbedSettingsIntoRunSettings(userSettingsContainer);

            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(Constants.RunSettingsName, "");
            navigator.MoveToChild(GoogleTestConstants.SettingsName, "");

            return(RunSettingsContainer.LoadFromXml(navigator));
        }
 public void Load(XmlReader reader)
 {
     SettingsContainer = RunSettingsContainer.LoadFromXml(reader);
 }
        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);
        }