mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
33f84f9ed2
* Improve fidelity of OpenAI Responses server and add Conversations * Merge * nit * Undo prior change * Undo prior change * Review feedback * Review feedback * Fix test * Use simpler JsonDocument approach for polymorphic deserialization * More review feedback * dotnet format
93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Text.Json;
|
|
using Microsoft.Agents.AI.Hosting.OpenAI.Responses;
|
|
|
|
namespace Microsoft.Agents.AI.Hosting.OpenAI.UnitTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for AgentInvocationContext.
|
|
/// </summary>
|
|
public sealed class AgentInvocationContextTests
|
|
{
|
|
[Fact]
|
|
public void Constructor_WithIdGenerator_InitializesCorrectly()
|
|
{
|
|
// Arrange
|
|
var idGenerator = new IdGenerator("resp_test123", "conv_test456");
|
|
|
|
// Act
|
|
var context = new AgentInvocationContext(idGenerator);
|
|
|
|
// Assert
|
|
Assert.NotNull(context);
|
|
Assert.Same(idGenerator, context.IdGenerator);
|
|
Assert.Equal("resp_test123", context.ResponseId);
|
|
Assert.Equal("conv_test456", context.ConversationId);
|
|
Assert.NotNull(context.JsonSerializerOptions);
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_WithoutJsonOptions_UsesDefaultOptions()
|
|
{
|
|
// Arrange
|
|
var idGenerator = new IdGenerator("resp_test", "conv_test");
|
|
|
|
// Act
|
|
var context = new AgentInvocationContext(idGenerator);
|
|
|
|
// Assert
|
|
Assert.NotNull(context.JsonSerializerOptions);
|
|
Assert.Same(OpenAIHostingJsonUtilities.DefaultOptions, context.JsonSerializerOptions);
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_WithCustomJsonOptions_UsesProvidedOptions()
|
|
{
|
|
// Arrange
|
|
var idGenerator = new IdGenerator("resp_test", "conv_test");
|
|
var customOptions = new JsonSerializerOptions
|
|
{
|
|
PropertyNameCaseInsensitive = true
|
|
};
|
|
|
|
// Act
|
|
var context = new AgentInvocationContext(idGenerator, customOptions);
|
|
|
|
// Assert
|
|
Assert.Same(customOptions, context.JsonSerializerOptions);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResponseId_ReturnsIdGeneratorResponseId()
|
|
{
|
|
// Arrange
|
|
const string ResponseId = "resp_property_test";
|
|
var idGenerator = new IdGenerator(ResponseId, "conv_test");
|
|
var context = new AgentInvocationContext(idGenerator);
|
|
|
|
// Act
|
|
string result = context.ResponseId;
|
|
|
|
// Assert
|
|
Assert.Equal(ResponseId, result);
|
|
Assert.Equal(idGenerator.ResponseId, result);
|
|
}
|
|
|
|
[Fact]
|
|
public void ConversationId_ReturnsIdGeneratorConversationId()
|
|
{
|
|
// Arrange
|
|
const string ConversationId = "conv_property_test";
|
|
var idGenerator = new IdGenerator("resp_test", ConversationId);
|
|
var context = new AgentInvocationContext(idGenerator);
|
|
|
|
// Act
|
|
string result = context.ConversationId;
|
|
|
|
// Assert
|
|
Assert.Equal(ConversationId, result);
|
|
Assert.Equal(idGenerator.ConversationId, result);
|
|
}
|
|
}
|