コード例 #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="options">
 /// The options.
 /// </param>
 public ListFullyQualifiedTestsArgumentExecutor(
     CommandLineOptions options,
     IRunSettingsProvider runSettingsProvider,
     ITestRequestManager testRequestManager) :
     this(options, runSettingsProvider, testRequestManager, ConsoleOutput.Instance)
 {
 }
コード例 #2
0
        private void CreateOrOverwriteRunSettings(IRunSettingsProvider runSettingsProvider, string[] args)
        {
            var length = args.Length;

            for (int index = 0; index < length; index++)
            {
                var keyValuePair     = args[index];
                var indexOfSeparator = keyValuePair.IndexOf("=");
                if (indexOfSeparator <= 0 || indexOfSeparator >= keyValuePair.Length - 1)
                {
                    continue;
                }
                var key   = keyValuePair.Substring(0, indexOfSeparator).Trim();
                var value = keyValuePair.Substring(indexOfSeparator + 1);

                if (string.IsNullOrWhiteSpace(key))
                {
                    continue;
                }

                // To determine whether to infer framework and platform.
                UpdateFrameworkAndPlatform(key, value);

                runSettingsProvider.UpdateRunSettingsNode(key, value);
            }
        }
コード例 #3
0
 internal EnableBlameArgumentExecutor(IRunSettingsProvider runSettingsManager, IEnvironment environment, IFileHelper fileHelper)
 {
     this.runSettingsManager = runSettingsManager;
     this.environment        = environment;
     this.Output             = ConsoleOutput.Instance;
     this.fileHelper         = fileHelper;
 }
コード例 #4
0
        internal EnableBlameArgumentExecutor(IRunSettingsProvider runSettingsManager, TestLoggerManager loggerManager)
        {
            Contract.Requires(loggerManager != null);

            this.runSettingsManager = runSettingsManager;
            this.loggerManager      = loggerManager;
        }
コード例 #5
0
        internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings);

            if (dataCollectionRunSettings == null)
            {
                dataCollectionRunSettings = new DataCollectionRunSettings();
            }
            else
            {
                // By default, all data collectors present in run settings are enabled, if enabled attribute is not specified.
                // So explicitely disable those data collectors and enable those which are specified.
                DisableUnConfiguredDataCollectors(dataCollectionRunSettings);
            }

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);
        }
コード例 #6
0
        internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager, IFileHelper fileHelper)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings       = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings) ?? new DataCollectionRunSettings();
            var inProcDataCollectionRunSettings = XmlRunSettingsUtilities.GetInProcDataCollectionRunSettings(settings)
                                                  ?? new DataCollectionRunSettings(
                Constants.InProcDataCollectionRunSettingsName,
                Constants.InProcDataCollectorsSettingName,
                Constants.InProcDataCollectorSettingName);

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);

            if (string.Equals(argument, CoverletConstants.CoverletDataCollectorFriendlyName, StringComparison.OrdinalIgnoreCase))
            {
                // Add in-proc data collector to runsettings if coverlet code coverage is enabled
                EnableCoverletInProcDataCollector(argument, inProcDataCollectionRunSettings, runSettingsManager, fileHelper);
                runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.InProcDataCollectionRunSettingsName, inProcDataCollectionRunSettings.ToXml().InnerXml);
            }
        }
コード例 #7
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="options"> The options. </param>
 /// <param name="runSettingsManager"> The runsettings manager. </param>
 public PlatformArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
 {
     Contract.Requires(options != null);
     Contract.Requires(runSettingsManager != null);
     this.commandLineOptions = options;
     this.runSettingsManager = runSettingsManager;
 }
コード例 #8
0
        /// <summary>
        /// Matches with test run parameter node pattern and returns that match.
        /// </summary>
        /// <param name="runSettingsProvider"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static Match GetTestRunParameterNodeMatch(this IRunSettingsProvider runSettingsProvider, string node)
        {
            var   attrName  = $"(?<{AttributeNameString}>\\w+)";
            var   attrValue = $"(?<{AttributeValueString}>.+)";
            Regex regex     = new Regex($"{Constants.TestRunParametersName}.{ParameterString}\\(name\\s*=\\s*\"{attrName}\"\\s*,\\s*value\\s*=\\s*\"{attrValue}\"\\)");
            Match match     = regex.Match(node);

            return(match);
        }
