Skip to content

Commit 8fc808a

Browse files
committed
Try fix tests in CI
1 parent 174009a commit 8fc808a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Http/Http.Extensions/test/ValidationsGenerator/ValidationsGeneratorTestsBase.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public class ValidationsGeneratorTestsBase
2323
private static readonly CSharpParseOptions _parseOptions = new CSharpParseOptions(LanguageVersion.Preview)
2424
.WithFeatures([new KeyValuePair<string, string>("InterceptorsNamespaces", "Microsoft.AspNetCore.Http.Validations.Generated")]);
2525

26+
private static string GetAssemblyAttributes(string directory, string assemblyName) => $"""
27+
[assembly: Microsoft.AspNetCore.Mvc.Testing.WebApplicationFactoryContentRootAttribute("{assemblyName}, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "", "{directory}", "0")]
28+
""";
29+
2630
private static string CreateSourceText(string source) => $$"""
2731
{{source}}
2832
// Make Program class public for consumption
@@ -54,10 +58,15 @@ public Task Verify(string source, out Compilation compilation)
5458
MetadataReference.CreateFromFile(typeof(IHttpMethodMetadata).Assembly.Location),
5559
MetadataReference.CreateFromFile(typeof(IResult).Assembly.Location),
5660
MetadataReference.CreateFromFile(typeof(HttpJsonServiceExtensions).Assembly.Location),
61+
MetadataReference.CreateFromFile(typeof(WebApplicationFactoryContentRootAttribute).Assembly.Location),
5762
]);
5863
var generator = new ValidationsGenerator();
59-
var inputCompilation = CSharpCompilation.Create($"ValidationsGeneratorSample-{Guid.NewGuid()}",
60-
[CSharpSyntaxTree.ParseText(CreateSourceText(source), options: _parseOptions, path: "Program.cs")],
64+
var assemblyName = $"ValidationsGeneratorSample-{Guid.NewGuid()}";
65+
var inputCompilation = CSharpCompilation.Create(assemblyName,
66+
[
67+
CSharpSyntaxTree.ParseText(CreateSourceText(source), options: _parseOptions, path: "Program.cs"),
68+
CSharpSyntaxTree.ParseText(GetAssemblyAttributes(AppContext.BaseDirectory, assemblyName), options: _parseOptions, path: "AssemblyAttributes.cs"),
69+
],
6170
references,
6271
new CSharpCompilationOptions(OutputKind.ConsoleApplication, nullableContextOptions: NullableContextOptions.Enable));
6372
var driver = CSharpGeneratorDriver.Create(generators: [generator.AsSourceGenerator()], parseOptions: _parseOptions);

0 commit comments

Comments
 (0)