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

Avoid referencing a test assembly in compilation #11005

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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 @@ -10,6 +10,8 @@
using Microsoft.AspNetCore.Mvc.Razor.Extensions;
using Microsoft.AspNetCore.Razor.Test.Common;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;

namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests;
Expand All @@ -22,8 +24,15 @@ public CodeGenerationIntegrationTest(bool designTime = false)
: base(layer: TestProject.Layer.Compiler)
{
this.designTime = designTime;
BaseCompilation = BaseCompilation.AddReferences(
MetadataReference.CreateFromFile(typeof(TestTagHelperDescriptors).Assembly.Location));
var testTagHelpers = CSharpCompilation.Create(
assemblyName: "Microsoft.AspNetCore.Razor.Language.Test",
syntaxTrees:
[
CSharpSyntaxTree.ParseText(TestTagHelperDescriptors.Code),
],
references: ReferenceUtil.AspNetLatestAll,
options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));
BaseCompilation = BaseCompilation.AddReferences(testTagHelpers.VerifyDiagnostics().EmitToImageReference());
}
[IntegrationTestFact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static IEnumerable<TagHelperDescriptor> EnumTagHelperDescriptors
.Name("catch-all")
.Metadata(PropertyName("CatchAll"))
.AsEnum()
.TypeName($"{typeof(TestTagHelperDescriptors).FullName}.{nameof(MyEnum)}"),
.TypeName("Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestTagHelperDescriptors.MyEnum"),
}),
CreateTagHelperDescriptor(
tagName: "input",
Expand All @@ -227,7 +227,7 @@ public static IEnumerable<TagHelperDescriptor> EnumTagHelperDescriptors
.Name("value")
.Metadata(PropertyName("Value"))
.AsEnum()
.TypeName($"{typeof(TestTagHelperDescriptors).FullName}.{nameof(MyEnum)}"),
.TypeName("Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestTagHelperDescriptors.MyEnum"),
}),
};
}
Expand Down Expand Up @@ -644,9 +644,17 @@ private class TestType
public string BoundProperty { get; set; }
}

public enum MyEnum
{
MyValue,
MySecondValue
}
public static readonly string Code = """
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests
{
public class TestTagHelperDescriptors
{
public enum MyEnum
{
MyValue,
MySecondValue
}
}
}
""";
}