コード例 #9
0
            internal TestableRunSettingsArgumentExecutor(
                CommandLineOptions commandLineOptions,
                IRunSettingsProvider runSettingsManager,
                string runSettings)
                : base(commandLineOptions, runSettingsManager)

            {
                this.runSettingsString = runSettings;
            }
コード例 #10
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="options"> The options. </param>
        /// <param name="testPlatform">The test platform</param>
        public TestAdapterPathArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager, IOutput output, IFileHelper fileHelper)
        {
            Contract.Requires(options != null);

            this.commandLineOptions = options;
            this.runSettingsManager = runSettingsManager;
            this.output             = output;
            this.fileHelper         = fileHelper;
        }
コード例 #11
0
        public static string QueryRunSettingsNode(this IRunSettingsProvider runSettingsProvider, string key)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));
            ValidateArg.NotNullOrWhiteSpace(key, nameof(key));

            var xmlDocument = runSettingsProvider.GetRunSettingXmlDocument();
            var node        = GetXmlNode(xmlDocument, key);

            return(node?.InnerText);
        }
コード例 #12
0
        public static void UpdateRunSettings(this IRunSettingsProvider runSettingsProvider, string runsettingsXml)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));
            ValidateArg.NotNullOrWhiteSpace(runsettingsXml, nameof(runsettingsXml));

            var runSettings = new RunSettings();

            runSettings.LoadSettingsXml(runsettingsXml);
            runSettingsProvider.SetActiveRunSettings(runSettings);
        }
コード例 #13
0
        public static void UpdateRunSettingsNode(this IRunSettingsProvider runSettingsProvider, string key, string data)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));
            ValidateArg.NotNullOrWhiteSpace(key, nameof(key));
            ValidateArg.NotNull(data, nameof(data));

            var xmlDocument = runSettingsProvider.GetRunSettingXmlDocument();

            RunSettingsProviderExtensions.UpdateRunSettingsXmlDocument(xmlDocument, key, data);
            runSettingsProvider.UpdateRunSettings(xmlDocument.OuterXml);
        }
コード例 #14
0
        public static void UpdateRunSettingsNodeInnerXml(this IRunSettingsProvider runSettingsProvider, string key, string xml)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));
            ValidateArg.NotNullOrWhiteSpace(key, nameof(key));
            ValidateArg.NotNull(xml, nameof(xml));

            var xmlDocument = runSettingsProvider.GetRunSettingXmlDocument();

            UpdateRunSettingsXmlDocumentInnerXml(xmlDocument, key, xml);
            runSettingsProvider.UpdateRunSettings(xmlDocument.OuterXml);
        }
コード例 #15
0
        private (XElement variables, XElement inIsolation) ParseSettingsXML(IRunSettingsProvider provider)
        {
            var document = XDocument.Parse(provider.ActiveRunSettings.SettingsXml);

            var runConfiguration = document
                                   ?.Root
                                   ?.Element("RunConfiguration");

            var variables   = runConfiguration?.Element("EnvironmentVariables");
            var inIsolation = runConfiguration?.Element("InIsolation");

            return(variables, inIsolation);
        }
コード例 #16
0
        public static void AddDefaultRunSettings(this IRunSettingsProvider runSettingsProvider)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));

            var runSettingsXml = runSettingsProvider.ActiveRunSettings?.SettingsXml;

            if (string.IsNullOrWhiteSpace(runSettingsXml))
            {
                runSettingsXml = EmptyRunSettings;
            }

            runSettingsXml = AddDefaultRunSettings(runSettingsXml);
            runSettingsProvider.UpdateRunSettings(runSettingsXml);
        }
