Exemple #1
0
        public void FilterCompatibleSourcesShouldIdentifyIncomaptiableSourcesAndConstructWarningMessage()
        {
            #region Arrange
            sourceArchitectures["AnyCPU1net46.dll"] = Architecture.AnyCPU;
            sourceArchitectures["x64net47.exe"]     = Architecture.X64;
            sourceArchitectures["x86net45.dll"]     = Architecture.X86;

            sourceFrameworks["AnyCPU1net46.dll"] = frameworkNet46;
            sourceFrameworks["x64net47.exe"]     = frameworkNet47;
            sourceFrameworks["x86net45.dll"]     = frameworkNet45;

            StringBuilder sb = new StringBuilder();
            sb.AppendLine();
            sb.AppendLine(GetSourceIncompatibleMessage("AnyCPU1net46.dll"));
            sb.AppendLine(GetSourceIncompatibleMessage("x64net47.exe"));
            sb.AppendLine(GetSourceIncompatibleMessage("x86net45.dll"));

            var expected = string.Format(CultureInfo.CurrentCulture, OMResources.DisplayChosenSettings, frameworkNet47, Constants.DefaultPlatform, sb.ToString(), @"http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409");
            #endregion

            string warningMessage    = string.Empty;
            var    compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(Constants.DefaultPlatform, frameworkNet47, sourceArchitectures, sourceFrameworks, out warningMessage);

            // None of the DLLs passed are compatible to the chosen settings
            Assert.AreEqual(0, compatibleSources.Count());
            Assert.AreEqual(expected, warningMessage);
        }
Exemple #2
0
        private void CheckSourcesForCompatibility(
            Framework chosenFramework,
            Architecture chosenPlatform,
            Architecture defaultArchitecture,
            IDictionary <string, Architecture> sourcePlatforms,
            IDictionary <string, Framework> sourceFrameworks,
            IBaseTestEventsRegistrar registrar)
        {
            // Find compatible sources.
            var compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(
                chosenPlatform,
                defaultArchitecture,
                chosenFramework,
                sourcePlatforms,
                sourceFrameworks,
                out var incompatibleSettingWarning);

            // Raise warnings for incompatible sources
            if (!string.IsNullOrEmpty(incompatibleSettingWarning))
            {
                EqtTrace.Warning(incompatibleSettingWarning);
                registrar?.LogWarning(incompatibleSettingWarning);
            }

            // Log compatible sources
            if (EqtTrace.IsInfoEnabled)
            {
                EqtTrace.Info("Compatible sources list : ");
                EqtTrace.Info(string.Join("\n", compatibleSources.ToArray()));
            }
        }
Exemple #3
0
        public void FilterCompatibleSourcesShouldRetrunWarningMessageIfNoConflict()
        {
            sourceArchitectures["x64net45.exe"] = Architecture.X64;
            sourceFrameworks["x64net45.exe"]    = frameworkNet45;

            string warningMessage    = string.Empty;
            var    compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(Architecture.X64, frameworkNet45, sourceArchitectures, sourceFrameworks, out warningMessage);

            Assert.IsTrue(string.IsNullOrEmpty(warningMessage));
        }
Exemple #4
0
        public void FilterCompatibleSourcesShouldNotComposeWarningIfSettingsAreCorrect()
        {
            sourceArchitectures["x86net45.dll"] = Architecture.X86;
            sourceFrameworks["x86net45.dll"]    = frameworkNet45;

            string warningMessage    = string.Empty;
            var    compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(Constants.DefaultPlatform, frameworkNet45, sourceArchitectures, sourceFrameworks, out warningMessage);

            // only "x86net45.dll" is the compatible source
            Assert.AreEqual(1, compatibleSources.Count());
            Assert.IsTrue(string.IsNullOrEmpty(warningMessage));
        }
Exemple #5
0
        public void FilterCompatibleSourcesShouldIdentifyCompatibleSources()
        {
            sourceArchitectures["x64net45.exe"] = Architecture.X64;
            sourceArchitectures["x86net45.dll"] = Architecture.X86;

            sourceFrameworks["x64net45.exe"] = frameworkNet45;
            sourceFrameworks["x86net45.dll"] = frameworkNet45;

            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine(GetSourceIncompatibleMessage("x64net45.exe"));

            var expected = string.Format(CultureInfo.CurrentCulture, OMResources.DisplayChosenSettings, frameworkNet45, Constants.DefaultPlatform, sb.ToString(), @"http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409");

            string warningMessage    = string.Empty;
            var    compatibleSources = InferRunSettingsHelper.FilterCompatibleSources(Constants.DefaultPlatform, frameworkNet45, sourceArchitectures, sourceFrameworks, out warningMessage);

            // only "x86net45.dll" is the compatible source
            Assert.AreEqual(1, compatibleSources.Count());
            Assert.AreEqual(expected, warningMessage);
        }
Exemple #6
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);
        }