Пример #1
0
        private bool TryUpdateDesignMode(string runsettingsXml, out string updatedRunSettingsXml)
        {
            updatedRunSettingsXml = runsettingsXml;

            // If user is already setting DesignMode via runsettings or CLI args; we skip. We also skip if the target framework
            // is not known or current run is targeted to netcoreapp (since it is a breaking change; user may be running older
            // NET.Test.Sdk; we will remove this constraint in 15.1).
            var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);

            if (runConfiguration.DesignModeSet || !runConfiguration.TargetFrameworkSet ||
                runConfiguration.TargetFrameworkVersion.Name.IndexOf("netstandard", StringComparison.OrdinalIgnoreCase) >= 0 ||
                runConfiguration.TargetFrameworkVersion.Name.IndexOf("netcoreapp", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                return(false);
            }

            // TargetFramework is full CLR. Set DesignMode based on current context.
            using (var stream = new StringReader(runsettingsXml))
                using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings))
                {
                    var document = new XmlDocument();
                    document.Load(reader);

                    var navigator = document.CreateNavigator();
                    InferRunSettingsHelper.UpdateDesignMode(navigator, this.commandLineOptions.IsDesignMode);
                    updatedRunSettingsXml = navigator.OuterXml;
                }

            return(true);
        }
Пример #2
0
        public void UpdateDesignModeShouldModifyXmlToValueProvided(bool designModeValue)
        {
            var settings  = @"<RunSettings><RunConfiguration></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateDesignMode(navigator, designModeValue);

            Assert.AreEqual(designModeValue.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode"));
        }
Пример #3
0
        public void UpdateDesignModeShouldNotModifyXmlIfItAlreadyHasDesignModeNode()
        {
            var settings  = @"<RunSettings><RunConfiguration><DesignMode>False</DesignMode></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateDesignMode(navigator, true);

            Assert.AreEqual("False", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode"));
        }
Пример #4
0
        public void UpdateDesignModeOrCsiShouldModifyXmlToValueProvided(bool val)
        {
            var settings  = @"<RunSettings><RunConfiguration></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateDesignMode(navigator, val);
            InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, val);

            Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode"));
            Assert.AreEqual(val.ToString(), this.GetValueOf(navigator, "/RunSettings/RunConfiguration/CollectSourceInformation"));
        }
Пример #5
0
        public void UpdateDesignModeOrCsiShouldNotModifyXmlIfNodeIsAlreadyPresent()
        {
            var settings  = @"<RunSettings><RunConfiguration><DesignMode>False</DesignMode><CollectSourceInformation>False</CollectSourceInformation></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateDesignMode(navigator, true);
            InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, true);

            Assert.AreEqual("False", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/DesignMode"));
            Assert.AreEqual("False", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/CollectSourceInformation"));
        }
        private bool UpdateDesignMode(XmlDocument document, RunConfiguration runConfiguration)
        {
            // If user is already setting DesignMode via runsettings or CLI args; we skip.
            bool updateRequired = !runConfiguration.DesignModeSet;

            if (updateRequired)
            {
                InferRunSettingsHelper.UpdateDesignMode(document, this.commandLineOptions.IsDesignMode);
            }
            return(updateRequired);
        }
Пример #7
0
        public void UpdateDesignModeShouldNotModifyXmlIfNavigatorIsNotAtRootNode()
        {
            var settings  = @"<RunSettings><RunConfiguration></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            navigator.MoveToFirstChild();

            InferRunSettingsHelper.UpdateDesignMode(navigator, true);

            navigator.MoveToRoot();
            Assert.IsTrue(navigator.InnerXml.IndexOf("DesignMode", StringComparison.OrdinalIgnoreCase) < 0);
        }
Пример #8
0
        private bool UpdateRunSettingsIfRequired(string runsettingsXml, out string updatedRunSettingsXml)
        {
            bool settingsUpdated = false;

            updatedRunSettingsXml = runsettingsXml;

            if (!string.IsNullOrEmpty(runsettingsXml))
            {
                // TargetFramework is full CLR. Set DesignMode based on current context.
                using (var stream = new StringReader(runsettingsXml))
                    using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings))
                    {
                        var document = new XmlDocument();
                        document.Load(reader);

                        var navigator = document.CreateNavigator();

                        // If user is already setting DesignMode via runsettings or CLI args; we skip.
                        var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);

                        if (!runConfiguration.DesignModeSet)
                        {
                            InferRunSettingsHelper.UpdateDesignMode(navigator, this.commandLineOptions.IsDesignMode);
                            settingsUpdated = true;
                        }

                        if (!runConfiguration.CollectSourceInformationSet)
                        {
                            InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, this.commandLineOptions.ShouldCollectSourceInformation);
                            settingsUpdated = true;
                        }

                        if (InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml))
                        {
                            InferRunSettingsHelper.UpdateTargetDeviceInformation(navigator, deviceXml);
                            settingsUpdated = true;
                        }

                        updatedRunSettingsXml = navigator.OuterXml;
                    }
            }

            return(settingsUpdated);
        }
