Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on Assembly.GetCallingAssembly #25494

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public class AspNetSdkBaselineTest : AspNetSdkTest
// path. Returning null avoids any transformation
protected Func<StaticWebAsset, string, StaticWebAsset, string> 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<AssemblyMetadataAttribute>();
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions src/Tests/Microsoft.NET.TestFramework/AspNetSdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use GetType() here instead? We do that in some other types in the framework like MemoryStream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this class is not concrete, GetType() wouldn't work here.

{
var assembly = Assembly.GetCallingAssembly();
var testAssemblyMetadata = assembly.GetCustomAttributes<AssemblyMetadataAttribute>();
var testAssemblyMetadata = testAssembly.GetCustomAttributes<AssemblyMetadataAttribute>();
DefaultTfm = testAssemblyMetadata.SingleOrDefault(a => a.Key == "AspNetTestTfm").Value;
}

Expand Down