File tree Expand file tree Collapse file tree 2 files changed +47
-1
lines changed
testassets/FunctionalTestsWebsite
test/FunctionalTests/Client Expand file tree Collapse file tree 2 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,35 @@ Task<HelloReply> UnaryThrowError(HelloRequest request, ServerCallContext context
6868 StringAssert . StartsWith ( "Failed to deserialize response message." , call . GetStatus ( ) . Detail ) ;
6969 }
7070
71+ [ TestCase ( "fr" , "fr" ) ]
72+ [ TestCase ( null , "en-US" ) ]
73+ public async Task Unary_SetAcceptLanguage_ServerCultureChanged ( string clientAcceptLanguage , string expectedServerCulture )
74+ {
75+ string ? serverCulture = null ;
76+ Task < HelloReply > UnaryThrowError ( HelloRequest request , ServerCallContext context )
77+ {
78+ serverCulture = Thread . CurrentThread . CurrentCulture . Name ;
79+ return Task . FromResult ( new HelloReply { Message = serverCulture } ) ;
80+ }
81+
82+ // Arrange
83+ var method = Fixture . DynamicGrpc . AddUnaryMethod < HelloRequest , HelloReply > ( UnaryThrowError ) ;
84+ var channel = CreateChannel ( ) ;
85+ var client = TestClientFactory . Create ( channel , method ) ;
86+ var metadata = new Metadata ( ) ;
87+ if ( clientAcceptLanguage != null )
88+ {
89+ metadata . Add ( "accept-language" , clientAcceptLanguage ) ;
90+ }
91+
92+ // Act
93+ var call = client . UnaryCall ( new HelloRequest ( ) , new CallOptions ( headers : metadata ) ) ;
94+ await call . ResponseAsync . DefaultTimeout ( ) ;
95+
96+ // Assert
97+ Assert . AreEqual ( expectedServerCulture , serverCulture ) ;
98+ }
99+
71100#if NET5_0_OR_GREATER
72101 [ Test ]
73102 public async Task MaxConcurrentStreams_StartConcurrently_AdditionalConnectionsCreated ( )
Original file line number Diff line number Diff line change 1717#endregion
1818
1919using System . Diagnostics ;
20+ using System . Globalization ;
2021using System . IdentityModel . Tokens . Jwt ;
2122using System . Security . Claims ;
2223using FunctionalTestsWebsite . Infrastructure ;
2627using Grpc . HealthCheck ;
2728using Grpc . Tests . Shared ;
2829using Microsoft . AspNetCore . Authentication . JwtBearer ;
30+ using Microsoft . AspNetCore . Localization ;
2931using Microsoft . Extensions . DependencyInjection . Extensions ;
3032using Microsoft . IdentityModel . Tokens ;
3133
@@ -123,6 +125,20 @@ static Uri GetCurrentAddress(IServiceProvider serviceProvider)
123125
124126 return new Uri ( $ "{ context . Request . Scheme } ://{ context . Request . Host . Value } ") ;
125127 }
128+
129+ services . Configure < RequestLocalizationOptions > ( options =>
130+ {
131+ const string enUSCulture = "en-US" ;
132+ var supportedCultures = new [ ]
133+ {
134+ new CultureInfo ( enUSCulture ) ,
135+ new CultureInfo ( "fr" )
136+ } ;
137+
138+ options . DefaultRequestCulture = new RequestCulture ( culture : enUSCulture , uiCulture : enUSCulture ) ;
139+ options . SupportedCultures = supportedCultures ;
140+ options . SupportedUICultures = supportedCultures ;
141+ } ) ;
126142 }
127143
128144 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -168,9 +184,10 @@ public void Configure(IApplicationBuilder app)
168184 await next ( ) ;
169185 }
170186 } ) ;
171-
172187 app . UseRouting ( ) ;
173188
189+ app . UseRequestLocalization ( ) ;
190+
174191 app . UseAuthorization ( ) ;
175192 app . UseGrpcWeb ( new GrpcWebOptions { DefaultEnabled = true } ) ;
176193 app . UseCors ( ) ;
You can’t perform that action at this time.
0 commit comments