diff --git a/src/TestFramework/MSTest.Core/Attributes/DynamicDataAttribute.cs b/src/TestFramework/MSTest.Core/Attributes/DynamicDataAttribute.cs
index 881926d7aa..3970fd8728 100644
--- a/src/TestFramework/MSTest.Core/Attributes/DynamicDataAttribute.cs
+++ b/src/TestFramework/MSTest.Core/Attributes/DynamicDataAttribute.cs
@@ -56,7 +56,7 @@ public DynamicDataAttribute(string dynamicDataSourceName, DynamicDataSourceType
/// Initializes a new instance of the class.
///
///
- /// The type in which the test data is declared (as property or in method).
+ /// The name of method or property having test data.
///
///
/// The declaring type of property or method having data.
@@ -70,6 +70,16 @@ public DynamicDataAttribute(string dynamicDataSourceName, Type dynamicDataDeclar
this.dynamicDataDeclaringType = dynamicDataDeclaringType;
}
+ ///
+ /// Gets or sets the name of method used to customize the display name in test results.
+ ///
+ public string DynamicDataDisplayName { get; set; }
+
+ ///
+ /// Gets or sets the declaring type used to customize the display name in test results.
+ ///
+ public Type DynamicDataDisplayNameDeclaringType { get; set; }
+
///
public IEnumerable GetData(MethodInfo methodInfo)
{
@@ -131,7 +141,35 @@ public IEnumerable GetData(MethodInfo methodInfo)
///
public string GetDisplayName(MethodInfo methodInfo, object[] data)
{
- if (data != null)
+ if (this.DynamicDataDisplayName != null)
+ {
+ var dynamicDisplayNameDeclaringType = this.DynamicDataDisplayNameDeclaringType ?? methodInfo.DeclaringType;
+
+ var method = dynamicDisplayNameDeclaringType.GetTypeInfo().GetDeclaredMethod(this.DynamicDataDisplayName);
+ if (method == null)
+ {
+ throw new ArgumentNullException(string.Format("{0} {1}", DynamicDataSourceType.Method, this.DynamicDataDisplayName));
+ }
+
+ var parameters = method.GetParameters();
+ if (parameters.Length != 2 ||
+ parameters[0].ParameterType != typeof(MethodInfo) ||
+ parameters[1].ParameterType != typeof(object[]) ||
+ method.ReturnType != typeof(string) ||
+ !method.IsStatic ||
+ !method.IsPublic)
+ {
+ throw new ArgumentNullException(
+ string.Format(
+ FrameworkMessages.DynamicDataDisplayName,
+ this.DynamicDataDisplayName,
+ typeof(string).Name,
+ string.Join(", ", typeof(MethodInfo).Name, typeof(object[]).Name)));
+ }
+
+ return method.Invoke(null, new object[] { methodInfo, data }) as string;
+ }
+ else if (data != null)
{
return string.Format(CultureInfo.CurrentCulture, FrameworkMessages.DataDrivenResultDisplayName, methodInfo.Name, string.Join(",", data.AsEnumerable()));
}
@@ -139,4 +177,4 @@ public string GetDisplayName(MethodInfo methodInfo, object[] data)
return null;
}
}
-}
+}
\ No newline at end of file
diff --git a/src/TestFramework/MSTest.Core/Interfaces/ITestDataSource.cs b/src/TestFramework/MSTest.Core/Interfaces/ITestDataSource.cs
index bfdc6677b1..d4dada30e1 100644
--- a/src/TestFramework/MSTest.Core/Interfaces/ITestDataSource.cs
+++ b/src/TestFramework/MSTest.Core/Interfaces/ITestDataSource.cs
@@ -26,7 +26,7 @@ public interface ITestDataSource
/// Gets the display name corresponding to test data row for displaying in TestResults.
///
///
- /// The method Info of test method.
+ /// The method info of test method.
///
///
/// The test data which is passed to test method.
diff --git a/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.Designer.cs b/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.Designer.cs
index 5eec0b3402..c6be5aa38c 100644
--- a/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.Designer.cs
+++ b/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.Designer.cs
@@ -259,6 +259,15 @@ internal static string DoNotUseAssertEquals {
}
}
+ ///
+ /// Looks up a localized string similar to Method {0} must match the expected signature: public static {1} {0}({2})..
+ ///
+ internal static string DynamicDataDisplayName {
+ get {
+ return ResourceManager.GetString("DynamicDataDisplayName", resourceCulture);
+ }
+ }
+
///
/// Looks up a localized string similar to Property or method {0} on {1} does not return IEnumerable<object[]>..
///
diff --git a/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.resx b/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.resx
index f69c5d8766..4cccff1036 100644
--- a/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.resx
+++ b/src/TestFramework/MSTest.Core/Resources/FrameworkMessages.resx
@@ -283,4 +283,7 @@ Stack Trace: {4}
Value returned by property or method {0} shouldn't be null.
+
+ Method {0} must match the expected signature: public static {1} {0}({2}).
+
\ No newline at end of file
diff --git a/src/TestFramework/MSTest.Core/Resources/xlf/FrameworkMessages.cs.xlf b/src/TestFramework/MSTest.Core/Resources/xlf/FrameworkMessages.cs.xlf
index d19ff7898c..666861e7d9 100644
--- a/src/TestFramework/MSTest.Core/Resources/xlf/FrameworkMessages.cs.xlf
+++ b/src/TestFramework/MSTest.Core/Resources/xlf/FrameworkMessages.cs.xlf
@@ -282,6 +282,11 @@ Trasování zásobníku: {4}
Hodnota vrácená vlastností nebo metodou {0} by neměla být null.
+
+ Method {0} must match the expected signature: public static {1} {0}({2}).
+ Method {0} must match the expected signature: {1} {0}({2}).
+
+