mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
.NET: Durable extension: initial src and unit tests (#1900)
This commit is contained in:
committed by
GitHub
Unverified
parent
1d5677be11
commit
5686a009fb
@@ -0,0 +1,43 @@
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Microsoft.Agents.AI.DurableTask.UnitTests;
|
||||
|
||||
public sealed class DurableAgentThreadTests
|
||||
{
|
||||
[Fact]
|
||||
public void BuiltInSerialization()
|
||||
{
|
||||
AgentSessionId sessionId = AgentSessionId.WithRandomKey("test-agent");
|
||||
AgentThread thread = new DurableAgentThread(sessionId);
|
||||
|
||||
JsonElement serializedThread = thread.Serialize();
|
||||
|
||||
// Expected format: "{\"sessionId\":\"@dafx-test-agent@<random-key>\"}"
|
||||
string expectedSerializedThread = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\"}}";
|
||||
Assert.Equal(expectedSerializedThread, serializedThread.ToString());
|
||||
|
||||
DurableAgentThread deserializedThread = DurableAgentThread.Deserialize(serializedThread);
|
||||
Assert.Equal(sessionId, deserializedThread.SessionId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void STJSerialization()
|
||||
{
|
||||
AgentSessionId sessionId = AgentSessionId.WithRandomKey("test-agent");
|
||||
AgentThread thread = new DurableAgentThread(sessionId);
|
||||
|
||||
// Need to specify the type explicitly because STJ, unlike other serializers,
|
||||
// does serialization based on the static type of the object, not the runtime type.
|
||||
string serializedThread = JsonSerializer.Serialize(thread, typeof(DurableAgentThread));
|
||||
|
||||
// Expected format: "{\"sessionId\":\"@dafx-test-agent@<random-key>\"}"
|
||||
string expectedSerializedThread = $"{{\"sessionId\":\"@dafx-{sessionId.Name}@{sessionId.Key}\"}}";
|
||||
Assert.Equal(expectedSerializedThread, serializedThread);
|
||||
|
||||
DurableAgentThread? deserializedThread = JsonSerializer.Deserialize<DurableAgentThread>(serializedThread);
|
||||
Assert.NotNull(deserializedThread);
|
||||
Assert.Equal(sessionId, deserializedThread.SessionId);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user