File tree 2 files changed +47
-1
lines changed
test/FunctionalTests/Client
testassets/FunctionalTestsWebsite
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
68
68
StringAssert . StartsWith ( "Failed to deserialize response message." , call . GetStatus ( ) . Detail ) ;
69
69
}
70
70
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
+
71
100
#if NET5_0_OR_GREATER
72
101
[ Test ]
73
102
public async Task MaxConcurrentStreams_StartConcurrently_AdditionalConnectionsCreated ( )
Original file line number Diff line number Diff line change 17
17
#endregion
18
18
19
19
using System . Diagnostics ;
20
+ using System . Globalization ;
20
21
using System . IdentityModel . Tokens . Jwt ;
21
22
using System . Security . Claims ;
22
23
using FunctionalTestsWebsite . Infrastructure ;
26
27
using Grpc . HealthCheck ;
27
28
using Grpc . Tests . Shared ;
28
29
using Microsoft . AspNetCore . Authentication . JwtBearer ;
30
+ using Microsoft . AspNetCore . Localization ;
29
31
using Microsoft . Extensions . DependencyInjection . Extensions ;
30
32
using Microsoft . IdentityModel . Tokens ;
31
33
@@ -123,6 +125,20 @@ static Uri GetCurrentAddress(IServiceProvider serviceProvider)
123
125
124
126
return new Uri ( $ "{ context . Request . Scheme } ://{ context . Request . Host . Value } ") ;
125
127
}
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
+ } ) ;
126
142
}
127
143
128
144
// 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)
168
184
await next ( ) ;
169
185
}
170
186
} ) ;
171
-
172
187
app . UseRouting ( ) ;
173
188
189
+ app . UseRequestLocalization ( ) ;
190
+
174
191
app . UseAuthorization ( ) ;
175
192
app . UseGrpcWeb ( new GrpcWebOptions { DefaultEnabled = true } ) ;
176
193
app . UseCors ( ) ;
You can’t perform that action at this time.
0 commit comments