Skip to content

Commit

Permalink
Fix DynamicData.GetData regression preventing it to work without adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jan 12, 2025
1 parent 014c00b commit f6a8f02
Show file tree
Hide file tree
Showing 39 changed files with 193 additions and 138 deletions.
13 changes: 3 additions & 10 deletions src/Adapter/MSTest.TestAdapter/PlatformServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,9 @@ internal sealed class PlatformServiceProvider : IPlatformServiceProvider
/// <summary>
/// Initializes a new instance of the <see cref="PlatformServiceProvider"/> class - a singleton.
/// </summary>
private PlatformServiceProvider() =>
#if !WINDOWS_UWP
// Set the provider that is used by DynamicDataAttribute when generating data, to allow substituting functionality
// in TestFramework without having to put all the stuff in that library.
UTF.DynamicDataProvider.Instance = SourceGeneratorToggle.UseSourceGenerator
? new SourceGeneratedDynamicDataOperations()
: new DynamicDataOperations();
#else
UTF.DynamicDataProvider.Instance = new DynamicDataOperations();
#endif
private PlatformServiceProvider()
{
}

/// <summary>
/// Gets an instance to the platform service validator for test sources.
Expand Down
9 changes: 0 additions & 9 deletions src/Adapter/MSTest.TestAdapter/Resources/Resource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,4 @@ but received {4} argument(s), with types '{5}'.</value>
<data name="GenericParameterConflict" xml:space="preserve">
<value>Found two conflicting types for generic parameter '{0}'. The conflicting types are '{1}' and '{2}'.</value>
</data>
<data name="DynamicDataSourceShouldExistAndBeValid" xml:space="preserve">
<value>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</value>
</data>
</root>
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ byl však přijat tento počet argumentů: {4} s typy {5}.</target>
<target state="translated">Byly zjištěny soubory .runsettings i .testconfig.json. Vyberte prosím jenom jeden z těchto souborů konfigurace testu.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">Dynamický zdroj dat '{0}' v typu '{1}' by měl existovat a být vlastností nebo metodou.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Časový limit '{0}' testu vypršel po {1}ms.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ aber empfing {4} Argument(e) mit den Typen „{5}“.</target>
<target state="translated">Es wurden sowohl die Dateien „.runsettings“ als auch „.testconfig.json“ erkannt. Wählen Sie nur eine dieser Testkonfigurationsdateien aus.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">Die dynamische Datenquelle '{0}' im Typ '{1}' muss vorhanden sein und eine Eigenschaft oder Methode sein.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Timeout bei test '{0}' nach {1}ms.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ pero recibió {4} argumento(s), con los tipos "{5}".</target>
<target state="translated">Se han detectado los archivos ".runsettings" y ".testconfig.json". Seleccione solo uno de estos archivos de configuración de prueba.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">El origen de datos dinámico '{0}' en el tipo '{1}' debe existir y ser una propiedad o un método.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Se agotó el tiempo de espera de la '{0}' de pruebas después de {1}ms</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ mais a reçu {4} argument(s), avec les types « {5} ».</target>
<target state="translated">Les fichiers « .runsettings » et « .testconfig.json » ont été détectés. Veuillez sélectionner un seul de ces fichiers de configuration de test.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">La source de données dynamique '{0}' dans le type '{1}' doit exister et être une propriété ou une méthode.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Délai de '{0}' de test dépassé après {1}ms</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ ma ha ricevuto {4} argomenti, con tipi "{5}".</target>
<target state="translated">Sono stati rilevati sia i file '.runsettings' sia '.testconfig.json'. Selezionare solo uno di questi file di configurazione di test.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">L'origine dati dinamica '{0}' nel tipo '{1}' deve esistere ed essere una proprietà o un metodo.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Timeout del '{0}' di test dopo {1}ms</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ but received {4} argument(s), with types '{5}'.</source>
<target state="translated">'.runsettings' ファイルと '.testconfig.json' ファイルの両方が検出されました。これらのテスト構成ファイルのいずれか 1 つだけを選択してください。</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">型 '{1}' の動的データ ソース '{0}' は、プロパティまたはメソッドである必要があります。</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">テスト '{0}' が {1}ミリ秒後にタイムアウトしました</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ but received {4} argument(s), with types '{5}'.</source>
<target state="translated">'.runsettings' 및 '.testconfig.json' 파일이 모두 검색되었습니다. 이러한 테스트 구성 파일 중 하나만 선택하세요.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">'{1}' 형식의 동적 데이터 원본 '{0}' 존재하며 속성 또는 메서드여야 합니다.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">테스트 '{0}' {1}밀리초 후에 시간 초과되었습니다.</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ ale liczba odebranych argumentów to {4} z typami „{5}”.</target>
<target state="translated">Wykryto zarówno pliki „.runsettings”, jak i „.testconfig.json”. Wybierz tylko jeden z tych plików konfiguracji testu.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">Dynamiczne źródło danych '{0}' w typie '{1}' powinno istnieć i być właściwością lub metodą.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Upłynął limit czasu '{0}' testu po {1}ms</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ mas {4} argumentos recebidos, com tipos '{5}'.</target>
<target state="translated">Ambos os arquivos '.runsettings' e '.testconfig.json' foram detectados. Selecione apenas um desses arquivos de configuração de teste.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">A fonte de dados dinâmica '{0}' no tipo '{1}' deve existir e ser uma propriedade ou um método.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Tempo '{0}' tempo limite do teste após {1}ms</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ but received {4} argument(s), with types '{5}'.</source>
<target state="translated">Обнаружены файлы ".runsettings" и ".testconfig.json". Выберите только один из этих файлов тестовой конфигурации.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">Динамический источник '{0}' в типе '{1}' должен существовать и быть свойством или методом.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Время ожидания '{0}' истекло через {1}мс</target>
Expand Down
5 changes: 0 additions & 5 deletions src/Adapter/MSTest.TestAdapter/Resources/xlf/Resource.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ ancak, '{5}' türüyle {4} argüman aldı.</target>
<target state="translated">Hem '.runsettings' hem de '.testconfig.json' dosyaları algılandı. Lütfen bu test yapılandırma dosyalarından yalnızca birini seçin.</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">Dinamik veri kaynağı '{0}' türdeki '{1}' bir özellik veya yöntem olmalıdır.</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">Test '{0}' ms sonra zaman aşımına {1}oldu</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ but received {4} argument(s), with types '{5}'.</source>
<target state="translated">检测到 ".runsettings" 和 ".testconfig.json" 文件。请仅选择其中一个测试配置文件。</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">类型 '{1}' 中的动态数据源 '{0}' 应存在,并且应为属性或方法。</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">测试 '{0}' 在 {1}毫秒后超时</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ but received {4} argument(s), with types '{5}'.</source>
<target state="translated">偵測到 '.runsettings' 和 '.testconfig.json' 檔案。請只選取其中一個測試設定檔。</target>
<note />
</trans-unit>
<trans-unit id="DynamicDataSourceShouldExistAndBeValid">
<source>The dynamic data source '{0}' in type '{1}' should exist and be a property or a method.</source>
<target state="translated">類型 '{1}' 中的動態數據源 '{0}' 應該存在,而且必須是屬性或方法。</target>
<note />
</trans-unit>
<trans-unit id="Execution_Test_Timeout">
<source>Test '{0}' timed out after {1}ms</source>
<target state="translated">測試 '{0}' 在 {1}毫秒後逾時</target>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public DynamicDataAttribute(string dynamicDataSourceName, Type dynamicDataDeclar

/// <inheritdoc />
public IEnumerable<object[]> GetData(MethodInfo methodInfo)
=> DynamicDataProvider.Instance.GetData(_dynamicDataDeclaringType, _dynamicDataSourceType, _dynamicDataSourceName, methodInfo);
=> DynamicDataOperations.GetData(_dynamicDataDeclaringType, _dynamicDataSourceType, _dynamicDataSourceName, methodInfo);

/// <inheritdoc />
public string? GetDisplayName(MethodInfo methodInfo, object?[]? data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// 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.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;

internal class DynamicDataOperations : IDynamicDataOperations
internal static class DynamicDataOperations
{
public IEnumerable<object[]> GetData(Type? _dynamicDataDeclaringType, DynamicDataSourceType _dynamicDataSourceType, string _dynamicDataSourceName, MethodInfo methodInfo)
private const BindingFlags DeclaredOnlyLookup = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;

public static IEnumerable<object[]> GetData(Type? _dynamicDataDeclaringType, DynamicDataSourceType _dynamicDataSourceType, string _dynamicDataSourceName, MethodInfo methodInfo)
{
// Check if the declaring type of test data is passed in. If not, default to test method's class type.
_dynamicDataDeclaringType ??= methodInfo.DeclaringType;
Expand All @@ -29,7 +29,7 @@ public IEnumerable<object[]> GetData(Type? _dynamicDataDeclaringType, DynamicDat
}
else
{
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, Resource.DynamicDataSourceShouldExistAndBeValid, _dynamicDataSourceName, _dynamicDataDeclaringType.FullName));
throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, FrameworkMessages.DynamicDataSourceShouldExistAndBeValid, _dynamicDataSourceName, _dynamicDataDeclaringType.FullName));
}
#pragma warning restore IDE0045 // Convert to conditional expression

