From 69df2eb1b870b762052e627c7d05988eb766512c Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Mon, 1 Jun 2026 13:58:28 +0530 Subject: [PATCH 1/3] .NET: test: add AgentResponse coverage for protected constructor, message property propagation, and [JsonIgnore] fields --- .../AgentResponseTests.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 7a8203dea7..21b923dc12 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -323,4 +323,88 @@ public void ToAgentResponseUpdatesWithAdditionalPropertiesOnlyProducesSingleUpda Assert.NotNull(update.AdditionalProperties); Assert.Equal("value", update.AdditionalProperties!["key"]); } + + [Fact] + public void ProtectedCopyConstructor_WithNullAgentResponse_ThrowsArgumentNullException() + { + Assert.Throws("response", () => new DerivedAgentResponse(null!)); + } + + [Fact] + public void ProtectedCopyConstructor_WithAgentResponse_CopiesAllProperties() + { + // Arrange + AgentResponse original = new(new ChatMessage(ChatRole.Assistant, "hello")) + { + AdditionalProperties = new() { ["key"] = "value" }, + CreatedAt = new DateTimeOffset(2022, 1, 1, 0, 0, 0, TimeSpan.Zero), + FinishReason = ChatFinishReason.Stop, + ResponseId = "responseId", + Usage = new UsageDetails { TotalTokenCount = 42 }, + ContinuationToken = ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3 }), + }; + + // Act + DerivedAgentResponse copy = new(original); + + // Assert + Assert.Same(original.AdditionalProperties, copy.AdditionalProperties); + Assert.Equal(original.CreatedAt, copy.CreatedAt); + Assert.Equal(original.FinishReason, copy.FinishReason); + Assert.Same(original.Messages, copy.Messages); + Assert.Same(original, copy.RawRepresentation); + Assert.Equal(original.ResponseId, copy.ResponseId); + Assert.Same(original.Usage, copy.Usage); + Assert.Equivalent(original.ContinuationToken, copy.ContinuationToken); + } + + [Fact] + public void ToAgentResponseUpdates_PropagatesMessageAuthorName() + { + // Arrange + AgentResponse response = new(new ChatMessage(ChatRole.Assistant, "Text") { AuthorName = "bot" }); + + // Act + AgentResponseUpdate[] updates = response.ToAgentResponseUpdates(); + + // Assert + Assert.Equal("bot", updates[0].AuthorName); + } + + [Fact] + public void ToAgentResponseUpdates_PropagatesMessageAdditionalProperties() + { + // Arrange + AdditionalPropertiesDictionary messageProps = new() { ["msgKey"] = "msgValue" }; + AgentResponse response = new(new ChatMessage(ChatRole.Assistant, "Text") { AdditionalProperties = messageProps }); + + // Act + AgentResponseUpdate[] updates = response.ToAgentResponseUpdates(); + + // Assert + Assert.Same(messageProps, updates[0].AdditionalProperties); + } + + [Fact] + public void JsonSerialization_ExcludesTextAndRawRepresentation() + { + // Arrange + AgentResponse response = new(new ChatMessage(ChatRole.Assistant, "hello")) + { + RawRepresentation = new object(), + }; + + // Act + string json = JsonSerializer.Serialize(response, AgentAbstractionsJsonUtilities.DefaultOptions); + + // Assert + using JsonDocument doc = JsonDocument.Parse(json); + foreach (JsonProperty prop in doc.RootElement.EnumerateObject()) + { + Assert.NotEqual("text", prop.Name, StringComparer.OrdinalIgnoreCase); + Assert.NotEqual("rawRepresentation", prop.Name, StringComparer.OrdinalIgnoreCase); + } + } + + private sealed class DerivedAgentResponse(AgentResponse response) : AgentResponse(response); } From 5d20f0576ab2e318fde334be76a5930a38443980 Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Wed, 3 Jun 2026 08:25:43 +0530 Subject: [PATCH 2/3] test: add explicit update count assertions before index access --- .../AgentResponseTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 21b923dc12..3730444c9e 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -368,6 +368,7 @@ public void ToAgentResponseUpdates_PropagatesMessageAuthorName() AgentResponseUpdate[] updates = response.ToAgentResponseUpdates(); // Assert + Assert.Single(updates); Assert.Equal("bot", updates[0].AuthorName); } @@ -382,6 +383,7 @@ public void ToAgentResponseUpdates_PropagatesMessageAdditionalProperties() AgentResponseUpdate[] updates = response.ToAgentResponseUpdates(); // Assert + Assert.Single(updates); Assert.Same(messageProps, updates[0].AdditionalProperties); } From 020f5d2ba59648d4aa029881fbc58d3226e0b102 Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Wed, 3 Jun 2026 08:31:18 +0530 Subject: [PATCH 3/3] test: fix JsonIgnore assertion to guard against empty serialization output --- .../AgentResponseTests.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs index 3730444c9e..ddc5e5f14e 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseTests.cs @@ -401,11 +401,10 @@ public void JsonSerialization_ExcludesTextAndRawRepresentation() // Assert using JsonDocument doc = JsonDocument.Parse(json); - foreach (JsonProperty prop in doc.RootElement.EnumerateObject()) - { - Assert.NotEqual("text", prop.Name, StringComparer.OrdinalIgnoreCase); - Assert.NotEqual("rawRepresentation", prop.Name, StringComparer.OrdinalIgnoreCase); - } + JsonElement root = doc.RootElement; + Assert.True(root.TryGetProperty("messages", out _)); + Assert.False(root.TryGetProperty("text", out _)); + Assert.False(root.TryGetProperty("rawRepresentation", out _)); } private sealed class DerivedAgentResponse(AgentResponse response) : AgentResponse(response);