From 6af07271a8a7c8e0010a6d9aefb2003b3bc2e7b6 Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Thu, 14 May 2026 13:01:58 +0530 Subject: [PATCH 1/2] test: add AgentResponse edge case coverage --- .../AgentResponseTests.cs | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 6d24c821bc..655efe34f8 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -287,4 +287,67 @@ public void ToAgentResponseUpdatesWithAdditionalPropertiesOnlyProducesSingleUpda Assert.NotNull(update.AdditionalProperties); Assert.Equal("value", update.AdditionalProperties!["key"]); } + + [Fact] + public void Constructor_WithNullChatResponse_ThrowsArgumentNullException() + { + // Act & Assert + Assert.Throws(() => new AgentResponse((ChatResponse)null!)); + } + + [Fact] + public void Text_WithOnlyNonTextContent_ReturnsEmptyString() + { + // Arrange + AgentResponse response = new( + [ + new ChatMessage( + ChatRole.Assistant, + [ + new DataContent("data:image/png;base64,aGVsbG8="), + new FunctionCallContent("callId1", "fc1"), + new FunctionResultContent("callId1", "result"), + ]) + ]); + + // Act & Assert + Assert.Equal(string.Empty, response.Text); + } + + [Fact] + public void Text_AfterSettingMessagesToNull_ReturnsEmptyString() + { + // Arrange + AgentResponse response = new(new ChatMessage(ChatRole.Assistant, "hello")); + + // Act + response.Messages = null!; + + // Assert + Assert.Equal(string.Empty, response.Text); + } + + [Fact] + public void ToAgentResponseUpdates_WithMultipleMessages_PreservesOrder() + { + // Arrange + AgentResponse response = new( + [ + new ChatMessage(ChatRole.Assistant, "first") { MessageId = "msg1" }, + new ChatMessage(ChatRole.Assistant, "second") { MessageId = "msg2" }, + new ChatMessage(ChatRole.Assistant, "third") { MessageId = "msg3" }, + ]); + + // Act + AgentResponseUpdate[] updates = response.ToAgentResponseUpdates(); + + // Assert + Assert.Equal(3, updates.Length); + Assert.Equal("msg1", updates[0].MessageId); + Assert.Equal("first", updates[0].Text); + Assert.Equal("msg2", updates[1].MessageId); + Assert.Equal("second", updates[1].Text); + Assert.Equal("msg3", updates[2].MessageId); + Assert.Equal("third", updates[2].Text); + } } From ea9402fb90e48fbd422659dd9a0a6cb2099d533b Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Fri, 15 May 2026 09:35:30 +0530 Subject: [PATCH 2/2] test: assert parameter name in null ChatResponse constructor test --- .../AgentResponseTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 655efe34f8..f6fcf88222 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -292,7 +292,7 @@ public void ToAgentResponseUpdatesWithAdditionalPropertiesOnlyProducesSingleUpda public void Constructor_WithNullChatResponse_ThrowsArgumentNullException() { // Act & Assert - Assert.Throws(() => new AgentResponse((ChatResponse)null!)); + Assert.Throws("response", () => new AgentResponse((ChatResponse)null!)); } [Fact]