@@ -253,15 +253,26 @@ public async Task SubscribeResource_Stdio()
253253 {
254254 // arrange
255255 var clientId = "test_server" ;
256-
257- // act
258256 TaskCompletionSource < bool > tcs = new ( ) ;
259- await using var client = await _fixture . CreateClientAsync ( clientId ) ;
260- client . AddNotificationHandler ( NotificationMethods . ResourceUpdatedNotification , ( notification ) =>
257+ Task HandleResourceUpdatedNotification ( JsonRpcNotification notification )
261258 {
262259 var notificationParams = JsonSerializer . Deserialize < ResourceUpdatedNotificationParams > ( notification . Params ! . ToString ( ) ?? string . Empty ) ;
263260 tcs . TrySetResult ( true ) ;
264261 return Task . CompletedTask ;
262+ }
263+
264+ // act
265+ await using var client = await _fixture . CreateClientAsync ( clientId , new ( )
266+ {
267+ ClientInfo = new ( )
268+ {
269+ Name = "IntegrationTestClient" ,
270+ Version = "1.0.0"
271+ } ,
272+ NotificationHandlers = new Dictionary < string , List < Func < JsonRpcNotification , Task > > > ( )
273+ {
274+ [ NotificationMethods . ResourceUpdatedNotification ] = [ HandleResourceUpdatedNotification ] ,
275+ } ,
265276 } ) ;
266277 await client . SubscribeToResourceAsync ( "test://static/resource/1" , TestContext . Current . CancellationToken ) ;
267278
@@ -274,15 +285,26 @@ public async Task UnsubscribeResource_Stdio()
274285 {
275286 // arrange
276287 var clientId = "test_server" ;
277-
278- // act
279288 TaskCompletionSource < bool > receivedNotification = new ( ) ;
280- await using var client = await _fixture . CreateClientAsync ( clientId ) ;
281- client . AddNotificationHandler ( NotificationMethods . ResourceUpdatedNotification , ( notification ) =>
289+ Task HandleResourceUpdatedNotification ( JsonRpcNotification notification )
282290 {
283291 var notificationParams = JsonSerializer . Deserialize < ResourceUpdatedNotificationParams > ( notification . Params ! . ToString ( ) ?? string . Empty ) ;
284292 receivedNotification . TrySetResult ( true ) ;
285293 return Task . CompletedTask ;
294+ }
295+
296+ // act
297+ await using var client = await _fixture . CreateClientAsync ( clientId , new ( )
298+ {
299+ ClientInfo = new ( )
300+ {
301+ Name = "IntegrationTestClient" ,
302+ Version = "1.0.0"
303+ } ,
304+ NotificationHandlers = new Dictionary < string , List < Func < JsonRpcNotification , Task > > > ( )
305+ {
306+ [ NotificationMethods . ResourceUpdatedNotification ] = [ HandleResourceUpdatedNotification ] ,
307+ } ,
286308 } ) ;
287309 await client . SubscribeToResourceAsync ( "test://static/resource/1" , TestContext . Current . CancellationToken ) ;
288310
@@ -543,6 +565,16 @@ public async Task SamplingViaChatClient_RequestResponseProperlyPropagated()
543565 public async Task SetLoggingLevel_ReceivesLoggingMessages ( string clientId )
544566 {
545567 // arrange
568+ TaskCompletionSource < bool > receivedNotification = new ( ) ;
569+ Task HandleLoggingNotification ( JsonRpcNotification notification )
570+ {
571+ var loggingMessageNotificationParameters = JsonSerializer . Deserialize < LoggingMessageNotificationParams > ( notification . Params ! . ToString ( ) ?? string . Empty ) ;
572+ if ( loggingMessageNotificationParameters is not null )
573+ {
574+ receivedNotification . TrySetResult ( true ) ;
575+ }
576+ return Task . CompletedTask ;
577+ }
546578 JsonSerializerOptions jsonSerializerOptions = new ( JsonSerializerDefaults . Web )
547579 {
548580 TypeInfoResolver = new DefaultJsonTypeInfoResolver ( ) ,
@@ -552,17 +584,17 @@ public async Task SetLoggingLevel_ReceivesLoggingMessages(string clientId)
552584 Encoder = JavaScriptEncoder . UnsafeRelaxedJsonEscaping ,
553585 } ;
554586
555- TaskCompletionSource < bool > receivedNotification = new ( ) ;
556- await using var client = await _fixture . CreateClientAsync ( clientId ) ;
557- client . AddNotificationHandler ( NotificationMethods . LoggingMessageNotification , ( notification ) =>
587+ await using var client = await _fixture . CreateClientAsync ( clientId , new ( )
558588 {
559- var loggingMessageNotificationParameters = JsonSerializer . Deserialize < LoggingMessageNotificationParams > ( notification . Params ! . ToString ( ) ?? string . Empty ,
560- jsonSerializerOptions ) ;
561- if ( loggingMessageNotificationParameters is not null )
589+ ClientInfo = new ( )
562590 {
563- receivedNotification . TrySetResult ( true ) ;
564- }
565- return Task . CompletedTask ;
591+ Name = "IntegrationTestClient" ,
592+ Version = "1.0.0"
593+ } ,
594+ NotificationHandlers = new Dictionary < string , List < Func < JsonRpcNotification , Task > > > ( )
595+ {
596+ [ NotificationMethods . LoggingMessageNotification ] = [ HandleLoggingNotification ] ,
597+ } ,
566598 } ) ;
567599
568600 // act
0 commit comments