mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
23db9569ce
* Rename AddAgentFrameworkHandler to AddFoundryResponses and add MapFoundryResponses - Rename extension methods: AddAgentFrameworkHandler -> AddFoundryResponses, MapAgentFrameworkHandler -> MapFoundryResponses - AddFoundryResponses now calls AddResponsesServer() internally - Add MapFoundryResponses() extension on IEndpointRouteBuilder - Update sample and tests to use new API names - Remove redundant AddResponsesServer() and /ready endpoint from sample Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fixing numbering in sample. --------- Co-authored-by: alliscode <bentho@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
74 lines
2.2 KiB
C#
74 lines
2.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Linq;
|
|
using Microsoft.Agents.AI.Foundry.Hosting;
|
|
using Azure.AI.AgentServer.Responses;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Moq;
|
|
|
|
namespace Microsoft.Agents.AI.Foundry.UnitTests.Hosting;
|
|
|
|
public class ServiceCollectionExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void AddFoundryResponses_RegistersResponseHandler()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
services.AddFoundryResponses();
|
|
|
|
var descriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.NotNull(descriptor);
|
|
Assert.Equal(typeof(AgentFrameworkResponseHandler), descriptor.ImplementationType);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddFoundryResponses_CalledTwice_RegistersOnce()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
services.AddFoundryResponses();
|
|
services.AddFoundryResponses();
|
|
|
|
var count = services.Count(d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.Equal(1, count);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddFoundryResponses_NullServices_ThrowsArgumentNullException()
|
|
{
|
|
Assert.Throws<ArgumentNullException>(
|
|
() => FoundryHostingExtensions.AddFoundryResponses(null!));
|
|
}
|
|
|
|
[Fact]
|
|
public void AddFoundryResponses_WithAgent_RegistersAgentAndHandler()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
var mockAgent = new Mock<AIAgent>();
|
|
|
|
services.AddFoundryResponses(mockAgent.Object);
|
|
|
|
var handlerDescriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(ResponseHandler));
|
|
Assert.NotNull(handlerDescriptor);
|
|
|
|
var agentDescriptor = services.FirstOrDefault(
|
|
d => d.ServiceType == typeof(AIAgent));
|
|
Assert.NotNull(agentDescriptor);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddFoundryResponses_WithNullAgent_ThrowsArgumentNullException()
|
|
{
|
|
var services = new ServiceCollection();
|
|
Assert.Throws<ArgumentNullException>(
|
|
() => services.AddFoundryResponses(null!));
|
|
}
|
|
}
|