mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
6bd2cfec03
* Add support for approving tools via heuristic rules * Address PR comments * Address PR comments * Apply suggestion from @SergeyMenshykh Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> --------- Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com>
76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Text.Json;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.AI.UnitTests;
|
|
|
|
/// <summary>
|
|
/// Unit tests for the <see cref="ToolApprovalAgentBuilderExtensions"/> class.
|
|
/// </summary>
|
|
public class ToolApprovalAgentBuilderExtensionsTests
|
|
{
|
|
/// <summary>
|
|
/// Verify that UseToolApproval throws ArgumentNullException when builder is null.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseToolApproval_WithNullBuilder_ThrowsArgumentNullException()
|
|
{
|
|
// Act & Assert
|
|
Assert.Throws<ArgumentNullException>("builder", () => ((AIAgentBuilder)null!).UseToolApproval());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseToolApproval returns a ToolApprovalAgent.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseToolApproval_WithValidBuilder_ReturnsToolApprovalAgent()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
|
|
// Act
|
|
var result = builder.UseToolApproval().Build();
|
|
|
|
// Assert
|
|
Assert.IsType<ToolApprovalAgent>(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseToolApproval returns the same builder instance for chaining.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseToolApproval_ReturnsBuilderForChaining()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
|
|
// Act
|
|
var result = builder.UseToolApproval();
|
|
|
|
// Assert
|
|
Assert.Same(builder, result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify that UseToolApproval with custom JsonSerializerOptions works correctly.
|
|
/// </summary>
|
|
[Fact]
|
|
public void UseToolApproval_WithCustomOptions_ReturnsToolApprovalAgent()
|
|
{
|
|
// Arrange
|
|
var mockAgent = new Mock<AIAgent>();
|
|
var builder = new AIAgentBuilder(mockAgent.Object);
|
|
var options = new ToolApprovalAgentOptions { JsonSerializerOptions = new JsonSerializerOptions() };
|
|
|
|
// Act
|
|
var result = builder.UseToolApproval(options: options).Build();
|
|
|
|
// Assert
|
|
Assert.IsType<ToolApprovalAgent>(result);
|
|
}
|
|
}
|