Skip to content

Commit

Permalink
Avoid referencing a test assembly in compilation (#11005)
Browse files Browse the repository at this point in the history
Related to #10343.
  • Loading branch information
jjonescz authored Oct 14, 2024
1 parent 80cd097 commit ecb4434
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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
}
}
}
""";
}

0 comments on commit ecb4434

Please sign in to comment.