29
29
using Grpc . AspNetCore . Server . Tests . Infrastructure ;
30
30
using Grpc . AspNetCore . Server . Tests . TestObjects ;
31
31
using Grpc . Core ;
32
- using Grpc . Net . Compression ;
33
32
using Grpc . Shared . Server ;
34
33
using Grpc . Tests . Shared ;
35
34
using Microsoft . AspNetCore . Http ;
@@ -176,7 +175,26 @@ public async Task ProtocolValidation_IISHttp2Protocol_Success()
176
175
Assert . IsNull ( log ) ;
177
176
}
178
177
179
- private static ServerCallHandlerBase < TestService , TestMessage , TestMessage > CreateHandler ( MethodType methodType , ILoggerFactory ? loggerFactory = null )
178
+ [ Test ]
179
+ public async Task StatusDebugException_ErrorInHandler_SetInDebugException ( )
180
+ {
181
+ // Arrange
182
+ var ex = new Exception ( "Test exception" ) ;
183
+ var httpContext = HttpContextHelpers . CreateContext ( ) ;
184
+ var call = CreateHandler ( MethodType . ClientStreaming , handlerAction : ( ) => throw ex ) ;
185
+
186
+ // Act
187
+ await call . HandleCallAsync ( httpContext ) . DefaultTimeout ( ) ;
188
+
189
+ // Assert
190
+ var serverCallContext = httpContext . Features . Get < IServerCallContextFeature > ( ) ;
191
+ Assert . AreEqual ( ex , serverCallContext . ServerCallContext . Status . DebugException ) ;
192
+ }
193
+
194
+ private static ServerCallHandlerBase < TestService , TestMessage , TestMessage > CreateHandler (
195
+ MethodType methodType ,
196
+ ILoggerFactory ? loggerFactory = null ,
197
+ Action ? handlerAction = null )
180
198
{
181
199
var method = new Method < TestMessage , TestMessage > ( methodType , "test" , "test" , _marshaller , _marshaller ) ;
182
200
@@ -185,31 +203,47 @@ private static ServerCallHandlerBase<TestService, TestMessage, TestMessage> Crea
185
203
case MethodType . Unary :
186
204
return new UnaryServerCallHandler < TestService , TestMessage , TestMessage > (
187
205
new UnaryServerMethodInvoker < TestService , TestMessage , TestMessage > (
188
- ( service , reader , context ) => Task . FromResult ( new TestMessage ( ) ) ,
206
+ ( service , reader , context ) =>
207
+ {
208
+ handlerAction ? . Invoke ( ) ;
209
+ return Task . FromResult ( new TestMessage ( ) ) ;
210
+ } ,
189
211
method ,
190
212
HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
191
213
new TestGrpcServiceActivator < TestService > ( ) ) ,
192
214
loggerFactory ?? NullLoggerFactory . Instance ) ;
193
215
case MethodType . ClientStreaming :
194
216
return new ClientStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
195
217
new ClientStreamingServerMethodInvoker < TestService , TestMessage , TestMessage > (
196
- ( service , reader , context ) => Task . FromResult ( new TestMessage ( ) ) ,
218
+ ( service , reader , context ) =>
219
+ {
220
+ handlerAction ? . Invoke ( ) ;
221
+ return Task . FromResult ( new TestMessage ( ) ) ;
222
+ } ,
197
223
method ,
198
224
HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
199
225
new TestGrpcServiceActivator < TestService > ( ) ) ,
200
226
loggerFactory ?? NullLoggerFactory . Instance ) ;
201
227
case MethodType . ServerStreaming :
202
228
return new ServerStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
203
229
new ServerStreamingServerMethodInvoker < TestService , TestMessage , TestMessage > (
204
- ( service , request , writer , context ) => Task . FromResult ( new TestMessage ( ) ) ,
230
+ ( service , request , writer , context ) =>
231
+ {
232
+ handlerAction ? . Invoke ( ) ;
233
+ return Task . FromResult ( new TestMessage ( ) ) ;
234
+ } ,
205
235
method ,
206
236
HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
207
237
new TestGrpcServiceActivator < TestService > ( ) ) ,
208
238
loggerFactory ?? NullLoggerFactory . Instance ) ;
209
239
case MethodType . DuplexStreaming :
210
240
return new DuplexStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
211
241
new DuplexStreamingServerMethodInvoker < TestService , TestMessage , TestMessage > (
212
- ( service , reader , writer , context ) => Task . CompletedTask ,
242
+ ( service , reader , writer , context ) =>
243
+ {
244
+ handlerAction ? . Invoke ( ) ;
245
+ return Task . CompletedTask ;
246
+ } ,
213
247
method ,
214
248
HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
215
249
new TestGrpcServiceActivator < TestService > ( ) ) ,
0 commit comments