Пример #9
0
        public void UpdateRunSettingsShouldNotModifyXmlIfNavigatorIsNotAtRootNode(string settingName)
        {
            var settings  = @"<RunSettings><RunConfiguration></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            navigator.MoveToFirstChild();

            switch (settingName.ToUpperInvariant())
            {
            case "DESIGNMODE":
                InferRunSettingsHelper.UpdateDesignMode(navigator, true);
                break;

            case "COLLECTSOURCEINFORMATION":
                InferRunSettingsHelper.UpdateCollectSourceInformation(navigator, true);
                break;
            }
            ;

            navigator.MoveToRoot();
            Assert.IsTrue(navigator.InnerXml.IndexOf(settingName, StringComparison.OrdinalIgnoreCase) < 0);
        }
Пример #10
0
        private bool UpdateRunSettingsIfRequired(string runsettingsXml, List <string> sources, out string updatedRunSettingsXml)
        {
            bool settingsUpdated = false;

            updatedRunSettingsXml = runsettingsXml;
            IDictionary <string, Architecture> sourcePlatforms  = new Dictionary <string, Architecture>();
            IDictionary <string, Framework>    sourceFrameworks = new Dictionary <string, Framework>();

            if (!string.IsNullOrEmpty(runsettingsXml))
            {
                // TargetFramework is full CLR. Set DesignMode based on current context.
                using (var stream = new StringReader(runsettingsXml))
                    using (var reader = XmlReader.Create(stream, XmlRunSettingsUtilities.ReaderSettings))
                    {
                        var document = new XmlDocument();
                        document.Load(reader);

                        var navigator = document.CreateNavigator();

                        var          inferedFramework = inferHelper.AutoDetectFramework(sources, sourceFrameworks);
                        Framework    chosenFramework;
                        var          inferedPlatform = inferHelper.AutoDetectArchitecture(sources, sourcePlatforms);
                        Architecture chosenPlatform;

                        // Update frmaework and platform if required. For commandline scenario update happens in ArgumentProcessor.
                        bool updateFramework = IsAutoFrameworkDetectRequired(navigator, out chosenFramework);
                        bool updatePlatform  = IsAutoPlatformDetectRequired(navigator, out chosenPlatform);

                        if (updateFramework)
                        {
                            InferRunSettingsHelper.UpdateTargetFramework(document, inferedFramework?.ToString(), overwrite: true);
                            chosenFramework = inferedFramework;
                            settingsUpdated = true;
                        }

                        if (updatePlatform)
                        {
                            InferRunSettingsHelper.UpdateTargetPlatform(document, inferedPlatform.ToString(), overwrite: true);
                            chosenPlatform  = inferedPlatform;
                            settingsUpdated = true;
                        }

                        var compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(chosenPlatform, chosenFramework, sourcePlatforms, sourceFrameworks, out var incompatibleSettingWarning);

                        if (!string.IsNullOrEmpty(incompatibleSettingWarning))
                        {
                            EqtTrace.Info(incompatibleSettingWarning);
                            ConsoleLogger.RaiseTestRunWarning(incompatibleSettingWarning);
                        }

                        if (EqtTrace.IsInfoEnabled)
                        {
                            EqtTrace.Info("Compatible sources list : ");
                            EqtTrace.Info(string.Join("\n", compatibleSources.ToArray()));
                        }

                        // If user is already setting DesignMode via runsettings or CLI args; we skip.
                        var runConfiguration = XmlRunSettingsUtilities.GetRunConfigurationNode(runsettingsXml);

                        if (!runConfiguration.DesignModeSet)
                        {
                            InferRunSettingsHelper.UpdateDesignMode(document, this.commandLineOptions.IsDesignMode);
                            settingsUpdated = true;
                        }

                        if (!runConfiguration.CollectSourceInformationSet)
                        {
                            InferRunSettingsHelper.UpdateCollectSourceInformation(document, this.commandLineOptions.ShouldCollectSourceInformation);
                            settingsUpdated = true;
                        }

                        if (InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml))
                        {
                            InferRunSettingsHelper.UpdateTargetDevice(document, deviceXml);
                            settingsUpdated = true;
                        }

                        var designMode = runConfiguration.DesignModeSet ?
                                         runConfiguration.DesignMode :
                                         this.commandLineOptions.IsDesignMode;

                        // Add or update console logger.
                        if (!designMode)
                        {
                            AddOrUpdateConsoleLogger(document, runsettingsXml);
                            settingsUpdated = true;
                        }
                        else
                        {
                            settingsUpdated = UpdateConsoleLoggerIfExists(document, runsettingsXml) || settingsUpdated;
                        }

                        updatedRunSettingsXml = navigator.OuterXml;
                    }
            }

            return(settingsUpdated);
        }