db620d33df
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
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);
|
|
}
|
|
}
|