2929using Grpc . AspNetCore . Server . Tests . Infrastructure ;
3030using Grpc . AspNetCore . Server . Tests . TestObjects ;
3131using Grpc . Core ;
32- using Grpc . Net . Compression ;
3332using Grpc . Shared . Server ;
3433using Grpc . Tests . Shared ;
3534using Microsoft . AspNetCore . Http ;
@@ -176,7 +175,26 @@ public async Task ProtocolValidation_IISHttp2Protocol_Success()
176175 Assert . IsNull ( log ) ;
177176 }
178177
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 )
180198 {
181199 var method = new Method < TestMessage , TestMessage > ( methodType , "test" , "test" , _marshaller , _marshaller ) ;
182200
@@ -185,31 +203,47 @@ private static ServerCallHandlerBase<TestService, TestMessage, TestMessage> Crea
185203 case MethodType . Unary :
186204 return new UnaryServerCallHandler < TestService , TestMessage , TestMessage > (
187205 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+ } ,
189211 method ,
190212 HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
191213 new TestGrpcServiceActivator < TestService > ( ) ) ,
192214 loggerFactory ?? NullLoggerFactory . Instance ) ;
193215 case MethodType . ClientStreaming :
194216 return new ClientStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
195217 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+ } ,
197223 method ,
198224 HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
199225 new TestGrpcServiceActivator < TestService > ( ) ) ,
200226 loggerFactory ?? NullLoggerFactory . Instance ) ;
201227 case MethodType . ServerStreaming :
202228 return new ServerStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
203229 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+ } ,
205235 method ,
206236 HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
207237 new TestGrpcServiceActivator < TestService > ( ) ) ,
208238 loggerFactory ?? NullLoggerFactory . Instance ) ;
209239 case MethodType . DuplexStreaming :
210240 return new DuplexStreamingServerCallHandler < TestService , TestMessage , TestMessage > (
211241 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+ } ,
213247 method ,
214248 HttpContextServerCallContextHelper . CreateMethodOptions ( ) ,
215249 new TestGrpcServiceActivator < TestService > ( ) ) ,
0 commit comments