Esempio n. 1
0
        private bool UpdateFramework(
            XmlDocument document,
            XPathNavigator navigator,
            IList <string> sources,
            IDictionary <string, Framework> sourceFrameworks,
            IBaseTestEventsRegistrar registrar,
            out Framework chosenFramework)
        {
            // Get framework from sources.
            var inferedFramework = inferHelper.AutoDetectFramework(sources, sourceFrameworks);

            // Get framework from runsettings.
            bool updateFramework = IsAutoFrameworkDetectRequired(navigator, out chosenFramework);

            // Update framework if required. For command line scenario update happens in
            // ArgumentProcessor.
            if (updateFramework)
            {
                InferRunSettingsHelper.UpdateTargetFramework(
                    document,
                    inferedFramework?.ToString(),
                    overwrite: true);
                chosenFramework = inferedFramework;
            }

            // Raise warnings for unsupported frameworks.
            if (Constants.DotNetFramework35.Equals(chosenFramework.Name))
            {
                EqtTrace.Warning("TestRequestManager.UpdateRunSettingsIfRequired: throw warning on /Framework:Framework35 option.");
                registrar.LogWarning(Resources.Framework35NotSupported);
            }

            return(updateFramework);
        }
Esempio n. 2
0
        public void UpdateTargetFrameworkShouldAddFrameworkXmlNodeIfNotPresent()
        {
            var settings  = @"<RunSettings><RunConfiguration></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateTargetFramework(navigator, ".NETCoreApp,Version=v1.0");

            Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetFrameworkVersion"));
        }
Esempio n. 3
0
        public void UpdateTargetFrameworkShouldModifyXmlIfNodeIsAlreadyPresentForOverwriteTrue()
        {
            var settings  = @"<RunSettings><RunConfiguration><TargetFrameworkVersion>.NETFramework,Version=v4.5</TargetFrameworkVersion></RunConfiguration></RunSettings>";
            var navigator = this.GetNavigator(settings);

            InferRunSettingsHelper.UpdateTargetFramework(navigator, ".NETCoreApp,Version=v1.0", overwrite: true);

            Assert.AreEqual(".NETCoreApp,Version=v1.0", this.GetValueOf(navigator, "/RunSettings/RunConfiguration/TargetFrameworkVersion"));
        }
Esempio n. 4
0
        public void UpdateTargetFrameworkShouldNotModifyXmlIfNodeIsAlreadyPresentForOverwriteFalse()
        {
            var settings    = @"<RunSettings><RunConfiguration><TargetFrameworkVersion>.NETFramework,Version=v4.5</TargetFrameworkVersion></RunConfiguration></RunSettings>";
            var xmlDocument = this.GetXmlDocument(settings);

            InferRunSettingsHelper.UpdateTargetFramework(xmlDocument, ".NETCoreApp,Version=v1.0", overwrite: false);

            Assert.AreEqual(".NETFramework,Version=v4.5", this.GetValueOf(xmlDocument, "/RunSettings/RunConfiguration/TargetFrameworkVersion"));
        }
Esempio n. 5
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);
        }