-
Notifications
You must be signed in to change notification settings - Fork 193
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
Convert SourceGenerator_RazorFiles_Works to Microsoft.CodeAnalysis.Testing #8356
base: main
Are you sure you want to change the base?
Conversation
|
||
var result = RunGenerator(compilation!, ref driver) | ||
.VerifyPageOutput( | ||
@"#pragma checksum ""Pages/Index.razor"" ""{ff1816ec-aa5e-4d10-87f7-6f4963833460}"" ""6b5db227a6aa2228c777b0771108b184b1fc5df3"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 the page output was moved to an embedded resource, which is generated by modifying the #define
at the top of the test file and otherwise loaded from disk for the test
@@ -0,0 +1,22 @@ | |||
#pragma checksum "/0/Pages/Index.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "6b5db227a6aa2228c777b0771108b184b1fc5df3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This line is the only change to this file relative to the original string. The change presumably occurred because AdditionalFiles now includes an absolute path to the razor source file. It's not clear to me whether a full build with the source generator running will use an absolute path here or a relative path here. If it's a relative path, I'm not sure where it's derived from.
// Don't resolve any reference assemblies from NuGet | ||
ReferenceAssemblies = new ReferenceAssemblies("custom"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This line ensures that we don't hit NuGet for anything during testing (unless a specific test overrides this property to a different value).
foreach (var defaultCompileLibrary in DependencyContext.Load(typeof(RazorSourceGeneratorTests).Assembly)!.CompileLibraries) | ||
{ | ||
foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(new AppLocalResolver())) | ||
{ | ||
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(resolveReferencePath)); | ||
} | ||
} | ||
|
||
// The deps file in the project is incorrect and does not contain "compile" nodes for some references. | ||
// However these binaries are always present in the bin output. As a "temporary" workaround, we'll add | ||
// every dll file that's present in the test's build output as a metadatareference. | ||
foreach (var assembly in Directory.EnumerateFiles(AppContext.BaseDirectory, "*.dll")) | ||
{ | ||
if (!TestState.AdditionalReferences.Any(c => string.Equals(Path.GetFileNameWithoutExtension(c.Display), Path.GetFileNameWithoutExtension(assembly), StringComparison.OrdinalIgnoreCase))) | ||
{ | ||
TestState.AdditionalReferences.Add(MetadataReference.CreateFromFile(assembly)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 This manually adds MetadataReference
items for all the items that were being added to the old tests. The whole block was copied from CreateBaseProject()
.
This is a proof of concept for discussion.