コード例 #17
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public RunTestsArgumentExecutor(
            CommandLineOptions commandLineOptions,
            IRunSettingsProvider runSettingsProvider,
            ITestRequestManager testRequestManager,
            IOutput output)
        {
            Contract.Requires(commandLineOptions != null);

            this.commandLineOptions     = commandLineOptions;
            this.runSettingsManager     = runSettingsProvider;
            this.testRequestManager     = testRequestManager;
            this.output                 = output;
            this.testRunEventsRegistrar = new TestRunRequestEventsRegistrar(this.output);
        }
コード例 #18
0
        /// <summary>
        /// Returns coverlet code base searching coverlet.collector.dll assembly inside adaptersPaths
        /// </summary>
        private static string GetCoverletCodeBasePath(IRunSettingsProvider runSettingProvider, IFileHelper fileHelper)
        {
            foreach (string adapterPath in RunSettingsUtilities.GetTestAdaptersPaths(runSettingProvider.ActiveRunSettings.SettingsXml))
            {
                string collectorPath = Path.Combine(adapterPath, CoverletConstants.CoverletDataCollectorCodebase);
                if (fileHelper.Exists(collectorPath))
                {
                    EqtTrace.Verbose("CoverletDataCollector in-process codeBase path '{0}'", collectorPath);
                    return(collectorPath);
                }
            }

            return(null);
        }
コード例 #19
0
        private static XmlDocument GetRunSettingXmlDocument(this IRunSettingsProvider runSettingsProvider)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));

            var doc = new XmlDocument();

            if (runSettingsProvider.ActiveRunSettings != null &&
                !string.IsNullOrEmpty(runSettingsProvider.ActiveRunSettings.SettingsXml))
            {
                var settingsXml = runSettingsProvider.ActiveRunSettings.SettingsXml;

#if NET451
                using (var reader = XmlReader.Create(new StringReader(settingsXml), new XmlReaderSettings()
                {
                    XmlResolver = null, CloseInput = true, DtdProcessing = DtdProcessing.Prohibit
                }))
                {
#else
                using (
                    var reader = XmlReader.Create(new StringReader(settingsXml),
                                                  new XmlReaderSettings()
                {
                    CloseInput = true, DtdProcessing = DtdProcessing.Prohibit
                }))
                {
#endif
                    doc.Load(reader);
                }
            }
            else
            {
#if NET451
                doc = (XmlDocument)XmlRunSettingsUtilities.CreateDefaultRunSettings();
#else
                using (
                    var reader =
                        XmlReader.Create(
                            new StringReader(
                                XmlRunSettingsUtilities.CreateDefaultRunSettings().CreateNavigator().OuterXml),
                            new XmlReaderSettings()
                {
                    CloseInput = true, DtdProcessing = DtdProcessing.Prohibit
                }))
                {
                    doc.Load(reader);
                }
#endif
            }
            return(doc);
        }
コード例 #20
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        public RunSpecificTestsArgumentExecutor(
            CommandLineOptions options,
            IRunSettingsProvider runSettingsProvider,
            ITestRequestManager testRequestManager)
        {
            Contract.Requires(options != null);
            Contract.Requires(testRequestManager != null);

            this.commandLineOptions = options;
            this.testRequestManager = testRequestManager;

            this.runSettingsManager       = runSettingsProvider;
            this.output                   = ConsoleOutput.Instance;
            this.discoveryEventsRegistrar = new DiscoveryEventsRegistrar(this.discoveryRequest_OnDiscoveredTests);
        }
コード例 #21
0
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="options">
        /// The options.
        /// </param>
        internal ListTestsArgumentExecutor(
            CommandLineOptions options,
            IRunSettingsProvider runSettingsProvider,
            ITestRequestManager testRequestManager,
            IOutput output)
        {
            Contract.Requires(options != null);

            this.commandLineOptions = options;
            this.output             = output;
            this.testRequestManager = testRequestManager;

            this.runSettingsManager       = runSettingsProvider;
            this.discoveryEventsRegistrar = new DiscoveryEventsRegistrar(output);
        }
