diff --git a/src/Adapter/MSTest.TestAdapter/Helpers/MSTestDiscovererHelpers.cs b/src/Adapter/MSTest.TestAdapter/Helpers/MSTestDiscovererHelpers.cs index 0c186fd0d8..7d4d8ee7b8 100644 --- a/src/Adapter/MSTest.TestAdapter/Helpers/MSTestDiscovererHelpers.cs +++ b/src/Adapter/MSTest.TestAdapter/Helpers/MSTestDiscovererHelpers.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; @@ -20,7 +21,7 @@ internal static bool AreValidSources(IEnumerable sources) PlatformServiceProvider.Instance.TestSource.ValidSourceExtensions.Any(extension => string.Equals(Path.GetExtension(source), extension, StringComparison.OrdinalIgnoreCase))); - internal static bool InitializeDiscovery(IEnumerable sources, IDiscoveryContext? discoveryContext, IMessageLogger messageLogger) + internal static bool InitializeDiscovery(IEnumerable sources, IDiscoveryContext? discoveryContext, IMessageLogger messageLogger, IConfiguration? configuration) { if (!AreValidSources(sources)) { @@ -30,7 +31,7 @@ internal static bool InitializeDiscovery(IEnumerable sources, IDiscovery // Populate the runsettings. try { - MSTestSettings.PopulateSettings(discoveryContext, messageLogger); + MSTestSettings.PopulateSettings(discoveryContext, messageLogger, configuration); } catch (AdapterSettingsException ex) { diff --git a/src/Adapter/MSTest.TestAdapter/MSTestSettings.cs b/src/Adapter/MSTest.TestAdapter/MSTestSettings.cs index 3825cd9506..e4fa784a62 100644 --- a/src/Adapter/MSTest.TestAdapter/MSTestSettings.cs +++ b/src/Adapter/MSTest.TestAdapter/MSTestSettings.cs @@ -6,7 +6,9 @@ using System.Xml; using System.Xml.Linq; +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel; +using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; @@ -253,7 +255,7 @@ public static void PopulateSettings(MSTestSettings settings) /// The discovery context that contains the runsettings. /// [Obsolete("this function will be removed in v4.0.0")] - public static void PopulateSettings(IDiscoveryContext? context) => PopulateSettings(context, null); + public static void PopulateSettings(IDiscoveryContext? context) => PopulateSettings(context, null, null); /// /// Populate adapter settings from the context. @@ -262,32 +264,49 @@ public static void PopulateSettings(MSTestSettings settings) /// The logger for messages. /// The discovery context that contains the runsettings. /// - internal static void PopulateSettings(IDiscoveryContext? context, IMessageLogger? logger) + internal static void PopulateSettings(IDiscoveryContext? context, IMessageLogger? logger, IConfiguration? configuration) { - RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context); - - if (context?.RunSettings == null || StringEx.IsNullOrEmpty(context.RunSettings.SettingsXml)) + if (configuration != null && context?.RunSettings != null) { - // This will contain default adapter settings - CurrentSettings = new MSTestSettings(); - return; + throw new InvalidOperationException(Resource.DuplicateConfigurationError); } - MSTestSettings? aliasSettings = GetSettings(context.RunSettings.SettingsXml, SettingsNameAlias, logger); - - // If a user specifies MSTestV2 in the runsettings, then prefer that over the v1 settings. - if (aliasSettings != null) + if (context?.RunSettings != null && !StringEx.IsNullOrEmpty(context.RunSettings.SettingsXml)) { - CurrentSettings = aliasSettings; + RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(context); + + MSTestSettings? aliasSettings = GetSettings(context.RunSettings.SettingsXml, SettingsNameAlias, logger); + + // If a user specifies MSTestV2 in the runsettings, then prefer that over the v1 settings. + if (aliasSettings != null) + { + CurrentSettings = aliasSettings; + } + else + { + MSTestSettings? settings = GetSettings(context.RunSettings.SettingsXml, SettingsName, logger); + + CurrentSettings = settings ?? new MSTestSettings(); + } + + SetGlobalSettings(context.RunSettings.SettingsXml, CurrentSettings, logger); + return; } - else + + if (configuration is not null) { - MSTestSettings? settings = GetSettings(context.RunSettings.SettingsXml, SettingsName, logger); + RunConfigurationSettings = RunConfigurationSettings.PopulateSettings(configuration); + + MSTestSettings? settings = GetSettingsFromConfig(configuration, logger); CurrentSettings = settings ?? new MSTestSettings(); + + return; } - SetGlobalSettings(context.RunSettings.SettingsXml, CurrentSettings, logger); + // This will contain default adapter settings + CurrentSettings = new MSTestSettings(); + return; } /// @@ -831,4 +850,162 @@ private static void SetGlobalSettings( logger?.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resource.InvalidValue, disableParallelizationString, "DisableParallelization")); } } + + private static void ParseBooleanSetting(IConfiguration configuration, string key, IMessageLogger? logger, Action setSetting) + { + if (configuration[$"mstest:{key}"] is string value) + { + if (bool.TryParse(value, out bool result)) + { + setSetting(result); + } + else + { + logger?.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resource.InvalidValue, value, key)); + } + } + } + + private static void ParseIntegerSetting(IConfiguration configuration, string key, IMessageLogger? logger, Action setSetting) + { + if (configuration[$"mstest:{key}"] is string value) + { + if (int.TryParse(value, out int result) && result > 0) + { + setSetting(result); + } + else + { + logger?.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resource.InvalidValue, value, key)); + } + } + } + + private static void ParseStringSetting(IConfiguration configuration, string key, IMessageLogger? logger, Action setSetting) + { + if (configuration[$"mstest:{key}"] is string value) + { + if (!string.IsNullOrEmpty(value)) + { + setSetting(value); + } + else + { + logger?.SendMessage(TestMessageLevel.Warning, string.Format(CultureInfo.CurrentCulture, Resource.InvalidValue, value, key)); + } + } + } + + /// + /// Convert the parameter xml to TestSettings. + /// + /// Configuration to load the settings from. + /// The logger for messages. + /// An instance of the class. + private static MSTestSettings GetSettingsFromConfig(IConfiguration configuration, IMessageLogger? logger) + { + // Expected format of the json is: - + // + // "mstest" : { + // "timeout" : { + // "assemblyInitialize" : strictly positive int, + // "assemblyCleanup" : strictly positive int, + // "classInitialize" : strictly positive int, + // "classCleanup" : strictly positive int, + // "testInitialize" : strictly positive int, + // "testCleanup" : strictly positive int, + // "test" : strictly positive int + // }, + // "parallelism" : { + // "enabled": true/false, + // "workers": positive int, + // "scope": method/class, + // }, + // ... remaining settings + // } + MSTestSettings settings = new(); + + ParseBooleanSetting(configuration, "captureTraceOutput", logger, result => settings.CaptureDebugTraces = result); + ParseBooleanSetting(configuration, "enableBaseClassTestMethodsFromOtherAssemblies", logger, result => settings.EnableBaseClassTestMethodsFromOtherAssemblies = result); + ParseBooleanSetting(configuration, "forcedLegacyMode", logger, result => settings.ForcedLegacyMode = result); + ParseBooleanSetting(configuration, "mapInconclusiveToFailed", logger, result => settings.MapInconclusiveToFailed = result); + ParseBooleanSetting(configuration, "mapNotRunnableToFailed", logger, result => settings.MapNotRunnableToFailed = result); + ParseBooleanSetting(configuration, "treatDiscoveryWarningsAsErrors", logger, result => settings.TreatDiscoveryWarningsAsErrors = result); + ParseBooleanSetting(configuration, "considerEmptyDataSourceAsInconclusive", logger, result => settings.ConsiderEmptyDataSourceAsInconclusive = result); + ParseBooleanSetting(configuration, "treatClassAndAssemblyCleanupWarningsAsErrors", logger, result => settings.TreatClassAndAssemblyCleanupWarningsAsErrors = result); + ParseBooleanSetting(configuration, "considerFixturesAsSpecialTests", logger, result => settings.ConsiderFixturesAsSpecialTests = result); + ParseBooleanSetting(configuration, "cooperativeCancellationTimeout", logger, result => settings.CooperativeCancellationTimeout = result); + ParseBooleanSetting(configuration, "orderTestsByNameInClass", logger, result => settings.OrderTestsByNameInClass = result); + ParseBooleanSetting(configuration, "parallelism:enabled", logger, result => settings.OrderTestsByNameInClass = result); + + ParseIntegerSetting(configuration, "timeout:test", logger, result => settings.TestTimeout = result); + ParseIntegerSetting(configuration, "timeout:assemblyCleanup", logger, result => settings.AssemblyCleanupTimeout = result); + ParseIntegerSetting(configuration, "timeout:assemblyInitialize", logger, result => settings.AssemblyInitializeTimeout = result); + ParseIntegerSetting(configuration, "timeout:classInitialize", logger, result => settings.ClassInitializeTimeout = result); + ParseIntegerSetting(configuration, "timeout:classCleanup", logger, result => settings.ClassCleanupTimeout = result); + ParseIntegerSetting(configuration, "timeout:testInitialize", logger, result => settings.TestInitializeTimeout = result); + ParseIntegerSetting(configuration, "timeout:testCleanup", logger, result => settings.TestCleanupTimeout = result); + + ParseStringSetting(configuration, "settingsFile", logger, fileName => settings.TestSettingsFile = fileName); + + if (configuration["mstest:classCleanupLifecycle"] is string classCleanupLifecycle) + { + if (TryParseEnum(classCleanupLifecycle, out ClassCleanupBehavior lifecycle)) + { + settings.ClassCleanupLifecycle = lifecycle; + } + else + { + throw new AdapterSettingsException(string.Format( + CultureInfo.CurrentCulture, + Resource.InvalidClassCleanupLifecycleValue, + classCleanupLifecycle, +#if NET + string.Join(", ", Enum.GetNames()))); +#else + string.Join(", ", EnumPolyfill.GetNames()))); +#endif + } + } + + if (configuration["mstest:parallelism:workers"] is string workers) + { + settings.ParallelizationWorkers = int.TryParse(workers, out int parallelWorkers) + ? parallelWorkers == 0 + ? Environment.ProcessorCount + : parallelWorkers > 0 + ? parallelWorkers + : throw new AdapterSettingsException(string.Format( + CultureInfo.CurrentCulture, + Resource.InvalidParallelWorkersValue, + workers)) + : throw new AdapterSettingsException(string.Format( + CultureInfo.CurrentCulture, + Resource.InvalidParallelWorkersValue, + workers)); + } + + if (configuration["mstest:parallelism:scope"] is string value) + { + if (TryParseEnum(value, out ExecutionScope scope)) + { + settings.ParallelizationScope = scope; + } + else + { + throw new AdapterSettingsException(string.Format( + CultureInfo.CurrentCulture, + Resource.InvalidParallelScopeValue, + value, +#if NET + string.Join(", ", Enum.GetNames()))); +#else + string.Join(", ", EnumPolyfill.GetNames()))); +#endif + } + } + + MSTestSettingsProvider.Load(configuration); + return settings; + } } diff --git a/src/Adapter/MSTest.TestAdapter/Resources/Resource.Designer.cs b/src/Adapter/MSTest.TestAdapter/Resources/Resource.Designer.cs index ffe3b8962a..2aed87f631 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/Resource.Designer.cs +++ b/src/Adapter/MSTest.TestAdapter/Resources/Resource.Designer.cs @@ -233,6 +233,15 @@ internal static string DiscoveryWarning { } } + /// + /// Looks up a localized string similar to You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file.. + /// + internal static string DuplicateConfigurationError { + get { + return ResourceManager.GetString("DuplicateConfigurationError", resourceCulture); + } + } + /// /// Looks up a localized string similar to '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>'. /// diff --git a/src/Adapter/MSTest.TestAdapter/Resources/Resource.resx b/src/Adapter/MSTest.TestAdapter/Resources/Resource.resx index b473275fb7..183b6d57d2 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/Resource.resx +++ b/src/Adapter/MSTest.TestAdapter/Resources/Resource.resx @@ -414,4 +414,7 @@ but received {4} argument(s), with types '{5}'. '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + \ No newline at end of file diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf index 9154fd57a2..e3461023a1 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf @@ -56,6 +56,11 @@ byl však přijat tento počet argumentů: {4} s typy {5}. Metoda inicializace třídy {0}.{1} byla zrušena. + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' Odkazovaný člen [DynamicData] {0}.{1} by měl vracet IEnumerable<object[]>, IEnumerable<Tuple> nebo IEnumerable<ValueTuple>. diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf index c5e039108c..0ab5c5b647 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf @@ -56,6 +56,11 @@ aber empfing {4} Argument(e) mit den Typen „{5}“. Die Initialisierungsmethode "{0}.{1}" der Klasse wurde abgebrochen + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' "[DynamicData]"-Element "{0}.{1}" muss "IEnumerable"<"object[]>", "IEnumerable<Tuple>" oder "IEnumerable<ValueTuple>" zurückgeben. diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf index 716b9e5258..18cfeab504 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf @@ -56,6 +56,11 @@ pero recibió {4} argumento(s), con los tipos "{5}". Método de inicialización de clase "{0}.{1}" se canceló + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' El miembro ''{0}.{1}'' de '[DynamicData]' al que se hace referencia debe devolver ''IEnumerable<object[]>', 'IEnumerable<Tuple>'' o ''IEnumerable<ValueTuple>'' diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf index 3a841abdfb..3a544b065b 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf @@ -56,6 +56,11 @@ mais a reçu {4} argument(s), avec les types « {5} ». La méthode d’initialisation de la classe « {0}.{1} » a été annulée + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' Le membre référencé « [DynamicData] '{0}.{1}' doit renvoyer « IEnumerable<object[]> », « IEnumerable<Tuple> » ou « IEnumerable<ValueTuple> » diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf index 9e88cfa0bb..d23f43b4b8 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf @@ -56,6 +56,11 @@ ma ha ricevuto {4} argomenti, con tipi "{5}". Il metodo di inizializzazione della classe "{0}.{1}" è stato annullato + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' '[DynamicData]' membro di riferimento '{0}.{1}' deve restituire 'IEnumerable<object[]>', 'IEnumerable<Tuple>' o 'IEnumerable<ValueTuple>' diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf index cc21c190c3..263173fb28 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf @@ -57,6 +57,11 @@ but received {4} argument(s), with types '{5}'. クラス初期化メソッド '{0}.{1}' が取り消されました + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' '[DynamicData]' の参照されるメンバー '{0}.{1}' は、'IEnumerable<object[]>'、'IEnumerable<Tuple>`、'IEnumerable<ValueTuple>' のいずれかを返す必要があります diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf index 16c32195af..4a4ebee3c9 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf @@ -56,6 +56,11 @@ but received {4} argument(s), with types '{5}'. '클래스 초기화 메서드 '{0}.{1}'이(가) 취소되었습니다. + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' '[DynamicData]'이(가) '{0} 멤버를 참조했습니다.{1}'은(는) 'IEnumerable<object[]>', 'IEnumerable<Tuple>' 또는 'IEnumerable<ValueTuple>'을 반환해야 합니다. diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf index 42a8ed8c57..e0d229c621 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf @@ -56,6 +56,11 @@ ale liczba odebranych argumentów to {4} z typami „{5}”. Anulowano metodę inicjowania klasy „{0}.{1}” + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' Przywołany element członkowski „{0}.{1}” „[DynamicData]” powinien zwrócić „IEnumerable<object[]>”, „IEnumerable<Tuple>” lub „IEnumerable<ValueTuple>” diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pt-BR.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pt-BR.xlf index d272d87daa..3e1f9c6b4d 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pt-BR.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pt-BR.xlf @@ -56,6 +56,11 @@ mas {4} argumentos recebidos, com tipos '{5}'. O método de inicialização de classe "{0}.{1}" foi cancelado + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' O membro referenciado "{0}.{1}" de "[DynamicData]" deve retornar "IEnumerable<object[]>", "IEnumerable<Tuple>" ou "IEnumerable<ValueTuple>" diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf index c49e60f795..4393ef36b8 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf @@ -56,6 +56,11 @@ but received {4} argument(s), with types '{5}'. Метод инициализации класса "{0}.{1}" отменен + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' Указанный элемент "[DynamicData]" "{0}.{1}" должен возвращать "IEnumerable<object[]>", "IEnumerable<Tuple>" или "IEnumerable<ValueTuple>" diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf index c556049da2..8afc9b5b7b 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf @@ -56,6 +56,11 @@ ancak, '{5}' türüyle {4} argüman aldı. '{0}.{1}' sınıf başlatma yöntemi iptal edildi + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' '[DynamicData]' başvurulan üyesi '{0}.{1}' şu değerleri döndürmelidir: 'IEnumerable<object[]>', 'IEnumerable<Tuple>` veya 'IEnumerable<ValueTuple>' diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hans.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hans.xlf index e0c6c07ee4..7145dfa1b2 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hans.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hans.xlf @@ -56,6 +56,11 @@ but received {4} argument(s), with types '{5}'. 已取消类初始化方法“{0}.{1}” + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' “[DynamicData]”引用的成员“{0}.{1}”应返回“IEnumerable<object[]>”、“IEnumerable<Tuple>”或“IEnumerable<ValueTuple>” diff --git a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hant.xlf b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hant.xlf index 4b21b8a7f2..7672786db8 100644 --- a/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hant.xlf +++ b/src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.zh-Hant.xlf @@ -56,6 +56,11 @@ but received {4} argument(s), with types '{5}'. 已取消類別初始化方法 '{0}.{1}' + + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + You are using both 'runsettings' and 'testconfig' files. Please use only one type of configuration file. + + '[DynamicData]' referenced member '{0}.{1}' should return 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' '[DynamicData]' 參考成員 '{0}.{1}' 應傳回 'IEnumerable<object[]>', 'IEnumerable<Tuple>` or 'IEnumerable<ValueTuple>' diff --git a/src/Adapter/MSTest.TestAdapter/RunConfigurationSettings.cs b/src/Adapter/MSTest.TestAdapter/RunConfigurationSettings.cs index a7763b8be2..1ddba16d82 100644 --- a/src/Adapter/MSTest.TestAdapter/RunConfigurationSettings.cs +++ b/src/Adapter/MSTest.TestAdapter/RunConfigurationSettings.cs @@ -4,6 +4,7 @@ using System.Diagnostics.CodeAnalysis; using System.Xml; +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestPlatform.PlatformAbstractions; @@ -53,6 +54,8 @@ public static RunConfigurationSettings PopulateSettings(IDiscoveryContext? conte return settings ?? new RunConfigurationSettings(); } + internal static RunConfigurationSettings PopulateSettings(IConfiguration configuration) => ToSettings(configuration) ?? new RunConfigurationSettings(); + /// /// Gets the configuration settings from the xml. /// @@ -100,6 +103,7 @@ private static RunConfigurationSettings ToSettings(XmlReader reader) // // // true + // STA/MTA // // RunConfigurationSettings settings = new(); @@ -155,4 +159,39 @@ private static RunConfigurationSettings ToSettings(XmlReader reader) return settings; } + + private static RunConfigurationSettings ToSettings(IConfiguration configuration) + { + // Expected format of the json is: - + // "mstest" : { + // "runConfiguration": { + // "collectSourceInformation": true, + // "executionApartmentState": "STA" + // } + // } + + // Initialize settings object + RunConfigurationSettings settings = new(); + + if (bool.TryParse(configuration["mstest:runConfiguration:collectSourceInformation"], out bool collectSourceInformation)) + { + settings.CollectSourceInformation = collectSourceInformation; + PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo( + "CollectSourceInformation value Found : {0}", collectSourceInformation); + } + + string? apartmentStateValue = configuration["mstest:runConfiguration:executionApartmentState"]; + if (!string.IsNullOrEmpty(apartmentStateValue) && + Enum.TryParse(apartmentStateValue, out PlatformApartmentState platformApartmentState)) + { + settings.ExecutionApartmentState = platformApartmentState switch + { + PlatformApartmentState.STA => ApartmentState.STA, + PlatformApartmentState.MTA => ApartmentState.MTA, + _ => throw new NotSupportedException($"Platform apartment state '{platformApartmentState}' is not supported."), + }; + } + + return settings; + } } diff --git a/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestBridgedTestFramework.cs b/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestBridgedTestFramework.cs index 08a1acc40a..01f0601435 100644 --- a/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestBridgedTestFramework.cs +++ b/src/Adapter/MSTest.TestAdapter/TestingPlatformAdapter/MSTestBridgedTestFramework.cs @@ -8,17 +8,24 @@ using Microsoft.Testing.Extensions.VSTestBridge; using Microsoft.Testing.Extensions.VSTestBridge.Requests; using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Configurations; using Microsoft.Testing.Platform.Messages; +using Microsoft.Testing.Platform.Services; using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter; namespace Microsoft.VisualStudio.TestTools.UnitTesting; internal sealed class MSTestBridgedTestFramework : SynchronizedSingleSessionVSTestBridgedTestFramework { + private readonly IConfiguration? _configration; + public MSTestBridgedTestFramework(MSTestExtension mstestExtension, Func> getTestAssemblies, IServiceProvider serviceProvider, ITestFrameworkCapabilities capabilities) : base(mstestExtension, getTestAssemblies, serviceProvider, capabilities) { + // check if it have mstest settings + IConfiguration config = serviceProvider.GetConfiguration(); + _configration = config["mstest"] is null ? null : config; } /// @@ -31,7 +38,7 @@ protected override Task SynchronizedDiscoverTestsAsync(VSTestDiscoverTestExecuti Debugger.Launch(); } - new MSTestDiscoverer().DiscoverTests(request.AssemblyPaths, request.DiscoveryContext, request.MessageLogger, request.DiscoverySink); + MSTestDiscoverer.DiscoverTests(request.AssemblyPaths, request.DiscoveryContext, request.MessageLogger, request.DiscoverySink, _configration); return Task.CompletedTask; } @@ -49,11 +56,11 @@ protected override Task SynchronizedRunTestsAsync(VSTestRunTestExecutionRequest if (request.VSTestFilter.TestCases is { } testCases) { - testExecutor.RunTests(testCases, request.RunContext, request.FrameworkHandle); + testExecutor.RunTests(testCases, request.RunContext, request.FrameworkHandle, _configration); } else { - testExecutor.RunTests(request.AssemblyPaths, request.RunContext, request.FrameworkHandle); + testExecutor.RunTests(request.AssemblyPaths, request.RunContext, request.FrameworkHandle, _configration); } return Task.CompletedTask; diff --git a/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestDiscoverer.cs b/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestDiscoverer.cs index 1a0cee9c04..061beb1f1e 100644 --- a/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestDiscoverer.cs +++ b/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestDiscoverer.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; @@ -26,13 +27,15 @@ public class MSTestDiscoverer : ITestDiscoverer /// Used to send testcases and discovery related events back to Discoverer manager. [System.Security.SecurityCritical] [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", MessageId = "0", Justification = "Discovery context can be null.")] - public void DiscoverTests(IEnumerable sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) + public void DiscoverTests(IEnumerable sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) => MSTestDiscoverer.DiscoverTests(sources, discoveryContext, logger, discoverySink, null); + + internal static void DiscoverTests(IEnumerable sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration) { ValidateArg.NotNull(sources, "sources"); ValidateArg.NotNull(logger, "logger"); ValidateArg.NotNull(discoverySink, "discoverySink"); - if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger)) + if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger, configuration)) { new UnitTestDiscoverer().DiscoverTests(sources, logger, discoverySink, discoveryContext); } diff --git a/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs b/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs index 725b74d1ae..abce9402ed 100644 --- a/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs +++ b/src/Adapter/MSTest.TestAdapter/VSTestAdapter/MSTestExecutor.cs @@ -3,6 +3,7 @@ using System.Runtime.InteropServices; +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; @@ -43,13 +44,17 @@ internal MSTestExecutor(CancellationToken cancellationToken) /// public TestExecutionManager TestExecutionManager { get; protected set; } - public void RunTests(IEnumerable? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle) + public void RunTests(IEnumerable? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle) => RunTests(tests, runContext, frameworkHandle, null); + + public void RunTests(IEnumerable? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle) => RunTests(sources, runContext, frameworkHandle, null); + + internal void RunTests(IEnumerable? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration) { PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases."); ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); ValidateArg.NotNullOrEmpty(tests, "tests"); - if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle)) + if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle, configuration)) { return; } @@ -57,13 +62,12 @@ public void RunTests(IEnumerable? tests, IRunContext? runContext, IFra RunTestsFromRightContext(frameworkHandle, testRunToken => TestExecutionManager.RunTests(tests, runContext, frameworkHandle, testRunToken)); } - public void RunTests(IEnumerable? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle) + internal void RunTests(IEnumerable? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration) { PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources."); ValidateArg.NotNull(frameworkHandle, "frameworkHandle"); ValidateArg.NotNullOrEmpty(sources, "sources"); - - if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle)) + if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle, configuration)) { return; } diff --git a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj index af1301711d..bdeecf4929 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj +++ b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj @@ -31,6 +31,7 @@ + diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.Designer.cs b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.Designer.cs index 9eafefb7ac..33f4d030e6 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.Designer.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.Designer.cs @@ -10,9 +10,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { using System; - using System.Reflection; - - + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -24,15 +23,15 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resource { - + private static global::System.Resources.ResourceManager resourceMan; - + private static global::System.Globalization.CultureInfo resourceCulture; - + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resource() { } - + /// /// Returns the cached ResourceManager instance used by this class. /// @@ -47,7 +46,7 @@ internal Resource() { return resourceMan; } } - + /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. @@ -61,7 +60,7 @@ internal Resource() { resourceCulture = value; } } - + /// /// Looks up a localized string similar to Could not find file '{0}'.. /// @@ -70,7 +69,7 @@ internal static string CannotFindFile { return ResourceManager.GetString("CannotFindFile", resourceCulture); } } - + /// /// Looks up a localized string similar to The parameter should not be null or empty.. /// @@ -79,7 +78,7 @@ internal static string Common_CannotBeNullOrEmpty { return ResourceManager.GetString("Common_CannotBeNullOrEmpty", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Bad deployment item: '{0}': output directory '{1}' specifies the item to be deployed outside deployment root directory which is not allowed.. /// @@ -88,7 +87,7 @@ internal static string DeploymentErrorBadDeploymentItem { return ResourceManager.GetString("DeploymentErrorBadDeploymentItem", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Failed to access output directory '{1}' specified by deployment item '{0}', the item will not be deployed: {2}: {3}. /// @@ -97,7 +96,7 @@ internal static string DeploymentErrorFailedToAccesOutputDirectory { return ResourceManager.GetString("DeploymentErrorFailedToAccesOutputDirectory", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Failed to access the file '{0}': {1}: {2}. /// @@ -106,7 +105,7 @@ internal static string DeploymentErrorFailedToAccessFile { return ResourceManager.GetString("DeploymentErrorFailedToAccessFile", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Failed to copy file '{0}' to '{1}': {2}: {3}. /// @@ -115,7 +114,7 @@ internal static string DeploymentErrorFailedToCopyWithOverwrite { return ResourceManager.GetString("DeploymentErrorFailedToCopyWithOverwrite", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Failed to deploy dependencies for test storage '{0}': {1}. /// @@ -124,7 +123,7 @@ internal static string DeploymentErrorFailedToDeployDependencies { return ResourceManager.GetString("DeploymentErrorFailedToDeployDependencies", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: Failed to get the file for {0}: {1}: {2}. /// @@ -133,7 +132,7 @@ internal static string DeploymentErrorFailedToGetFileForDeploymentItem { return ResourceManager.GetString("DeploymentErrorFailedToGetFileForDeploymentItem", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: an error occurred while getting satellite assemblies for {0}: {1}: {2}. /// @@ -142,7 +141,7 @@ internal static string DeploymentErrorGettingSatellite { return ResourceManager.GetString("DeploymentErrorGettingSatellite", resourceCulture); } } - + /// /// Looks up a localized string similar to deployment item '{0}'. /// @@ -151,7 +150,7 @@ internal static string DeploymentItem { return ResourceManager.GetString("DeploymentItem", resourceCulture); } } - + /// /// Looks up a localized string similar to Invalid deployment item: the specified path '{0}' or output directory '{1}' contains illegal characters.. /// @@ -160,7 +159,7 @@ internal static string DeploymentItemContainsInvalidCharacters { return ResourceManager.GetString("DeploymentItemContainsInvalidCharacters", resourceCulture); } } - + /// /// Looks up a localized string similar to Invalid deployment item: the output directory cannot be null.. /// @@ -169,7 +168,7 @@ internal static string DeploymentItemOutputDirectoryCannotBeNull { return ResourceManager.GetString("DeploymentItemOutputDirectoryCannotBeNull", resourceCulture); } } - + /// /// Looks up a localized string similar to Invalid deployment item: the specified output directory '{0}' is not relative.. /// @@ -178,7 +177,7 @@ internal static string DeploymentItemOutputDirectoryMustBeRelative { return ResourceManager.GetString("DeploymentItemOutputDirectoryMustBeRelative", resourceCulture); } } - + /// /// Looks up a localized string similar to Invalid deployment item: the path must contain at least one character.. /// @@ -187,7 +186,7 @@ internal static string DeploymentItemPathCannotBeNullOrEmpty { return ResourceManager.GetString("DeploymentItemPathCannotBeNullOrEmpty", resourceCulture); } } - + /// /// Looks up a localized string similar to deployment item '{0}' (output directory '{1}'). /// @@ -196,7 +195,7 @@ internal static string DeploymentItemWithOutputDirectory { return ResourceManager.GetString("DeploymentItemWithOutputDirectory", resourceCulture); } } - + /// /// Looks up a localized string similar to MSTestAdapter encountered an unexpected element '{0}' in its settings '{1}'. Remove this element and try again.. /// @@ -205,7 +204,16 @@ internal static string InvalidSettingsXmlElement { return ResourceManager.GetString("InvalidSettingsXmlElement", resourceCulture); } } - + + /// + /// Looks up a localized string similar to Invalid value '{0}' for runsettings entry '{1}', setting will be ignored.. + /// + internal static string InvalidValue { + get { + return ResourceManager.GetString("InvalidValue", resourceCulture); + } + } + /// /// Looks up a localized string similar to Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1}. /// @@ -214,7 +222,7 @@ internal static string MissingDeploymentDependency { return ResourceManager.GetString("MissingDeploymentDependency", resourceCulture); } } - + /// /// Looks up a localized string similar to Test Run deployment issue: The assembly or module '{0}' was not found.. /// @@ -223,7 +231,7 @@ internal static string MissingDeploymentDependencyWithoutReason { return ResourceManager.GetString("MissingDeploymentDependencyWithoutReason", resourceCulture); } } - + /// /// Looks up a localized string similar to {0}_{1} {2}. /// @@ -232,7 +240,7 @@ internal static string TestRunName { return ResourceManager.GetString("TestRunName", resourceCulture); } } - + /// /// Looks up a localized string similar to Data source '{0}' cannot be found in the test configuration settings. /// @@ -241,7 +249,7 @@ internal static string UTA_DataSourceConfigurationSectionMissing { return ResourceManager.GetString("UTA_DataSourceConfigurationSectionMissing", resourceCulture); } } - + /// /// Looks up a localized string similar to The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library. Error details: {0}. /// @@ -250,7 +258,7 @@ internal static string UTA_ErrorDataConnectionFailed { return ResourceManager.GetString("UTA_ErrorDataConnectionFailed", resourceCulture); } } - + /// /// Looks up a localized string similar to Wrong number of objects for permutation. Should be greater than zero.. /// diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx index 8e4dc527f7..414073c307 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx @@ -183,4 +183,7 @@ Wrong number of objects for permutation. Should be greater than zero. - + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + \ No newline at end of file diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf index 855b8928dd..38e606d80d 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf @@ -82,6 +82,11 @@ Nástroj MSTestAdapter zjistil neočekávaný prvek {0} v nastavení {1}. Odeberte tento prvek a zkuste to znovu. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problém nasazení testovacího běhu: Sestavení nebo modul {0} se nenašly. Důvod: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf index ec55c904df..9fffbd5a04 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf @@ -82,6 +82,11 @@ "MSTestAdapter" hat ein unerwartetes Element "{0}" in den Einstellungen "{1}" ermittelt. Entfernen Sie dieses Element, und versuchen Sie es erneut. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problem bei der Testlaufbereitstellung: Die Assembly oder das Modul "{0}" wurde nicht gefunden. Ursache: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf index e55ca74a52..96576cc1d9 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf @@ -82,6 +82,11 @@ MSTestAdapter encontró un elemento inesperado '{0}' en su configuración '{1}'. Quite este elemento e inténtelo de nuevo. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problema de implementación en la serie de pruebas: no se encontró el ensamblado o el módulo '{0}'. Motivo: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf index 57fe2887b0..e0ed64fc5f 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf @@ -82,6 +82,11 @@ MSTestAdapter a rencontré un élément inattendu '{0}' dans ses paramètres '{1}'. Supprimez cet élément, puis réessayez. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problème de déploiement de la série de tests : l'assembly ou le module '{0}' est introuvable. Raison : {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf index 39b053aa6e..767a950fb6 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf @@ -82,6 +82,11 @@ MSTestAdapter ha rilevato un elemento imprevisto '{0}' nelle impostazioni '{1}'. Rimuovere l'elemento e riprovare. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problema di distribuzione dell'esecuzione dei test: l'assembly o il modulo '{0}' non è stato trovato. Motivo: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf index 66ab2d4c70..a2a49b52e0 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf @@ -82,6 +82,11 @@ MSTestAdapter で設定 '{1}' に予期しない要素 '{0}' が見つかりました。この要素を削除して、もう一度お試しください。 + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} テストの実行の配置問題です: アセンブリまたはモジュール '{0}' が見つかりませんでした。理由: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf index f178d5dabd..da14d8fecb 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf @@ -82,6 +82,11 @@ MSTestAdapter의 '{1}' 설정에서 예기치 않은 요소 '{0}'이(가) 발견되었습니다. 이 요소를 제거하고 다시 시도하세요. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} 테스트 실행 배포 문제: 어셈블리 또는 모듈 '{0}'을(를) 찾을 수 없습니다. 이유: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf index e6bf15ea4f..3d8a187bef 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf @@ -82,6 +82,11 @@ Adapter MSTestAdapter napotkał nieoczekiwany element „{0}” w ustawieniach „{1}”. Usuń ten element i spróbuj ponownie. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problem wdrażania przebiegu testu: nie znaleziono zestawu lub modułu „{0}”. Przyczyna: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf index 08128e31f9..e7a8e1dc40 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf @@ -82,6 +82,11 @@ MSTestAdapter encontrou um elemento inesperado '{0}' em suas configurações '{1}'. Remova este elemento e tente novamente. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Problema de implantação de Execução de Teste: o assembly ou módulo '{0}' não foi encontrado. Motivo: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf index 45aa6f359d..882b8698da 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf @@ -82,6 +82,11 @@ MSTestAdapter обнаружил непредвиденный элемент "{0}" в параметрах "{1}". Удалите этот элемент и повторите попытку. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Ошибка развертывания тестового запуска: не удалось найти сборку или модуль "{0}". Причина: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf index a52a766599..0ff60e4faa 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf @@ -82,6 +82,11 @@ MSTestAdapter, '{1}' ayarlarında beklenmedik bir öğeyle ('{0}') karşılaştı. Bu öğeyi kaldırıp yeniden deneyin. + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} Test Çalıştırması dağıtım sorunu: '{0}' adlı bütünleştirilmiş kod veya modül bulunamadı. Nedeni: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf index 2cdb3e60e3..5e702854c9 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf @@ -82,6 +82,11 @@ MSTestAdapter 在其设置“{1}”中遇到意外的元素“{0}”。删除此元素,然后再试一次。 + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} 测试运行部署问题: 找不到程序集或模块“{0}”。原因: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf index ccb057a8ac..8005d4a38e 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf @@ -82,6 +82,11 @@ MSTestAdapter 在其設定 '{1}' 中遇到未預期的項目 '{0}'。請移除此項目,然後再試一次。 + + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + Invalid value '{0}' for runsettings entry '{1}', setting will be ignored. + + Test Run deployment issue: The assembly or module '{0}' was not found. Reason: {1} 測試回合部署問題: 找不到組件或模組 '{0}'。原因: {1} diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/MSTestAdapterSettings.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/MSTestAdapterSettings.cs index 4c76e1262f..bd46b97a83 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/MSTestAdapterSettings.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/MSTestAdapterSettings.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Xml; +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -126,6 +127,40 @@ public static MSTestAdapterSettings ToSettings(XmlReader reader) return settings; } + private static void ParseBooleanSetting(IConfiguration configuration, string key, Action setSetting) + { + if (configuration[$"mstest:{key}"] is string value) + { + if (bool.TryParse(value, out bool result)) + { + setSetting(result); + } + } + } + + internal static MSTestAdapterSettings ToSettings(IConfiguration configuration) + { + // Expected format of the json is: - + // + // "mstest" : { + // "deployment" : { + // "enabled": true / false, + // "deployTestSourceDependencies": true / false, + // "deleteDeploymentDirectoryAfterTestRunIsComplete": true / false + // }, + // ... remaining settings + // } + MSTestAdapterSettings settings = new(); + + ParseBooleanSetting(configuration, "deployment:enabled", result => settings.DeploymentEnabled = result); + ParseBooleanSetting(configuration, "deployment:deployTestSourceDependencies", result => settings.DeployTestSourceDependencies = result); + ParseBooleanSetting(configuration, "deployment:deleteDeploymentDirectoryAfterTestRunIsComplete", result => settings.DeleteDeploymentDirectoryAfterTestRunIsComplete = result); + + settings.ReadAssemblyResolutionPath(configuration); + + return settings; + } + public static bool IsAppDomainCreationDisabled(string? settingsXml) { if (StringEx.IsNullOrEmpty(settingsXml)) @@ -304,5 +339,32 @@ private void ReadAssemblyResolutionPath(XmlReader reader) // go to the end of the element. reader.ReadEndElement(); } + + private void ReadAssemblyResolutionPath(IConfiguration configuration) + { + // Expected format of the json is: - + // + // "mstest" : { + // "assemblyResolution" : [ + // { "path" : "..." , includeSub: "true" } , + // { "path" : "..." , includeSub: "true" } , + // { "path" : "..." , includeSub: "true" } , + // ... + // ] + // ... remaining settings + // } + int indx = 0; + while (configuration[$"mstest:assemblyResolution:{indx}:path"] is string path) + { + if (!StringEx.IsNullOrEmpty(path)) + { + // Default includeSubDirectories to false if not provided + bool includeSubDirectories = false; + ParseBooleanSetting(configuration, $"mstest:assemblyResolution:{indx}:includeSubDirectories", result => includeSubDirectories = result); + + SearchDirectories.Add(new RecursiveDirectoryPath(path, includeSubDirectories)); + } + } + } } #endif diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/SettingsProvider.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/SettingsProvider.cs index fde9c76fce..b652f220d7 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/SettingsProvider.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/SettingsProvider.cs @@ -3,6 +3,7 @@ using System.Xml; +using Microsoft.Testing.Platform.Configurations; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; #if !WINDOWS_UWP using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -40,6 +41,15 @@ public static MSTestAdapterSettings Settings public static void Reset() => s_settings = null; #endif + internal static void Load(IConfiguration configuration) + { +#if !WINDOWS_UWP +#pragma warning disable IDE0022 // Use expression body for method + s_settings = MSTestAdapterSettings.ToSettings(configuration); +#pragma warning restore IDE0022 // Use expression body for method +#endif + } + /// /// Load the settings from the reader. /// diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Discovery/TypeEnumeratorTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Discovery/TypeEnumeratorTests.cs index 748fd4b542..e3706ea127 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/Discovery/TypeEnumeratorTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/Discovery/TypeEnumeratorTests.cs @@ -117,7 +117,7 @@ public void GetTestsShouldReturnBaseTestMethodsFromAnotherAssemblyByDefault() mockRunContext.Setup(dc => dc.RunSettings).Returns(mockRunSettings.Object); mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingsXml); - MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object, null); SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: false); TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName); @@ -148,7 +148,7 @@ public void GetTestsShouldReturnBaseTestMethodsFromAnotherAssemblyByConfiguratio mockRunContext.Setup(dc => dc.RunSettings).Returns(mockRunSettings.Object); mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingsXml); - MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object, null); SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true); TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName); @@ -179,7 +179,7 @@ public void GetTestsShouldNotReturnBaseTestMethodsFromAnotherAssemblyByConfigura mockRunContext.Setup(dc => dc.RunSettings).Returns(mockRunSettings.Object); mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingsXml); - MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(mockRunContext.Object, _mockMessageLogger.Object, null); SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: false); TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyDerivedTestClass), Assembly.GetExecutingAssembly().FullName); diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Discovery/UnitTestDiscovererTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Discovery/UnitTestDiscovererTests.cs index d79cd17d8c..2941a271e0 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/Discovery/UnitTestDiscovererTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/Discovery/UnitTestDiscovererTests.cs @@ -114,7 +114,7 @@ public void DiscoverTestsInSourceShouldSendBackHandleTreatAsError() _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(settingsXml); // Act - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); _unitTestDiscoverer.DiscoverTestsInSource(Source, _mockMessageLogger.Object, _mockTestCaseDiscoverySink.Object, _mockDiscoveryContext.Object); @@ -196,7 +196,7 @@ public void SendTestCasesShouldSendTestCasesWithoutNavigationDataWhenCollectSour _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(settingsXml); // Act - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); _unitTestDiscoverer.SendTestCases(Source, _testElements, _mockTestCaseDiscoverySink.Object, _mockDiscoveryContext.Object, _mockMessageLogger.Object); // Assert diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestExecutionManagerTests.cs index 6ac5d92037..393624ce0c 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestExecutionManagerTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/TestExecutionManagerTests.cs @@ -460,7 +460,7 @@ public void RunTestsForTestShouldRunTestsInParallelWhenEnabledInRunsettings() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); _testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, new TestRunCancellationToken()); Verify(DummyTestClassForParallelize.ThreadIds.Count == 1); @@ -497,7 +497,7 @@ public void RunTestsForTestShouldRunTestsByMethodLevelWhenSpecified() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); _testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, new TestRunCancellationToken()); Verify(_enqueuedParallelTestsCount == 2); @@ -534,7 +534,7 @@ public void RunTestsForTestShouldRunTestsWithSpecifiedNumberOfWorkers() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); _testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, new TestRunCancellationToken()); Verify(DummyTestClassForParallelize.ThreadIds.Count == 1); @@ -569,7 +569,7 @@ public void RunTestsForTestShouldNotRunTestsInParallelWhenDisabledFromRunsetting try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); TestablePlatformServiceProvider testablePlatformService = SetupTestablePlatformService(); testablePlatformService.SetupMockReflectionOperations(); @@ -625,7 +625,7 @@ public void RunTestsForTestShouldNotRunTestsInParallelWhenDisabledFromSource() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); TestablePlatformServiceProvider testablePlatformService = SetupTestablePlatformService(); testablePlatformService.SetupMockReflectionOperations(); @@ -689,7 +689,7 @@ public void RunTestsForTestShouldRunNonParallelizableTestsSeparately() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); _testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, new TestRunCancellationToken()); Verify(_enqueuedParallelTestsCount == 2); @@ -723,7 +723,7 @@ public void RunTestsForTestShouldPreferParallelSettingsFromRunSettingsOverAssemb try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); TestablePlatformServiceProvider testablePlatformService = SetupTestablePlatformService(); testablePlatformService.SetupMockReflectionOperations(); @@ -792,7 +792,7 @@ private void RunTestsForTestShouldRunTestsInTheParentDomainsApartmentState() try { - MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_runContext, _mockMessageLogger.Object, null); _testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, new TestRunCancellationToken()); Verify(DummyTestClassWithDoNotParallelizeMethods.ThreadApartmentStates.Count == 1); diff --git a/test/UnitTests/MSTestAdapter.UnitTests/MSTestSettingsTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/MSTestSettingsTests.cs index 1916738314..b0fa3733a4 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/MSTestSettingsTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/MSTestSettingsTests.cs @@ -635,7 +635,7 @@ public void DisableParallelizationShouldBeFalseByDefault() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(!MSTestSettings.CurrentSettings.DisableParallelization); _mockMessageLogger.Verify(lm => lm.SendMessage(TestMessageLevel.Warning, It.IsAny()), Times.Never); @@ -654,7 +654,7 @@ public void DisableParallelizationShouldBeConsumedFromRunSettingsWhenSpecified() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(MSTestSettings.CurrentSettings.DisableParallelization); } @@ -672,7 +672,7 @@ public void DisableParallelization_WithInvalidValue_GettingAWarning() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); _mockMessageLogger.Verify(lm => lm.SendMessage(TestMessageLevel.Warning, "Invalid value '3' for runsettings entry 'DisableParallelization', setting will be ignored."), Times.Once); } @@ -988,7 +988,7 @@ public void CurrentSettingShouldReturnCachedLoadedSettings() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; MSTestSettings adapterSettings2 = MSTestSettings.CurrentSettings; @@ -1035,7 +1035,7 @@ public void PopulateSettingsShouldFillInSettingsFromSettingsObject() public void PopulateSettingsShouldInitializeDefaultAdapterSettingsWhenDiscoveryContextIsNull() { - MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; Verify(adapterSettings.CaptureDebugTraces); @@ -1047,7 +1047,7 @@ public void PopulateSettingsShouldInitializeDefaultAdapterSettingsWhenDiscoveryC public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsIsNull() { - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; Verify(adapterSettings.CaptureDebugTraces); @@ -1060,7 +1060,7 @@ public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsIsNull public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsXmlIsEmpty() { _mockDiscoveryContext.Setup(md => md.RunSettings.SettingsXml).Returns(string.Empty); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; Verify(adapterSettings.CaptureDebugTraces); @@ -1083,7 +1083,7 @@ public void PopulateSettingsShouldInitializeSettingsToDefaultIfNotSpecified() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; @@ -1110,7 +1110,7 @@ public void PopulateSettingsShouldInitializeSettingsFromMSTestSection() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; @@ -1140,7 +1140,7 @@ public void PopulateSettingsShouldInitializeSettingsFromMSTestV2Section() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; @@ -1173,7 +1173,7 @@ public void PopulateSettingsShouldInitializeSettingsFromMSTestV2OverMSTestV1Sect _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); MSTestSettings adapterSettings = MSTestSettings.CurrentSettings; @@ -1193,7 +1193,7 @@ public void PopulateSettingsShouldInitializeSettingsFromMSTestV2OverMSTestV1Sect public void IsLegacyScenarioReturnsFalseWhenDiscoveryContextIsNull() { - MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object, null); Verify(!MSTestSettings.IsLegacyScenario(null)); } @@ -1210,7 +1210,7 @@ public void IsLegacyScenarioReturnsFalseWhenForcedLegacyModeIsSetToFalse() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(!MSTestSettings.IsLegacyScenario(_mockMessageLogger.Object)); } @@ -1226,7 +1226,7 @@ public void IsLegacyScenarioReturnsFalseWhenForcedLegacyModeIsSetToTrue() """; _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(!MSTestSettings.IsLegacyScenario(_mockMessageLogger.Object)); } @@ -1242,7 +1242,7 @@ public void IsLegacyScenarioReturnsTrueWhenTestSettingsFileIsGiven() """; _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(MSTestSettings.IsLegacyScenario(_mockMessageLogger.Object)); } @@ -1258,7 +1258,7 @@ public void LegacyScenariosNotSupportedWarningIsPrintedWhenVsmdiFileIsGiven() """; _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); Verify(MSTestSettings.IsLegacyScenario(_mockMessageLogger.Object)); _mockMessageLogger.Verify(logger => logger.SendMessage(TestMessageLevel.Warning, Resource.LegacyScenariosNotSupportedWarning), Times.Once); } diff --git a/test/UnitTests/MSTestAdapter.UnitTests/RunConfigurationSettingsTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/RunConfigurationSettingsTests.cs index 35237c3606..3b3592cf12 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/RunConfigurationSettingsTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/RunConfigurationSettingsTests.cs @@ -91,7 +91,7 @@ public void ConfigurationSettingsShouldReturnDefaultSettingsIfNotSet() public void PopulateSettingsShouldInitializeDefaultConfigurationSettingsWhenDiscoveryContextIsNull() { - MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(null, _mockMessageLogger.Object, null); RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings; Verify(settings.CollectSourceInformation); @@ -99,7 +99,7 @@ public void PopulateSettingsShouldInitializeDefaultConfigurationSettingsWhenDisc public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsIsNull() { - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings; Verify(settings.CollectSourceInformation); @@ -108,7 +108,7 @@ public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsIsNull public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsXmlIsEmpty() { _mockDiscoveryContext.Setup(md => md.RunSettings.SettingsXml).Returns(string.Empty); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings; Verify(settings.CollectSourceInformation); @@ -127,7 +127,7 @@ public void PopulateSettingsShouldInitializeSettingsToDefaultIfNotSpecified() _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings; Verify(settings is not null); @@ -150,7 +150,7 @@ public void PopulateSettingsShouldInitializeSettingsFromRunConfigurationSection( _mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(_mockRunSettings.Object); _mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml); - MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object); + MSTestSettings.PopulateSettings(_mockDiscoveryContext.Object, _mockMessageLogger.Object, null); RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings; Verify(settings is not null);