11using CleanArchitecture . Extensions . Multitenancy ;
22using CleanArchitecture . Extensions . Multitenancy . Abstractions ;
33using CleanArchitecture . Extensions . Multitenancy . AspNetCore . Context ;
4+ using CleanArchitecture . Extensions . Multitenancy . AspNetCore ;
45using CleanArchitecture . Extensions . Multitenancy . AspNetCore . Middleware ;
56using CleanArchitecture . Extensions . Multitenancy . AspNetCore . Options ;
67using CleanArchitecture . Extensions . Multitenancy . Behaviors ;
78using CleanArchitecture . Extensions . Multitenancy . Configuration ;
89using CleanArchitecture . Extensions . Multitenancy . Context ;
10+ using Microsoft . AspNetCore . Builder ;
911using Microsoft . AspNetCore . Http ;
12+ using Microsoft . Extensions . DependencyInjection ;
1013using Microsoft . Extensions . Logging . Abstractions ;
1114using OptionsFactory = Microsoft . Extensions . Options . Options ;
1215
@@ -34,8 +37,13 @@ public async Task InvokeAsync_sets_current_tenant_and_http_context_items()
3437 return Task . CompletedTask ;
3538 } ;
3639
37- var middleware = new TenantResolutionMiddleware (
38- next ,
40+ var middleware = new TenantResolutionMiddleware ( next ) ;
41+
42+ var httpContext = new DefaultHttpContext ( ) ;
43+ httpContext . Request . Headers [ "X-Tenant-ID" ] = "tenant-1" ;
44+
45+ await middleware . InvokeAsync (
46+ httpContext ,
3947 resolver ,
4048 accessor ,
4149 factory ,
@@ -44,16 +52,31 @@ public async Task InvokeAsync_sets_current_tenant_and_http_context_items()
4452 logger ,
4553 new TenantCorrelationScopeAccessor ( ) ) ;
4654
47- var httpContext = new DefaultHttpContext ( ) ;
48- httpContext . Request . Headers [ "X-Tenant-ID" ] = "tenant-1" ;
49-
50- await middleware . InvokeAsync ( httpContext ) ;
51-
5255 Assert . Equal ( "tenant-1" , observedTenantId ) ;
5356 Assert . NotNull ( observedContext ) ;
5457 Assert . Null ( accessor . TenantId ) ;
5558 }
5659
60+ [ Fact ]
61+ public void UseCleanArchitectureMultitenancy_builds_pipeline_with_validated_scopes ( )
62+ {
63+ var services = new ServiceCollection ( ) ;
64+ services . AddLogging ( ) ;
65+ services . AddCleanArchitectureMultitenancyAspNetCore ( ) ;
66+
67+ using var provider = services . BuildServiceProvider ( new ServiceProviderOptions
68+ {
69+ ValidateScopes = true
70+ } ) ;
71+
72+ var app = new ApplicationBuilder ( provider ) ;
73+ app . UseCleanArchitectureMultitenancy ( ) ;
74+ app . Run ( _ => Task . CompletedTask ) ;
75+
76+ var exception = Record . Exception ( ( ) => app . Build ( ) ) ;
77+ Assert . Null ( exception ) ;
78+ }
79+
5780 private sealed class CapturingTenantResolver : ITenantResolver
5881 {
5982 public TenantResolutionContext ? CapturedContext { get ; private set ; }
0 commit comments