diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Discovery/TypeEnumerator.cs b/src/Adapter/MSTestAdapter.PlatformServices/Discovery/TypeEnumerator.cs index 88192b09bb..72c3680282 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Discovery/TypeEnumerator.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Discovery/TypeEnumerator.cs @@ -83,7 +83,7 @@ internal List GetTests(List warnings) { // ToString() outputs method name and its signature. This is necessary for overloaded methods to be recognized as distinct tests. foundDuplicateTests = foundDuplicateTests || !foundTests.Add(method.ToString() ?? method.Name); - UnitTestElement testMethod = GetTestFromMethod(method, isMethodDeclaredInTestTypeAssembly, warnings); + UnitTestElement testMethod = GetTestFromMethod(method, warnings); tests.Add(testMethod); } @@ -117,10 +117,9 @@ internal List GetTests(List warnings) /// Gets a UnitTestElement from a MethodInfo object filling it up with appropriate values. /// /// The reflected method. - /// True if the reflected method is declared in the same assembly as the current type. /// Contains warnings if any, that need to be passed back to the caller. /// Returns a UnitTestElement. - internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInTestTypeAssembly, ICollection warnings) + internal UnitTestElement GetTestFromMethod(MethodInfo method, ICollection warnings) { // null if the current instance represents a generic type parameter. DebugEx.Assert(_type.AssemblyQualifiedName != null, "AssemblyQualifiedName for method is null."); @@ -137,13 +136,6 @@ internal UnitTestElement GetTestFromMethod(MethodInfo method, bool isDeclaredInT testMethod.DeclaringClassFullName = method.DeclaringType.FullName; } - if (!isDeclaredInTestTypeAssembly) - { - testMethod.DeclaringAssemblyName = - PlatformServiceProvider.Instance.FileOperations.GetAssemblyPath( - method.DeclaringType.Assembly); - } - var testElement = new UnitTestElement(testMethod) { // Get compiler generated type name for async test method (either void returning or task returning). diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IFileOperations.cs b/src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IFileOperations.cs index 4cd6561417..eddc037d5e 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IFileOperations.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Interfaces/IFileOperations.cs @@ -25,13 +25,6 @@ internal interface IFileOperations /// Assembly LoadAssembly(string assemblyName, bool isReflectionOnly); - /// - /// Gets the path to the .DLL of the assembly. - /// - /// The assembly. - /// Path to the .DLL of the assembly. - string? GetAssemblyPath(Assembly assembly); - /// /// Verify if a file exists in the current context. /// diff --git a/src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs b/src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs index 0244fe1f62..f865758287 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/ObjectModel/TestMethod.cs @@ -76,22 +76,6 @@ internal TestMethod(string? managedTypeName, string? managedMethodName, string?[ public string? ParameterTypes { get; } - /// - /// Gets or sets the declaring assembly full name. This will be used while getting navigation data. - /// This will be null if AssemblyName is same as DeclaringAssemblyName. - /// Reason to set to null in the above case is to minimize the transfer of data across appdomains and not have a performance hit. - /// - public string? DeclaringAssemblyName - { - get; - - set - { - DebugEx.Assert(value != AssemblyName, "DeclaringAssemblyName should not be the same as AssemblyName."); - field = value; - } - } - /// /// Gets or sets the declaring class full name. /// This will be used to resolve overloads and while getting navigation data. @@ -154,11 +138,6 @@ public string? DeclaringClassFullName /// internal string? TestDataSourceIgnoreMessage { get; set; } - /// - /// Gets or sets the test group set during discovery. - /// - internal string? TestGroup { get; set; } - /// /// Gets or sets the display name set during discovery. /// diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/FileOperations.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/FileOperations.cs index 20d7c87d8c..654ef49380 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/FileOperations.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/FileOperations.cs @@ -60,21 +60,6 @@ public Assembly LoadAssembly(string assemblyName, bool isReflectionOnly) #endif } - /// - /// Gets the path to the .DLL of the assembly. - /// - /// The assembly. - /// Path to the .DLL of the assembly. - public string? GetAssemblyPath(Assembly assembly) -#if NETSTANDARD || (NETCOREAPP && !WINDOWS_UWP) || NETFRAMEWORK - // This method will never be called in source generator mode, we are providing a different provider for file operations. -#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file - => assembly.Location; -#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file -#elif WINDOWS_UWP - => null; // TODO: what are the options here? -#endif - /// /// Verifies if file exists in context. /// diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.cs b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.cs index 6ca0f5fbdd..1676ba6bcd 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.cs +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.cs @@ -267,7 +267,7 @@ public void GetTestFromMethodShouldInitiateTestMethodWithCorrectParameters() SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true); TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName"); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!, _warnings); Verify(testElement is not null); Verify(testElement.TestMethod.Name == "MethodWithVoidReturnType"); @@ -281,7 +281,7 @@ public void GetTestFromMethodShouldInitializeAsyncTypeNameCorrectly() TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName"); MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("AsyncMethodWithTaskReturnType")!; - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); string? expectedAsyncTaskName = methodInfo.GetCustomAttribute()!.StateMachineType.FullName; @@ -297,7 +297,7 @@ public void GetTestFromMethodShouldSetTestCategory() methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new TestCategoryAttribute("foo"), new TestCategoryAttribute("bar")); string[] testCategories = ["foo", "bar"]; - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testCategories.SequenceEqual(testElement.TestCategory)); @@ -310,7 +310,7 @@ public void GetTestFromMethodShouldSetDoNotParallelize() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new DoNotParallelizeAttribute()); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DoNotParallelize); @@ -327,7 +327,7 @@ public void GetTestFromMethodShouldFillTraitsWithTestProperties() new TestPropertyAttribute("foo", "bar"), new TestPropertyAttribute("fooprime", "barprime")); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.Traits!.Length == 2); @@ -349,7 +349,7 @@ public void GetTestFromMethodShouldFillTraitsWithTestOwnerPropertyIfPresent() new TestPropertyAttribute("fooprime", "barprime"), new OwnerAttribute("mike")); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.Traits!.Length == 3); @@ -368,7 +368,7 @@ public void GetTestFromMethodShouldFillTraitsWithTestPriorityPropertyIfPresent() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new TestPropertyAttribute("foo", "bar"), new TestPropertyAttribute("fooprime", "barprime"), new PriorityAttribute(1)); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.Traits!.Length == 3); @@ -387,7 +387,7 @@ public void GetTestFromMethodShouldSetPriority() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new PriorityAttribute(1)); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.Priority == 1); @@ -400,7 +400,7 @@ public void GetTestFromMethodShouldSetDescription() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new DescriptionAttribute("Dummy description")); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement.Traits is not null); Verify(testElement.Traits.Any(t => t.Name == "Description" && t.Value == "Dummy description")); @@ -413,7 +413,7 @@ public void GetTestFromMethodShouldSetWorkItemIds() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new WorkItemAttribute(123), new WorkItemAttribute(345)); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(new string[] { "123", "345" }.SequenceEqual(testElement.WorkItemIds)); } @@ -424,7 +424,7 @@ public void GetTestFromMethodShouldSetWorkItemIdsToNullIfNotAny() TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName"); MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement.WorkItemIds is null); } @@ -440,7 +440,7 @@ public void GetTestFromMethodShouldSetDeploymentItemsToNullIfNotPresent() td => td.GetDeploymentItems(It.IsAny(), It.IsAny(), _warnings)) .Returns((KeyValuePair[])null!); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DeploymentItems is null); @@ -457,31 +457,13 @@ public void GetTestFromMethodShouldSetDeploymentItems() _testablePlatformServiceProvider.MockTestDeployment.Setup( td => td.GetDeploymentItems(methodInfo, typeof(DummyTestClass), _warnings)).Returns(deploymentItems); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DeploymentItems is not null); Verify(deploymentItems.SequenceEqual(testElement.DeploymentItems)); } - public void GetTestFromMethodShouldSetDeclaringAssemblyName() - { - const bool isMethodFromSameAssembly = false; - - TypeEnumerator typeEnumerator = GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName"); - MethodInfo methodInfo = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType")!; - - // Setup mocks - string otherAssemblyName = "ADifferentAssembly"; - _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.GetAssemblyPath(It.IsAny())) - .Returns(otherAssemblyName); - - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, isMethodFromSameAssembly, _warnings); - - Verify(testElement is not null); - Verify(otherAssemblyName == testElement.TestMethod.DeclaringAssemblyName); - } - public void GetTestFromMethodShouldSetDisplayNameToTestMethodNameIfDisplayNameIsNotPresent() { SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true); @@ -489,7 +471,7 @@ public void GetTestFromMethodShouldSetDisplayNameToTestMethodNameIfDisplayNameIs MethodInfo methodInfo = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.MethodWithVoidReturnType))!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new TestMethodAttribute()); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DisplayName == "MethodWithVoidReturnType"); @@ -502,7 +484,7 @@ public void GetTestFromMethodShouldSetDisplayNameFromTestMethodAttribute() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.MethodWithVoidReturnType))!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new TestMethodAttribute() { DisplayName = "Test method display name." }); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DisplayName == "Test method display name."); @@ -515,7 +497,7 @@ public void GetTestFromMethodShouldSetDisplayNameFromDataTestMethodAttribute() MethodInfo methodInfo = typeof(DummyTestClass).GetMethod(nameof(DummyTestClass.MethodWithVoidReturnType))!; methodInfo = new MockedMethodInfoWithExtraAttributes(methodInfo, new DataTestMethodAttribute() { DisplayName = "Test method display name." }); - MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, true, _warnings); + MSTest.TestAdapter.ObjectModel.UnitTestElement testElement = typeEnumerator.GetTestFromMethod(methodInfo, _warnings); Verify(testElement is not null); Verify(testElement.DisplayName == "Test method display name.");