@@ -25,6 +25,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Discovery
25
25
using TestCleanup = FrameworkV1 ::Microsoft . VisualStudio . TestTools . UnitTesting . TestCleanupAttribute ;
26
26
using TestInitialize = FrameworkV1 ::Microsoft . VisualStudio . TestTools . UnitTesting . TestInitializeAttribute ;
27
27
using TestMethod = FrameworkV1 ::Microsoft . VisualStudio . TestTools . UnitTesting . TestMethodAttribute ;
28
+ using TestMethodV2 = FrameworkV2 ::Microsoft . VisualStudio . TestTools . UnitTesting . TestMethodAttribute ;
28
29
using UTF = FrameworkV2 ::Microsoft . VisualStudio . TestTools . UnitTesting ;
29
30
30
31
[ TestClass ]
@@ -529,6 +530,40 @@ public void GetTestFromMethodShouldSetDeclaringAssemblyName()
529
530
Assert . AreEqual ( otherAssemblyName , testElement . TestMethod . DeclaringAssemblyName ) ;
530
531
}
531
532
533
+ [ TestMethod ]
534
+ public void GetTestFromMethodShouldSetDisplayNameToTestMethodNameIfDisplayNameIsNotPresent ( )
535
+ {
536
+ this . SetupTestClassAndTestMethods ( isValidTestClass : true , isValidTestMethod : true , isMethodFromSameAssembly : true ) ;
537
+ TypeEnumerator typeEnumerator = this . GetTypeEnumeratorInstance ( typeof ( DummyTestClass ) , "DummyAssemblyName" ) ;
538
+ var methodInfo = typeof ( DummyTestClass ) . GetMethod ( nameof ( DummyTestClass . MethodWithVoidReturnType ) ) ;
539
+
540
+ // Setup mocks to behave like we have [TestMethod] attribute on the method
541
+ this . mockReflectHelper . Setup (
542
+ rh => rh . GetCustomAttribute ( It . IsAny < MemberInfo > ( ) , It . IsAny < Type > ( ) ) ) . Returns ( new TestMethodV2 ( ) ) ;
543
+
544
+ var testElement = typeEnumerator . GetTestFromMethod ( methodInfo , true , this . warnings ) ;
545
+
546
+ Assert . IsNotNull ( testElement ) ;
547
+ Assert . AreEqual ( "MethodWithVoidReturnType" , testElement . DisplayName ) ;
548
+ }
549
+
550
+ [ TestMethod ]
551
+ public void GetTestFromMethodShouldSetDisplayNameFromAttribute ( )
552
+ {
553
+ this . SetupTestClassAndTestMethods ( isValidTestClass : true , isValidTestMethod : true , isMethodFromSameAssembly : true ) ;
554
+ TypeEnumerator typeEnumerator = this . GetTypeEnumeratorInstance ( typeof ( DummyTestClass ) , "DummyAssemblyName" ) ;
555
+ var methodInfo = typeof ( DummyTestClass ) . GetMethod ( nameof ( DummyTestClass . MethodWithVoidReturnType ) ) ;
556
+
557
+ // Setup mocks to behave like we have [TestMethod("Test method display name.")] attribute on the method
558
+ this . mockReflectHelper . Setup (
559
+ rh => rh . GetCustomAttribute ( methodInfo , typeof ( TestMethodV2 ) ) ) . Returns ( new TestMethodV2 ( "Test method display name." ) ) ;
560
+
561
+ var testElement = typeEnumerator . GetTestFromMethod ( methodInfo , true , this . warnings ) ;
562
+
563
+ Assert . IsNotNull ( testElement ) ;
564
+ Assert . AreEqual ( "Test method display name." , testElement . DisplayName ) ;
565
+ }
566
+
532
567
#endregion
533
568
534
569
#region private methods
0 commit comments