From c0a76a57e0f72ae3209de881477c2266b8bafc8a Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Tue, 17 May 2022 19:31:46 -0500 Subject: [PATCH] Remove dependency on Assembly.GetCallingAssembly --- .../BlazorLegacyIntegrationTest50.cs | 2 +- .../WasmBuildIncrementalismTest.cs | 2 +- .../WasmBuildLazyLoadTest.cs | 2 +- .../WasmCompressionTests.cs | 2 +- .../WasmPublishIntegrationTestBase.cs | 2 +- .../WasmPwaManifestTests.cs | 2 +- .../ApplicationPartDiscoveryIntegrationTest.cs | 2 +- .../Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs | 6 +++--- .../BuildIncrementalismTest.cs | 2 +- .../Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs | 2 +- .../Microsoft.NET.Sdk.Razor.Tests/BuildIntrospectionTest.cs | 2 +- .../BuildWithComponents31IntegrationTest.cs | 2 +- .../BuildWithComponentsIntegrationTest.cs | 2 +- .../DesignTimeBuildIntegrationTest.cs | 2 +- .../MvcBuildIntegrationTest21NetFx.cs | 2 +- .../MvcBuildIntegrationTestLegacy.cs | 2 +- .../Microsoft.NET.Sdk.Razor.Tests/PackIntegrationTest.cs | 2 +- .../Microsoft.NET.Sdk.Razor.Tests/PublishIntegrationTest.cs | 2 +- src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs | 5 ++--- 19 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs index b4f92adf93c4..f7835285a610 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/BlazorLegacyIntegrationTest50.cs @@ -15,7 +15,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public class BlazorLegacyIntegrationTest50 : AspNetSdkBaselineTest { - public BlazorLegacyIntegrationTest50(ITestOutputHelper log) : base(log) + public BlazorLegacyIntegrationTest50(ITestOutputHelper log) : base(log, typeof(BlazorLegacyIntegrationTest50).Assembly) { } diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs index 1aa6d64cb327..dba1a6058595 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildIncrementalismTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public class WasmBuildIncrementalismTest : AspNetSdkTest { - public WasmBuildIncrementalismTest(ITestOutputHelper log) : base(log) { } + public WasmBuildIncrementalismTest(ITestOutputHelper log) : base(log, typeof(WasmBuildIncrementalismTest).Assembly) { } [Fact] public void Build_IsIncremental() diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs index 66ec3cf61726..10607589522c 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmBuildLazyLoadTest.cs @@ -19,7 +19,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public class WasmBuildLazyLoadTest : AspNetSdkTest { - public WasmBuildLazyLoadTest(ITestOutputHelper log) : base(log) {} + public WasmBuildLazyLoadTest(ITestOutputHelper log) : base(log, typeof(WasmBuildLazyLoadTest).Assembly) {} [Fact] public void Build_LazyLoadExplicitAssembly_Debug_Works() diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs index 320f71157fa3..d02c95970f43 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmCompressionTests.cs @@ -14,7 +14,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public class WasmCompressionTests : AspNetSdkTest { - public WasmCompressionTests(ITestOutputHelper log) : base(log) {} + public WasmCompressionTests(ITestOutputHelper log) : base(log, typeof(WasmCompressionTests).Assembly) {} [Fact] public void Publish_UpdatesFilesWhenSourcesChange() diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs index ab6409162f2e..127f513c9d4c 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPublishIntegrationTestBase.cs @@ -14,7 +14,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public abstract class WasmPublishIntegrationTestBase : AspNetSdkTest { - public WasmPublishIntegrationTestBase(ITestOutputHelper log) : base(log) { } + public WasmPublishIntegrationTestBase(ITestOutputHelper log) : base(log, typeof(WasmPublishIntegrationTestBase).Assembly) { } protected static void VerifyBootManifestHashes(TestAsset testAsset, string blazorPublishDirectory) { diff --git a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs index 287707faac85..4cd741c998c2 100644 --- a/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs +++ b/src/Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/WasmPwaManifestTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.NET.Sdk.BlazorWebAssembly.Tests { public class WasmPwaManifestTests : AspNetSdkTest { - public WasmPwaManifestTests(ITestOutputHelper log) : base(log) {} + public WasmPwaManifestTests(ITestOutputHelper log) : base(log, typeof(WasmPwaManifestTests).Assembly) {} [Fact] public void Build_ServiceWorkerAssetsManifest_Works() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/ApplicationPartDiscoveryIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/ApplicationPartDiscoveryIntegrationTest.cs index 74203b0c5d3f..eaa5364b31bd 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/ApplicationPartDiscoveryIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/ApplicationPartDiscoveryIntegrationTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class ApplicationPartDiscoveryIntegrationTest : AspNetSdkTest { - public ApplicationPartDiscoveryIntegrationTest(ITestOutputHelper log) : base(log) {} + public ApplicationPartDiscoveryIntegrationTest(ITestOutputHelper log) : base(log, typeof(ApplicationPartDiscoveryIntegrationTest).Assembly) {} [CoreMSBuildOnlyFact] public void Build_ProjectWithDependencyThatReferencesMvc_AddsAttribute_WhenBuildingUsingDotnetMsbuild() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs index 4fcddc09d826..c96e76b33f2e 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/AspNetSdkBaselineTest.cs @@ -39,15 +39,15 @@ public class AspNetSdkBaselineTest : AspNetSdkTest // path. Returning null avoids any transformation protected Func PathTemplatizer { get; set; } = (asset, originalValue, related) => null; - public AspNetSdkBaselineTest(ITestOutputHelper log) : base(log) + public AspNetSdkBaselineTest(ITestOutputHelper log, Assembly testAssembly) : base(log, typeof(AspNetSdkBaselineTest).Assembly) { - TestAssembly = Assembly.GetCallingAssembly(); + TestAssembly = testAssembly; var testAssemblyMetadata = TestAssembly.GetCustomAttributes(); RuntimeVersion = testAssemblyMetadata.SingleOrDefault(a => a.Key == "NetCoreAppRuntimePackageVersion").Value; DefaultPackageVersion = testAssemblyMetadata.SingleOrDefault(a => a.Key == "DefaultTestBaselinePackageVersion").Value; } - public AspNetSdkBaselineTest(ITestOutputHelper log, bool generateBaselines) : this(log) + public AspNetSdkBaselineTest(ITestOutputHelper log, bool generateBaselines) : this(log, typeof(AspNetSdkBaselineTest).Assembly) { _generateBaselines = generateBaselines; } diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIncrementalismTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIncrementalismTest.cs index 85c29e725368..b31aeb3b028d 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIncrementalismTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIncrementalismTest.cs @@ -21,7 +21,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class BuildIncrementalismTest : AspNetSdkTest { - public BuildIncrementalismTest(ITestOutputHelper log) : base(log) {} + public BuildIncrementalismTest(ITestOutputHelper log) : base(log, typeof(BuildIncrementalismTest).Assembly) {} [Fact(Skip = "https://github.com/dotnet/aspnetcore/issues/28780")] diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs index cfc64174f1bd..7eacce1a14fb 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntegrationTest.cs @@ -21,7 +21,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class BuildIntegrationTest : AspNetSdkTest { - public BuildIntegrationTest(ITestOutputHelper log) : base(log) {} + public BuildIntegrationTest(ITestOutputHelper log) : base(log, typeof(BuildIntegrationTest).Assembly) {} [CoreMSBuildOnlyFact] public void Build_SimpleMvc_UsingDotnetMSBuildAndWithoutBuildServer_CanBuildSuccessfully() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntrospectionTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntrospectionTest.cs index 2a26f8f2f72d..7015b286993b 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntrospectionTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildIntrospectionTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class BuildIntrospectionTest : AspNetSdkTest { - public BuildIntrospectionTest(ITestOutputHelper log) : base(log) {} + public BuildIntrospectionTest(ITestOutputHelper log) : base(log, typeof(BuildIntrospectionTest).Assembly) {} [Fact] public void RazorSdk_AddsCshtmlFilesToUpToDateCheckInput() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponents31IntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponents31IntegrationTest.cs index c763b5b31d8c..496c1aa1c466 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponents31IntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponents31IntegrationTest.cs @@ -15,7 +15,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class BuildWithComponents31IntegrationTest : AspNetSdkTest { - public BuildWithComponents31IntegrationTest(ITestOutputHelper log) : base(log) {} + public BuildWithComponents31IntegrationTest(ITestOutputHelper log) : base(log, typeof(BuildWithComponents31IntegrationTest).Assembly) {} [CoreMSBuildOnlyFact] public void Build_Components_WithDotNetCoreMSBuild_Works() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponentsIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponentsIntegrationTest.cs index f534deda86a7..24326afbf447 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponentsIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/BuildWithComponentsIntegrationTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class BuildWithComponentsIntegrationTest : AspNetSdkTest { - public BuildWithComponentsIntegrationTest(ITestOutputHelper log) : base(log) {} + public BuildWithComponentsIntegrationTest(ITestOutputHelper log) : base(log, typeof(BuildWithComponentsIntegrationTest).Assembly) {} [CoreMSBuildOnlyFact] public void Build_Components_WithDotNetCoreMSBuild_Works() => Build_ComponentsWorks(); diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/DesignTimeBuildIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/DesignTimeBuildIntegrationTest.cs index 323a108e536c..e96a98403221 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/DesignTimeBuildIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/DesignTimeBuildIntegrationTest.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Design.IntegrationTests { public class DesignTimeBuildIntegrationTest : AspNetSdkTest { - public DesignTimeBuildIntegrationTest(ITestOutputHelper log) : base(log) {} + public DesignTimeBuildIntegrationTest(ITestOutputHelper log) : base(log, typeof(DesignTimeBuildIntegrationTest).Assembly) {} [Fact] public void DesignTimeBuild_DoesNotRunRazorTargets() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTest21NetFx.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTest21NetFx.cs index 305808605129..3bbe0e82b78c 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTest21NetFx.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTest21NetFx.cs @@ -18,7 +18,7 @@ public class MvcBuildIntegrationTest21NetFx : AspNetSdkTest private const string TestProjectName ="SimpleMvc21NetFx"; private const string TargetFramework = "net462"; public const string OutputFileName = TestProjectName + ".exe"; - public MvcBuildIntegrationTest21NetFx(ITestOutputHelper log) : base(log) { } + public MvcBuildIntegrationTest21NetFx(ITestOutputHelper log) : base(log, typeof(MvcBuildIntegrationTest21NetFx).Assembly) { } [Fact] public virtual void Building_Project() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs index 9905b016dadd..020437d5ae8f 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/MvcBuildIntegrationTestLegacy.cs @@ -25,7 +25,7 @@ public abstract class MvcBuildIntegrationTestLegacy : AspNetSdkTest // Remove Razor prefix from assembly name public virtual string OutputFileName => $"{TestProjectName}.dll"; - public MvcBuildIntegrationTestLegacy(ITestOutputHelper log) : base(log) { } + public MvcBuildIntegrationTestLegacy(ITestOutputHelper log) : base(log, typeof(MvcBuildIntegrationTestLegacy).Assembly) { } [CoreMSBuildOnlyFact] public virtual void Building_Project() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PackIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PackIntegrationTest.cs index 9b5878c7cfbc..b827b4f2b063 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PackIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PackIntegrationTest.cs @@ -22,7 +22,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests public class PackIntegrationTest : AspNetSdkTest { - public PackIntegrationTest(ITestOutputHelper log) : base(log) {} + public PackIntegrationTest(ITestOutputHelper log) : base(log, typeof(PackIntegrationTest).Assembly) {} [Fact] public void Pack_NoBuild_Works_IncludesAssembly() diff --git a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PublishIntegrationTest.cs b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PublishIntegrationTest.cs index f5b4d4664252..591a1066ac1d 100644 --- a/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PublishIntegrationTest.cs +++ b/src/Tests/Microsoft.NET.Sdk.Razor.Tests/PublishIntegrationTest.cs @@ -18,7 +18,7 @@ namespace Microsoft.NET.Sdk.Razor.Tests { public class PublishIntegrationTest : AspNetSdkTest { - public PublishIntegrationTest(ITestOutputHelper log) : base(log) {} + public PublishIntegrationTest(ITestOutputHelper log) : base(log, typeof(PublishIntegrationTest).Assembly) {} [Fact] public void Publish_RazorCompileOnPublish_IsDefault() diff --git a/src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs b/src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs index 665e873c6c8e..b9c1d25b0842 100644 --- a/src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs +++ b/src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs @@ -18,10 +18,9 @@ public abstract class AspNetSdkTest : SdkTest { public readonly string DefaultTfm; - protected AspNetSdkTest(ITestOutputHelper log) : base(log) + protected AspNetSdkTest(ITestOutputHelper log, Assembly testAssembly) : base(log) { - var assembly = Assembly.GetCallingAssembly(); - var testAssemblyMetadata = assembly.GetCustomAttributes(); + var testAssemblyMetadata = testAssembly.GetCustomAttributes(); DefaultTfm = testAssemblyMetadata.SingleOrDefault(a => a.Key == "AspNetTestTfm").Value; }