Skip to content

Commit c9380a6

Browse files
address copilot comments
1 parent f976c88 commit c9380a6

3 files changed

Lines changed: 49 additions & 3 deletions

File tree

dotnet/src/Microsoft.Agents.AI.Hosting.A2A.AspNetCore/Microsoft.Agents.AI.Hosting.A2A.AspNetCore.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<InjectSharedDiagnosticIds>true</InjectSharedDiagnosticIds>
1717
<InjectExperimentalAttributeOnLegacy>true</InjectExperimentalAttributeOnLegacy>
1818
</PropertyGroup>
19-
19+
2020
<ItemGroup>
2121
<PackageReference Include="A2A.AspNetCore" />
2222
</ItemGroup>
@@ -28,7 +28,7 @@
2828
<ItemGroup>
2929
<ProjectReference Include="..\Microsoft.Agents.AI.Hosting.A2A\Microsoft.Agents.AI.Hosting.A2A.csproj" />
3030
</ItemGroup>
31-
31+
3232
<PropertyGroup>
3333
<!-- NuGet Package Settings -->
3434
<Title>Microsoft Agent Framework Hosting A2A ASP.NET Core</Title>

dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/A2AAgentHandlerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,4 +890,4 @@ private sealed class EventCollector
890890
}
891891

892892
private sealed class TestAgentSession : AgentSession;
893-
}
893+
}

dotnet/tests/Microsoft.Agents.AI.Hosting.A2A.UnitTests/A2AEndpointRouteBuilderExtensionsTests.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)