@@ -556,4 +556,75 @@ public async Task SupportsHandlersWithSameSignatureButDifferentParameterNamesFro
556
556
Assert . Equal ( new EventId ( 5 , "ImplicitBodyNotProvided" ) , log2 . EventId ) ;
557
557
Assert . Equal ( @"Implicit body inferred for parameter ""todo1"" but no body was provided. Did you mean to use a Service instead?" , log2 . Message ) ;
558
558
}
559
+
560
+ [ Fact ]
561
+ public async Task SkipsMapWithIncorrectNamespaceAndAssembly ( )
562
+ {
563
+ var source = """
564
+ using System;
565
+ using Microsoft.AspNetCore.Builder;
566
+ using Microsoft.AspNetCore.Routing;
567
+
568
+ namespace TestApp
569
+ {
570
+ public static class TestMapActions
571
+ {
572
+ public static IEndpointRouteBuilder MapTestEndpoints(this IEndpointRouteBuilder app)
573
+ {
574
+ app.ServiceProvider.Map(1, (string test) => "Hello world!");
575
+ app.ServiceProvider.MapPost(2, (string test) => "Hello world!");
576
+ app.Map(3, (string test) => "Hello world!");
577
+ app.MapPost(4, (string test) => "Hello world!");
578
+ return app;
579
+ }
580
+ }
581
+
582
+ public static class EndpointRouteBuilderExtensions
583
+ {
584
+ public static IServiceProvider Map(this IServiceProvider app, int id, Delegate requestDelegate)
585
+ {
586
+ return app;
587
+ }
588
+
589
+ public static IEndpointRouteBuilder Map(this IEndpointRouteBuilder app, int id, Delegate requestDelegate)
590
+ {
591
+ return app;
592
+ }
593
+ }
594
+ }
595
+ namespace Microsoft.AspNetCore.Builder
596
+ {
597
+ public static class EndpointRouteBuilderExtensions
598
+ {
599
+ public static IServiceProvider MapPost(this IServiceProvider app, int id, Delegate requestDelegate)
600
+ {
601
+ return app;
602
+ }
603
+
604
+ public static IEndpointRouteBuilder MapPost(this IEndpointRouteBuilder app, int id, Delegate requestDelegate)
605
+ {
606
+ return app;
607
+ }
608
+ }
609
+ }
610
+ """ ;
611
+ var project = CreateProject ( ) ;
612
+ project = project . AddDocument ( "TestMapActions.cs" , SourceText . From ( source , Encoding . UTF8 ) ) . Project ;
613
+ var compilation = await project . GetCompilationAsync ( ) ;
614
+
615
+ var generator = new RequestDelegateGenerator . RequestDelegateGenerator ( ) . AsSourceGenerator ( ) ;
616
+ GeneratorDriver driver = CSharpGeneratorDriver . Create ( generators : new [ ]
617
+ {
618
+ generator
619
+ } ,
620
+ driverOptions : new GeneratorDriverOptions ( IncrementalGeneratorOutputKind . None , trackIncrementalGeneratorSteps : true ) ,
621
+ parseOptions : ParseOptions ) ;
622
+ driver = driver . RunGeneratorsAndUpdateCompilation ( compilation , out var updatedCompilation ,
623
+ out var diagnostics ) ;
624
+ var generatorRunResult = driver . GetRunResult ( ) ;
625
+
626
+ // Emits diagnostic and generates source for all endpoints
627
+ var result = Assert . IsType < GeneratorRunResult > ( Assert . Single ( generatorRunResult . Results ) ) ;
628
+ Assert . Empty ( GetStaticEndpoints ( result , GeneratorSteps . EndpointModelStep ) ) ;
629
+ }
559
630
}
0 commit comments