From 7cb7457e7fbe9c95ac365cf651b0aaf878b3b80a Mon Sep 17 00:00:00 2001 From: Challa Ravindranath Date: Thu, 14 May 2026 10:03:40 +0530 Subject: [PATCH] add AgentSession StateBag edge case coverage --- .../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 void StateBag_Values_Roundtrips() 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