@@ -391,4 +391,50 @@ public void AddA2AServer_NullAgentBuilder_ThrowsArgumentNullException()
391391
392392 Assert . Equal ( "agentBuilder" , exception . ParamName ) ;
393393 }
394+
395+ /// <summary>
396+ /// Verifies that MapA2AHttpJson throws InvalidOperationException when no A2AServer has been
397+ /// registered for the specified agent via AddA2AServer.
398+ /// </summary>
399+ [ Fact ]
400+ public void MapA2AHttpJson_WithoutAddA2AServer_ThrowsInvalidOperationException ( )
401+ {
402+ // Arrange
403+ WebApplicationBuilder builder = WebApplication . CreateBuilder ( ) ;
404+ IChatClient mockChatClient = new DummyChatClient ( ) ;
405+ builder . Services . AddKeyedSingleton ( "chat-client" , mockChatClient ) ;
406+ builder . AddAIAgent ( "agent" , "Instructions" , chatClientServiceKey : "chat-client" ) ;
407+ builder . Services . AddLogging ( ) ;
408+ using WebApplication app = builder . Build ( ) ;
409+
410+ // Act & Assert
411+ InvalidOperationException exception = Assert . Throws < InvalidOperationException > ( ( ) =>
412+ app . MapA2AHttpJson ( "agent" , "/a2a" ) ) ;
413+
414+ Assert . Contains ( "agent" , exception . Message ) ;
415+ Assert . Contains ( "AddA2AServer" , exception . Message ) ;
416+ }
417+
418+ /// <summary>
419+ /// Verifies that MapA2AJsonRpc throws InvalidOperationException when no A2AServer has been
420+ /// registered for the specified agent via AddA2AServer.
421+ /// </summary>
422+ [ Fact ]
423+ public void MapA2AJsonRpc_WithoutAddA2AServer_ThrowsInvalidOperationException ( )
424+ {
425+ // Arrange
426+ WebApplicationBuilder builder = WebApplication . CreateBuilder ( ) ;
427+ IChatClient mockChatClient = new DummyChatClient ( ) ;
428+ builder . Services . AddKeyedSingleton ( "chat-client" , mockChatClient ) ;
429+ builder . AddAIAgent ( "agent" , "Instructions" , chatClientServiceKey : "chat-client" ) ;
430+ builder . Services . AddLogging ( ) ;
431+ using WebApplication app = builder . Build ( ) ;
432+
433+ // Act & Assert
434+ InvalidOperationException exception = Assert . Throws < InvalidOperationException > ( ( ) =>
435+ app . MapA2AJsonRpc ( "agent" , "/a2a" ) ) ;
436+
437+ Assert . Contains ( "agent" , exception . Message ) ;
438+ Assert . Contains ( "AddA2AServer" , exception . Message ) ;
439+ }
394440}
0 commit comments