Skip to content

Commit 28f953f

Browse files
committed
add save state test
1 parent 24f6490 commit 28f953f

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

dotnet/test/Microsoft.AutoGen.Core.Tests/AgentTests.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,25 @@ await runtime.RegisterAgentFactoryAsync("MyAgent", (id, runtime) =>
145145

146146
Assert.True(agent.ReceivedItems.Count == 1);
147147
}
148+
149+
[Fact]
150+
public async Task AgentShouldSaveStateCorrectlyTest()
151+
{
152+
var runtime = new InProcessRuntime();
153+
await runtime.StartAsync();
154+
155+
Logger<BaseAgent> logger = new(new LoggerFactory());
156+
TestAgent agent = new TestAgent(new AgentId("TestType", "TestKey"), runtime, logger);
157+
158+
var state = await agent.SaveStateAsync();
159+
160+
// Ensure state is a dictionary
161+
state.Should().NotBeNull();
162+
state.Should().BeOfType<Dictionary<string, object>>();
163+
state.Should().BeEmpty("Default SaveStateAsync should return an empty dictionary.");
164+
165+
// Add a sample value and verify it updates correctly
166+
state["testKey"] = "testValue";
167+
state.Should().ContainKey("testKey").WhoseValue.Should().Be("testValue");
168+
}
148169
}

0 commit comments

Comments
 (0)