Expand Down Expand Up @@ -105,15 +105,14 @@ public IEnumerable<object[]> GetData(Type? _dynamicDataDeclaringType, DynamicDat
return property.GetValue(null, null);
}

/// <inheritdoc />
public string? GetDisplayName(string? DynamicDataDisplayName, Type? DynamicDataDisplayNameDeclaringType, MethodInfo methodInfo, object?[]? data)
public static string? GetDisplayName(string? DynamicDataDisplayName, Type? DynamicDataDisplayNameDeclaringType, MethodInfo methodInfo, object?[]? data)
{
if (DynamicDataDisplayName != null)
{
Type? dynamicDisplayNameDeclaringType = DynamicDataDisplayNameDeclaringType ?? methodInfo.DeclaringType;
DebugEx.Assert(dynamicDisplayNameDeclaringType is not null, "Declaring type of test data cannot be null.");

MethodInfo method = PlatformServiceProvider.Instance.ReflectionOperations.GetDeclaredMethod(dynamicDisplayNameDeclaringType, DynamicDataDisplayName)
MethodInfo method = dynamicDisplayNameDeclaringType.GetMethod(DynamicDataDisplayName, DeclaredOnlyLookup)
?? throw new ArgumentNullException($"{DynamicDataSourceType.Method} {DynamicDataDisplayName}");
ParameterInfo[] parameters = method.GetParameters();
return parameters.Length != 2 ||
Expand Down Expand Up @@ -235,6 +234,7 @@ private static bool IsTupleOrValueTuple(Type type, out int tupleSize)
return true;
}

#if !NET462 // TODO: Add dependency on System.ValueTuple for net462?
if (genericTypeDefinition == typeof(ValueTuple<>) ||
genericTypeDefinition == typeof(ValueTuple<,>) ||
genericTypeDefinition == typeof(ValueTuple<,,>) ||
Expand All @@ -247,6 +247,7 @@ private static bool IsTupleOrValueTuple(Type type, out int tupleSize)
tupleSize = type.GetGenericArguments().Length;
return true;
}
#endif

return false;
}
Expand All @@ -258,7 +259,7 @@ private static bool IsTupleOrValueTuple(Type type, out int tupleSize)
Type? currentType = type;
while (currentType is not null)
{
PropertyInfo? property = PlatformServiceProvider.Instance.ReflectionOperations.GetDeclaredProperty(currentType, propertyName);
PropertyInfo? property = currentType.GetProperty(propertyName, DeclaredOnlyLookup);
if (property is not null)
{
return property;
Expand All @@ -276,7 +277,7 @@ private static bool IsTupleOrValueTuple(Type type, out int tupleSize)
Type? currentType = type;
while (currentType is not null)
{
MethodInfo? method = PlatformServiceProvider.Instance.ReflectionOperations.GetDeclaredMethod(currentType, methodName);
MethodInfo? method = currentType.GetMethod(methodName, DeclaredOnlyLookup);
if (method is not null)
{
return method;
Expand Down

This file was deleted.

Loading

0 comments on commit f6a8f02

Please sign in to comment.