Support running Reflection tests within Visual Studio (#75915)
authorSteve Harter <steveharter@users.noreply.github.com>
Fri, 30 Sep 2022 13:51:44 +0000 (08:51 -0500)
committerGitHub <noreply@github.com>
Fri, 30 Sep 2022 13:51:44 +0000 (08:51 -0500)
src/libraries/System.Reflection/tests/AssemblyTests.cs
src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj

index bd86b76..6105930 100644 (file)
@@ -154,10 +154,19 @@ namespace System.Reflection.Tests
             Assert.NotNull(Assembly.GetEntryAssembly());
             string assembly = Assembly.GetEntryAssembly().ToString();
 
-            // The single file test runner is not xunit.console
-            string expectedAssembly = PlatformDetection.IsNativeAot ? "System.Reflection.Tests" : "xunit.console";
+            bool correct;
+            if (PlatformDetection.IsNativeAot)
+            {
+                // The single file test runner is not 'xunit.console'.
+                correct = assembly.IndexOf("System.Reflection.Tests", StringComparison.OrdinalIgnoreCase) != -1;
+            }
+            else
+            {
+                // Under Visual Studio, the runner is 'testhost', otherwise it is 'xunit.console'.
+                correct = assembly.IndexOf("xunit.console", StringComparison.OrdinalIgnoreCase) != -1 ||
+                          assembly.IndexOf("testhost", StringComparison.OrdinalIgnoreCase) != -1;
+            }
 
-            bool correct = assembly.IndexOf(expectedAssembly, StringComparison.OrdinalIgnoreCase) != -1;
             Assert.True(correct, $"Unexpected assembly name {assembly}");
         }
 
index 5da8f6d..bc011a8 100644 (file)
@@ -2,8 +2,6 @@
   <PropertyGroup>
     <TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
     <TestRuntime>true</TestRuntime>
-    <!-- LoadFrom_SameIdentityAsAssemblyWithDifferentPath_ReturnsEqualAssemblies test relies on no deps.json -->
-    <GenerateDependencyFile>false</GenerateDependencyFile>
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <!-- SYSLIB0013: Uri.EscapeUriString is obsolete
          SYSLIB0037: AssemblyName members HashAlgorithm, ProcessorArchitecture, and VersionCompatibility are obsolete. -->