Files
agent-framework/dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentRunOptionsTests.cs
T
SergeyMenshykh 1bf520a7c2 .NET: Add support for background responses (#1501)
* add support for background responses

* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponseUpdate.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix broken link

* fix xml comments and background responses properties override funcitonity

* change ai model provider

* use Run{Streaming}Async overloads that don't require messages

* stop using m: prefix in cref attribute of <see/> element.

* reject input messages provided with continuation token + don't extract messages from message store and context provide if continuation token is provided

* use agent thread for background-responses sample

* require agent thread for background responses

* Update dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs

Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>

* Update dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs

Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>

* remove CA1200

* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunOptions.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponse.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* Update dotnet/src/Microsoft.Agents.AI.Abstractions/AgentRunResponse.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

* address pr review comments

* Update dotnet/samples/GettingStarted/Agents/Agent_Step17_BackgroundResponses/Program.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
2025-10-22 17:43:57 +00:00

59 lines
1.8 KiB
C#

// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Text.Json;
using Microsoft.Extensions.AI;
namespace Microsoft.Agents.AI.Abstractions.UnitTests;
/// <summary>
/// Unit tests for the <see cref="AgentRunOptions"/> class.
/// </summary>
public class AgentRunOptionsTests
{
[Fact]
public void CloningConstructorCopiesProperties()
{
// Arrange
var options = new AgentRunOptions
{
ContinuationToken = new object(),
AllowBackgroundResponses = true
};
// Act
var clone = new AgentRunOptions(options);
// Assert
Assert.NotNull(clone);
Assert.Same(options.ContinuationToken, clone.ContinuationToken);
Assert.Equal(options.AllowBackgroundResponses, clone.AllowBackgroundResponses);
}
[Fact]
public void CloningConstructorThrowsIfNull() =>
// Act & Assert
Assert.Throws<ArgumentNullException>(() => new AgentRunOptions(null!));
[Fact]
public void JsonSerializationRoundtrips()
{
// Arrange
var options = new AgentRunOptions
{
ContinuationToken = ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3 }),
AllowBackgroundResponses = true
};
// Act
string json = JsonSerializer.Serialize(options, AgentAbstractionsJsonUtilities.DefaultOptions);
var deserialized = JsonSerializer.Deserialize<AgentRunOptions>(json, AgentAbstractionsJsonUtilities.DefaultOptions);
// Assert
Assert.NotNull(deserialized);
Assert.Equivalent(ResponseContinuationToken.FromBytes(new byte[] { 1, 2, 3 }), deserialized!.ContinuationToken);
Assert.Equal(options.AllowBackgroundResponses, deserialized.AllowBackgroundResponses);
}
}