From d81a8753d72612fd5c53e05724dc28ea7577c61c Mon Sep 17 00:00:00 2001 From: Challa Ravi Date: Fri, 15 May 2026 16:32:37 +0530 Subject: [PATCH] add AgentSession StateBag edge case coverage (#5838) Co-authored-by: Challa Ravindranath --- .../AgentSessionTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionTests.cs b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionTests.cs index b80f0a4fd2..5b14d41f74 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentSessionTests.cs @@ -24,6 +24,45 @@ public class AgentSessionTests Assert.Equal("value1", session.StateBag.GetValue("key1")); } + [Fact] + public void StateBag_Default_IsEmpty() + { + // Arrange & Act + var session = new TestAgentSession(); + + // Assert + Assert.Equal(0, session.StateBag.Count); + } + + [Fact] + public void StateBag_MultipleKeys_StoreAndRetrieveIndependently() + { + // Arrange + var session = new TestAgentSession(); + + // Act + session.StateBag.SetValue("key1", "value1"); + session.StateBag.SetValue("key2", "value2"); + + // Assert + Assert.Equal("value1", session.StateBag.GetValue("key1")); + Assert.Equal("value2", session.StateBag.GetValue("key2")); + } + + [Fact] + public void StateBag_OverwriteValue_ReturnsUpdatedValue() + { + // Arrange + var session = new TestAgentSession(); + session.StateBag.SetValue("key1", "original"); + + // Act + session.StateBag.SetValue("key1", "updated"); + + // Assert + Assert.Equal("updated", session.StateBag.GetValue("key1")); + } + #endregion #region GetService Method Tests