2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using System . Collections . Immutable ;
5
- using System . Linq ;
6
5
using System . Reflection ;
7
6
using System . Runtime . Loader ;
8
7
using System . Text ;
9
- using Microsoft . AspNetCore ;
10
8
using Microsoft . AspNetCore . Builder ;
11
9
using Microsoft . CodeAnalysis ;
12
10
using Microsoft . CodeAnalysis . CSharp ;
13
- using Microsoft . AspNetCore . Http . SourceGeneration ;
14
- using Microsoft . AspNetCore . Http . SourceGeneration . StaticRouteHandlerModel ;
15
11
using Microsoft . AspNetCore . Routing ;
16
- using Microsoft . CodeAnalysis . Diagnostics ;
17
12
using Microsoft . CodeAnalysis . Emit ;
18
13
using Microsoft . CodeAnalysis . Text ;
19
14
using Microsoft . Extensions . DependencyInjection ;
@@ -30,13 +25,10 @@ internal static (ImmutableArray<GeneratorRunResult>, Compilation) RunGenerator(s
30
25
var generator = new RequestDelegateGenerator ( ) . AsSourceGenerator ( ) ;
31
26
32
27
// Enable the source generator in tests
33
- var optionsProvider = new TestAnalyzerConfigOptionsProvider ( ) ;
34
- optionsProvider . TestGlobalOptions [ "build_property.EnableRequestDelegateGenerator" ] = "true" ;
35
28
GeneratorDriver driver = CSharpGeneratorDriver . Create ( generators : new [ ]
36
29
{
37
30
generator
38
31
} ,
39
- optionsProvider : optionsProvider ,
40
32
driverOptions : new GeneratorDriverOptions ( IncrementalGeneratorOutputKind . None , trackIncrementalGeneratorSteps : true ) ) ;
41
33
42
34
// Run the source generator
@@ -51,10 +43,10 @@ internal static (ImmutableArray<GeneratorRunResult>, Compilation) RunGenerator(s
51
43
52
44
internal static StaticRouteHandlerModel . Endpoint GetStaticEndpoint ( ImmutableArray < GeneratorRunResult > results , string stepName )
53
45
{
54
- var StaticEndpointStep = results [ 0 ] . TrackedSteps [ stepName ] . Single ( ) ;
55
- var StaticEndpointOutput = StaticEndpointStep . Outputs . Single ( ) ;
56
- var ( StaticEndpoint , _) = StaticEndpointOutput ;
57
- var endpoint = Assert . IsType < StaticRouteHandlerModel . Endpoint > ( StaticEndpoint ) ;
46
+ var staticEndpointStep = results [ 0 ] . TrackedSteps [ stepName ] . Single ( ) ;
47
+ var staticEndpointOutput = staticEndpointStep . Outputs . Single ( ) ;
48
+ var ( staticEndpoint , _) = staticEndpointOutput ;
49
+ var endpoint = Assert . IsType < StaticRouteHandlerModel . Endpoint > ( staticEndpoint ) ;
58
50
return endpoint ;
59
51
}
60
52
@@ -97,7 +89,7 @@ internal static Endpoint GetEndpointFromCompilation(Compilation compilation)
97
89
pdb . Position = 0 ;
98
90
99
91
var assembly = AssemblyLoadContext . Default . LoadFromStream ( output , pdb ) ;
100
- var handler = assembly ? . GetType ( "TestMapActions" )
92
+ var handler = assembly . GetType ( "TestMapActions" )
101
93
? . GetMethod ( "MapTestEndpoints" , BindingFlags . Public | BindingFlags . Static )
102
94
? . CreateDelegate < Func < IEndpointRouteBuilder , IEndpointRouteBuilder > > ( ) ;
103
95
var sourceKeyType = assembly . GetType ( "Microsoft.AspNetCore.Builder.SourceKey" ) ;
@@ -203,8 +195,6 @@ private class EmptyServiceProvider : IServiceScope, IServiceProvider, IServiceSc
203
195
{
204
196
public IServiceProvider ServiceProvider => this ;
205
197
206
- public RouteHandlerOptions RouteHandlerOptions { get ; set ; } = new RouteHandlerOptions ( ) ;
207
-
208
198
public IServiceScope CreateScope ( )
209
199
{
210
200
return this ;
@@ -226,62 +216,12 @@ public DefaultEndpointRouteBuilder(IApplicationBuilder applicationBuilder)
226
216
DataSources = new List < EndpointDataSource > ( ) ;
227
217
}
228
218
229
- public IApplicationBuilder ApplicationBuilder { get ; }
219
+ private IApplicationBuilder ApplicationBuilder { get ; }
230
220
231
221
public IApplicationBuilder CreateApplicationBuilder ( ) => ApplicationBuilder . New ( ) ;
232
222
233
223
public ICollection < EndpointDataSource > DataSources { get ; }
234
224
235
225
public IServiceProvider ServiceProvider => ApplicationBuilder . ApplicationServices ;
236
226
}
237
-
238
- private class TestAnalyzerConfigOptionsProvider : AnalyzerConfigOptionsProvider
239
- {
240
- public override AnalyzerConfigOptions GlobalOptions => TestGlobalOptions ;
241
-
242
- public TestAnalyzerConfigOptions TestGlobalOptions { get ; } = new TestAnalyzerConfigOptions ( ) ;
243
-
244
- public override AnalyzerConfigOptions GetOptions ( SyntaxTree tree ) => throw new NotImplementedException ( ) ;
245
-
246
- public Dictionary < string , TestAnalyzerConfigOptions > AdditionalTextOptions { get ; } = new ( ) ;
247
-
248
- public override AnalyzerConfigOptions GetOptions ( AdditionalText textFile )
249
- {
250
- return AdditionalTextOptions . TryGetValue ( textFile . Path , out var options ) ? options : new TestAnalyzerConfigOptions ( ) ;
251
- }
252
-
253
- public TestAnalyzerConfigOptionsProvider Clone ( )
254
- {
255
- var provider = new TestAnalyzerConfigOptionsProvider ( ) ;
256
- foreach ( var option in this . TestGlobalOptions . Options )
257
- {
258
- provider . TestGlobalOptions [ option . Key ] = option . Value ;
259
- }
260
- foreach ( var option in this . AdditionalTextOptions )
261
- {
262
- var newOptions = new TestAnalyzerConfigOptions ( ) ;
263
- foreach ( var subOption in option . Value . Options )
264
- {
265
- newOptions [ subOption . Key ] = subOption . Value ;
266
- }
267
- provider . AdditionalTextOptions [ option . Key ] = newOptions ;
268
-
269
- }
270
- return provider ;
271
- }
272
- }
273
-
274
- private class TestAnalyzerConfigOptions : AnalyzerConfigOptions
275
- {
276
- public Dictionary < string , string > Options { get ; } = new ( ) ;
277
-
278
- public string this [ string name ]
279
- {
280
- get => Options [ name ] ;
281
- set => Options [ name ] = value ;
282
- }
283
-
284
- public override bool TryGetValue ( string key , out string value )
285
- => Options . TryGetValue ( key , out value ) ;
286
- }
287
227
}
0 commit comments