コード例 #22
0
        private bool UpdateTestRunParameterNode(IRunSettingsProvider runSettingsProvider, string node)
        {
            if (!node.Contains(Constants.TestRunParametersName))
            {
                return(false);
            }

            var match = runSettingsProvider.GetTestRunParameterNodeMatch(node);

            if (string.Compare(match.Value, node) == 0)
            {
                runSettingsProvider.UpdateTestRunParameterSettingsNode(match);
                return(true);
            }

            var exceptionMessage = string.Format(CommandLineResources.InvalidTestRunParameterArgument, node);

            throw new CommandLineException(exceptionMessage);
        }
コード例 #23
0
        /// <summary>
        /// If test run parameter exists already it will override with new value otherwise this will add new test run parameter.
        /// </summary>
        /// <param name="runSettingsProvider"></param>
        /// <param name="match"></param>
        public static void UpdateTestRunParameterSettingsNode(this IRunSettingsProvider runSettingsProvider, Match match)
        {
            ValidateArg.NotNull(runSettingsProvider, nameof(runSettingsProvider));

            var     xmlDocument          = runSettingsProvider.GetRunSettingXmlDocument();
            XmlNode testRunParameterNode = GetXmlNode(xmlDocument, Constants.TestRunParametersName) ?? xmlDocument.CreateElement(Constants.TestRunParametersName);
            var     attrName             = match.Groups[AttributeNameString].Value;
            var     attrValue            = match.Groups[AttributeValueString].Value;

            if (!TryOverrideAttributeValue(testRunParameterNode, attrName, attrValue))
            {
                XmlElement element = xmlDocument.CreateElement(ParameterString);
                element.SetAttribute(NameString, attrName);
                element.SetAttribute(ValueString, attrValue);
                testRunParameterNode.AppendChild(element);
                xmlDocument.DocumentElement.AppendChild(testRunParameterNode);
            }

            runSettingsProvider.UpdateRunSettings(xmlDocument.OuterXml);
        }
コード例 #24
0
        internal static void AddDataCollectorToRunSettings(string argument, IRunSettingsProvider runSettingsManager)
        {
            EnabledDataCollectors.Add(argument.ToLower());

            var settings = runSettingsManager.ActiveRunSettings?.SettingsXml;

            if (settings == null)
            {
                runSettingsManager.AddDefaultRunSettings();
                settings = runSettingsManager.ActiveRunSettings?.SettingsXml;
            }

            var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settings);

            if (dataCollectionRunSettings == null)
            {
                dataCollectionRunSettings = new DataCollectionRunSettings();
            }

            // Add data collectors if not already present, enable if already present.
            EnableDataCollectorUsingFriendlyName(argument, dataCollectionRunSettings);

            runSettingsManager.UpdateRunSettingsNodeInnerXml(Constants.DataCollectionRunSettingsName, dataCollectionRunSettings.ToXml().InnerXml);
        }
コード例 #25
0
 internal CollectArgumentExecutor(IRunSettingsProvider runSettingsManager)
 {
     this.runSettingsManager = runSettingsManager;
 }
コード例 #26
0
 internal EnableCodeCoverageArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsManager)
 {
     this.commandLineOptions = options;
     this.runSettingsManager = runSettingsManager;
 }
コード例 #27
0
 internal TestableTestAdapterPathArgumentExecutor(CommandLineOptions options, IRunSettingsProvider runSettingsProvider, IOutput output, IFileHelper fileHelper)
     : base(options, runSettingsProvider, output, fileHelper)
 {
 }
コード例 #28
0
 internal RunSettingsArgumentExecutor(CommandLineOptions commandLineOptions, IRunSettingsProvider runSettingsManager)
 {
     this.commandLineOptions = commandLineOptions;
     this.runSettingsManager = runSettingsManager;
     this.FileHelper         = new FileHelper();
 }
コード例 #29
0
 internal TestableEnableBlameArgumentExecutor(IRunSettingsProvider runSettingsManager, IEnvironment environment, IOutput output)
     : base(runSettingsManager, environment, new Mock <IFileHelper>().Object)
 {
     this.Output = output;
 }
コード例 #30
0
 public void Init()
 {
     this.settingsProvider = new TestableRunSettingsProvider();
 }